加入在线看的跳转按钮,精简代码

This commit is contained in:
emm
2022-08-31 19:11:40 +08:00
parent 749237a02d
commit be43729cd6
4 changed files with 124 additions and 123 deletions
+49 -58
View File
@@ -2,12 +2,12 @@ import vuex from "vuex"
import axios from "axios"
import {ElMessage} from "element-plus"
import qs from "qs"
const base_url = "http://107.189.14.196:8080/TaskHandler/"
const BaseUrl = "http://100.42.234.138:8888/"
const GalleryTaskHandlerUrl = BaseUrl + "GalleryTaskHandler/"
const actions = {
update(context){
const AuthCode = context.state.AuthCode
axios.get(base_url, {
axios.get(GalleryTaskHandlerUrl, {
params:{
param:"",
type:"all",
@@ -17,20 +17,23 @@ const actions = {
let temp = []
context.commit("_empty")
JSON.parse(res.data.data).forEach((task) => {
temp.push(JSON.parse(task))
temp.push(task)
})
context.commit("_update", temp)
})
},
post(context, link){
post(context, data){
const AuthCode = context.state.AuthCode
axios.post(base_url, qs.stringify({
AuthCode:AuthCode,
link:link
axios.post(GalleryTaskHandlerUrl, qs.stringify({
AuthCode:AuthCode,
link:data.link,
targetResolution:data.targetResolution
})).then((res) => {
if(res.data.result === "success")
if(res.data.result === "success") {
ElMessage("提交成功")
context.commit("_setPreDownloadGallery", false)
}
else{
if(res.data.data)
ElMessage(res.data.data)
@@ -42,7 +45,7 @@ const actions = {
},
query(context, link){
const AuthCode = context.state.AuthCode
axios.get(base_url, {
axios.get(GalleryTaskHandlerUrl, {
params:{
param:link,
type:'link',
@@ -51,46 +54,19 @@ const actions = {
}).then((res) => {
if(res.data.result === 'success'){
const gallery = JSON.parse(res.data.data)
let message = "本子名字: " + gallery.name + "<br>"
message += "本子页数: " + gallery.pages + "<br>"
message += "gid: " + gallery.gid + "<br>"
if(gallery.language === "N/A")
message += "语言: 未知<br>"
else
message += "语言: " + gallery.language + "<br>"
message += "大小: " + gallery.fileSize + "<br>"
switch (gallery.status){
case "complete":
message += "状态: 下载完成"
break
case "posted" :
message += "状态: 等待中"
break
case "proceeding":
message += "状态: 下载中"
break
default:
break
}
console.log(gallery)
ElMessage({
dangerouslyUseHTMLString: true,
duration: 5000,
showClose: true,
message
})
context.commit("_setPreDownloadGallery", gallery)
}
else
ElMessage("查询失败")
})
},
validate(context, AuthCode){
axios.post(base_url + "validate?AuthCode=" + AuthCode).then((res)=>{
axios.post(BaseUrl + "validate?AuthCode=" + AuthCode).then((res)=>{
if(res.data.result === 'success'){
context.commit("_authed", AuthCode, context)
context.dispatch("update")
context.dispatch("update").then()
setInterval(() => {
context.dispatch("update")
context.dispatch("update").then()
}, 30000)
}
else{
@@ -105,7 +81,7 @@ const actions = {
context.commit("_searchByKeyword", keyword)
},
deleteGallery(context, gid){
axios.delete(base_url, {params:{AuthCode:state.AuthCode, gid:gid}}).then((res) => {
axios.delete(GalleryTaskHandlerUrl, {params:{AuthCode:state.AuthCode, gid:gid}}).then((res) => {
if(res.data.result === "success"){
ElMessage("删除成功")
context.commit("_deleteGallery", gid)
@@ -122,7 +98,7 @@ const mutations = {
state.totalTask.splice(0)
},
_update(state, tasks){
const download_url = base_url + "file?link="
const download_url = GalleryTaskHandlerUrl + "file?link="
tasks.forEach((task) => {
if(task.status === "posted"){
@@ -154,6 +130,7 @@ const mutations = {
state.isAuth = false
state.AuthCode = ""
ElMessage("授权码错误")
localStorage.removeItem("auth")
},
_searchByLink(state, link){
let gid = link.split('/')[4]
@@ -185,26 +162,34 @@ const mutations = {
}
},
_deleteGallery(state, gid){
state.totalTask.map((currentValue, index, arr) => {
return currentValue.gid === gid ? null: currentValue
state.totalTask.forEach((item, index, arr) => {
if(item.gid === gid){
arr.splice(index, 1)
}
})
if(state.searchTask.length !== 1){
state.searchTask.map(currentValue => {
return currentValue.gid === gid ? null : currentValue
})
}
},
_setPreDownloadGallery(state,gallery){
state.preDownloadGallery = gallery
},
_openHistoryPanel(state){
state.showHistory = true
},
_closeHistoryPanel(state){
state.showHistory = false
}
}
const state = {
totalTask:[], //存放数据的数组
page:1, //当前页数
length:8, //每页能有多少个链接
isAuth:false, //是否授权
AuthCode:'', //授权码
loadComplete:false, //是否加载完成
isInclude:false, //是否搜索到任务
searchTask:[] //搜索到的任务
totalTask:[], //存放数据的数组
page:1, //当前页数
length:8, //每页能有多少个链接
isAuth:false, //是否授权
AuthCode:'', //授权码
loadComplete:false, //是否加载完成
isInclude:false, //是否搜索到任务
searchTask:[], //搜索到的任务
preDownloadGallery:false, //准备下载的本子
showHistory:false
}
const getters = {
@@ -243,6 +228,12 @@ const getters = {
},
loadComplete(state){
return state.loadComplete
},
preDownloadGallery(state){
return state.preDownloadGallery
},
showHistory(state){
return state.showHistory
}
}