加入收藏以及标签,优化搜索,优化翻页的位置,加入部分注释,抽取简短名称的处理函数(同步更新)
This commit is contained in:
+145
-75
@@ -119,6 +119,7 @@ const actions = {
|
||||
validate(context, AuthCode){
|
||||
axios.post(BaseUrl + "validate?AuthCode=" + AuthCode).then((res)=>{
|
||||
if(res.data.result === 'success'){
|
||||
state.userId = parseInt(res.data.data)
|
||||
context.commit("_authed", AuthCode)
|
||||
context.dispatch("loadMaskDomain").then()
|
||||
context.dispatch("loadWeekUsedAmount").then()
|
||||
@@ -148,43 +149,33 @@ const actions = {
|
||||
ElMessage("查询用量失败")
|
||||
})
|
||||
},
|
||||
searchByLink(context, link){
|
||||
context.commit("_searchByLink", link)
|
||||
collectGallery(context, gid){
|
||||
axios.post(GalleryManageUrl + "/collect?" +qs.stringify( {
|
||||
gid,
|
||||
id:state.userId
|
||||
})).then((res) => {
|
||||
ElMessage(res.data.data)
|
||||
if(res.data.result === 'success')
|
||||
context.commit("_collectGallery", gid)
|
||||
})
|
||||
},
|
||||
searchLocalByKeyword(context, keyword){
|
||||
context.commit("_searchLocalByKeyword", keyword)
|
||||
disCollectGallery(context, gid){
|
||||
axios.post(GalleryManageUrl + "/disCollect?" + qs.stringify(
|
||||
{
|
||||
gid,
|
||||
id:state.userId
|
||||
})).then((res) => {
|
||||
ElMessage(res.data.data)
|
||||
if(res.data.result === 'success')
|
||||
context.commit("_disCollectGallery", gid)
|
||||
})
|
||||
},
|
||||
searchRemoteByKeyword(context, keyword){
|
||||
if(context.state.showType === "gallery"){
|
||||
axios.get(GalleryManageUrl, {
|
||||
params:{
|
||||
type:"name",
|
||||
param:keyword
|
||||
}
|
||||
}).then((res) => {
|
||||
if(res.data.result === 'success'){
|
||||
context.commit("_setChosenGallery", {'gallery':JSON.parse(res.data.data)})
|
||||
}
|
||||
else{
|
||||
ElMessage(res.data.data)
|
||||
}
|
||||
})
|
||||
}
|
||||
else{
|
||||
axios.get(VideoManageUrl, {
|
||||
params:{
|
||||
type:"name",
|
||||
param:keyword
|
||||
}
|
||||
}).then((res) => {
|
||||
if(res.data.result === 'success'){
|
||||
context.commit("_setChosenVideo", {'video': JSON.parse(res.data.data)})
|
||||
}
|
||||
else{
|
||||
ElMessage(res.data.data)
|
||||
}
|
||||
})
|
||||
}
|
||||
updateTag(context, data){
|
||||
axios.post(GalleryManageUrl + "/tag?" + qs.stringify(data)).then((res) => {
|
||||
ElMessage(res.data.data)
|
||||
if(res.data.result === 'success')
|
||||
context.commit("_updateTag", data)
|
||||
})
|
||||
},
|
||||
deleteGallery(context, gid){
|
||||
axios.delete(GalleryManageUrl, {
|
||||
@@ -231,32 +222,40 @@ const actions = {
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
_collectGallery(state, gid){
|
||||
state.totalGalleryTask.forEach((gallery) => {
|
||||
if(!gallery.isCollect && gallery.gid === gid){
|
||||
gallery.isCollect = true
|
||||
state.collectGallery.push(gallery)
|
||||
}
|
||||
})
|
||||
},
|
||||
_disCollectGallery(state, gid){
|
||||
state.collectGallery.splice(0)
|
||||
state.totalGalleryTask.forEach((gallery) => {
|
||||
if(gallery.isCollect && gallery.gid === gid)
|
||||
gallery.isCollect = false
|
||||
|
||||
else if(gallery.isCollect)
|
||||
state.collectGallery.push(gallery)
|
||||
})
|
||||
},
|
||||
_updateTag(state, data){
|
||||
state.totalGalleryTask.forEach((gallery) => {
|
||||
if(gallery.gid === data.gid){
|
||||
gallery.tag = data.tag
|
||||
}
|
||||
})
|
||||
},
|
||||
_updateGalleryTasks(state, data){
|
||||
let {tasks, type} = data
|
||||
if(type === 'all') {
|
||||
state.totalGalleryTask.splice(0)
|
||||
tasks.forEach((task) => {
|
||||
if (task.name.includes("[")) {
|
||||
let name = task.name
|
||||
let lastIndex = name.lastIndexOf("[")
|
||||
name = name.substring(0, lastIndex)
|
||||
while (name.includes("[") && name.includes("]")) {
|
||||
let start = name.indexOf("[")
|
||||
let end = name.indexOf("]") + 1
|
||||
let temp = name.substring(start, end)
|
||||
name = name.replace(temp, "")
|
||||
}
|
||||
while (name.includes("(") && name.includes(")")) {
|
||||
let start = name.indexOf("(")
|
||||
let end = name.indexOf(")") + 1
|
||||
let temp = name.substring(start, end)
|
||||
name = name.replace(temp, "")
|
||||
}
|
||||
task.shortName = name.trim()
|
||||
} else {
|
||||
task.shortName = task.name
|
||||
}
|
||||
//处理名字
|
||||
task.shortName = getShortname(task.name)
|
||||
|
||||
//处理进度相关
|
||||
switch (task.status) {
|
||||
case "已提交":
|
||||
task.progress = "已提交"
|
||||
@@ -276,7 +275,29 @@ const mutations = {
|
||||
break;
|
||||
}
|
||||
|
||||
//处理时间戳
|
||||
task.createTimeDisplay = moment(task.createTime * 1000).format("YYYY-MM-DD HH:mm:ss")
|
||||
|
||||
//处理标签
|
||||
if (task.tag === undefined) {
|
||||
task.tag = ""
|
||||
}
|
||||
|
||||
//处理是否收藏
|
||||
if(task.collector !== undefined){
|
||||
let collector = task.collector.split(",")
|
||||
task.collector = undefined
|
||||
collector.forEach((id) => {
|
||||
if(parseInt(id) === state.userId) {
|
||||
task.isCollect = true
|
||||
state.collectGallery.push(task)
|
||||
}
|
||||
})
|
||||
|
||||
if(task.isCollect === undefined)
|
||||
task.isCollect = false
|
||||
}
|
||||
|
||||
state.totalGalleryTask.push(task)
|
||||
})
|
||||
}
|
||||
@@ -385,29 +406,27 @@ const mutations = {
|
||||
ElMessage("授权码错误")
|
||||
localStorage.removeItem("auth")
|
||||
},
|
||||
_searchByLink(state, link){
|
||||
_searchLocalByLink(state, link){
|
||||
let tasks
|
||||
if(state.showType === "gallery") {
|
||||
tasks = state.totalGalleryTask
|
||||
}
|
||||
else
|
||||
tasks = state.totalVideoTask
|
||||
let i = 0
|
||||
let found = false
|
||||
for (i = 0; i < tasks.length; i++) {
|
||||
|
||||
if(state.showType === "gallery")
|
||||
tasks = state.totalGalleryTask
|
||||
else
|
||||
tasks = state.totalVideoTask
|
||||
|
||||
for (i = 0; i < tasks.length; i++)
|
||||
if (tasks[i].link === link) {
|
||||
state.page = Math.floor(i / state.length) + 1
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if(!found){
|
||||
|
||||
if(!found)
|
||||
ElMessage("未找到此任务")
|
||||
}
|
||||
else{
|
||||
else
|
||||
ElMessage("已跳转到该任务所在页数")
|
||||
state.isShowHistory = true
|
||||
}
|
||||
},
|
||||
_searchLocalByKeyword(state, keyword){
|
||||
state.searchTask.splice(0)
|
||||
@@ -424,11 +443,32 @@ const mutations = {
|
||||
})
|
||||
if (state.searchTask.length === 0) {
|
||||
ElMessage("未找到该关键字的任务")
|
||||
} else {
|
||||
state.isShowHistory = true
|
||||
}
|
||||
}
|
||||
},
|
||||
_searchLocalByTag(state, tags) {
|
||||
state.searchTask.splice(0)
|
||||
state.page = 1
|
||||
|
||||
let tagAmount = tags.length
|
||||
let hitAmount
|
||||
let tasks = state.totalGalleryTask
|
||||
|
||||
if (tags[0].trim() !== '') {
|
||||
tasks.forEach((task) => {
|
||||
hitAmount = 0
|
||||
tags.forEach((tag) => {
|
||||
if (task.tag.includes(tag))
|
||||
hitAmount++
|
||||
})
|
||||
if (hitAmount === tagAmount)
|
||||
state.searchTask.push(task)
|
||||
})
|
||||
|
||||
if (state.searchTask.length === 0)
|
||||
ElMessage("未找到符合这些tag的任务")
|
||||
}
|
||||
},
|
||||
_deleteGallery(state, gid){
|
||||
state.totalGalleryTask.forEach((item, index, arr) => {
|
||||
if(item.gid === gid){
|
||||
@@ -444,7 +484,7 @@ const mutations = {
|
||||
},
|
||||
_setChosenGallery(state,data){
|
||||
if(data.gallery === false) {
|
||||
//state.chosenGallery.shortName = getShortName(state.chosenGallery.name)
|
||||
state.chosenGallery.shortName = getShortname(state.chosenGallery.name)
|
||||
state.chosenGallery.resolution = data.resolution
|
||||
state.chosenGallery.fileSize = "等待下载完成后再查看"
|
||||
state.chosenGallery.createTimeDisplay = "等待下载完成后再查看"
|
||||
@@ -517,6 +557,7 @@ const state = {
|
||||
totalGalleryTask:[], //存放本子数据的数组
|
||||
chosenGallery:false, //准备下载的本子
|
||||
thumbnailGallery:{}, //预览本子
|
||||
collectGallery:[], //收藏的本子
|
||||
|
||||
totalVideoTask:[], //存放视频数据的数组
|
||||
chosenVideo:false, //准备下载的视频
|
||||
@@ -526,6 +567,7 @@ const state = {
|
||||
defaultLength:4, //默认个数
|
||||
shortLength:5, //简洁个数
|
||||
|
||||
userId:-1, //用户id
|
||||
isAuth:false, //是否授权
|
||||
AuthCode:'', //授权码
|
||||
loadComplete:false, //是否加载完成
|
||||
@@ -543,6 +585,8 @@ const state = {
|
||||
|
||||
const getters = {
|
||||
galleryTasks(state){
|
||||
if(state.showType === 'collect')
|
||||
return state.collectGallery.slice((state.page-1)*state.length, state.page*state.length)
|
||||
if(state.searchTask.length !== 0)
|
||||
return state.searchTask.slice((state.page-1)*state.length, state.page*state.length)
|
||||
if(state.totalGalleryTask.length !== 0)
|
||||
@@ -562,21 +606,26 @@ const getters = {
|
||||
max(state){
|
||||
let max = 0
|
||||
let tasks
|
||||
if(state.searchTask.length !== 0){
|
||||
if(state.showType === 'collect')
|
||||
tasks = state.collectGallery
|
||||
else if(state.searchTask.length !== 0)
|
||||
tasks = state.searchTask
|
||||
}
|
||||
else if(state.showType === "gallery")
|
||||
if(state.totalGalleryTask.length !== 0)
|
||||
tasks = state.totalGalleryTask
|
||||
else if(state.showType === "video")
|
||||
if(state.totalVideoTask.length)
|
||||
tasks = state.totalVideoTask
|
||||
|
||||
if(!tasks)
|
||||
return 1
|
||||
|
||||
max = Math.floor(tasks.length/state.length)
|
||||
if(tasks.length % state.length !== 0){
|
||||
if(tasks.length % state.length !== 0)
|
||||
max += 1
|
||||
}
|
||||
|
||||
if(max === 0)
|
||||
return 1
|
||||
return max
|
||||
}
|
||||
}
|
||||
@@ -588,3 +637,24 @@ export default new vuex.Store({
|
||||
getters
|
||||
})
|
||||
|
||||
function getShortname(name){
|
||||
if (name.includes("[")) {
|
||||
let lastIndex = name.lastIndexOf("[")
|
||||
name = name.substring(0, lastIndex)
|
||||
while (name.includes("[") && name.includes("]")) {
|
||||
let start = name.indexOf("[")
|
||||
let end = name.indexOf("]") + 1
|
||||
let temp = name.substring(start, end)
|
||||
name = name.replace(temp, "")
|
||||
}
|
||||
while (name.includes("(") && name.includes(")")) {
|
||||
let start = name.indexOf("(")
|
||||
let end = name.indexOf(")") + 1
|
||||
let temp = name.substring(start, end)
|
||||
name = name.replace(temp, "")
|
||||
}
|
||||
return name.trim()
|
||||
} else {
|
||||
return name
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user