加入标签编辑跟收藏

This commit is contained in:
chuzhongzai
2022-12-29 19:16:30 +08:00
parent aca3da4b7b
commit 9aca694f68
2 changed files with 165 additions and 38 deletions
+93 -2
View File
@@ -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,6 +149,37 @@ const actions = {
ElMessage("查询用量失败")
})
},
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)
}
})
},
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)
}
})
},
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)
}
})
},
searchByLink(context, link){
context.commit("_searchByLink", link)
},
@@ -232,11 +264,39 @@ 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
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)
state.collectGallery.slice(0)
tasks.forEach((task) => {
//处理名字
if (task.name.includes("[")) {
let name = task.name
let lastIndex = name.lastIndexOf("[")
@@ -258,6 +318,7 @@ const mutations = {
task.shortName = task.name
}
//处理进度相关
switch (task.status) {
case "已提交":
task.progress = "已提交"
@@ -277,7 +338,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)
})
}
@@ -509,6 +592,7 @@ const state = {
totalGalleryTask:[], //存放本子数据的数组
chosenGallery:false, //准备下载的本子
thumbnailGallery:{},
collectGallery:[], //收藏的本子
totalVideoTask:[], //存放视频数据的数组
chosenVideo:false, //准备下载的视频
@@ -518,6 +602,7 @@ const state = {
defaultLength:7, //默认个数
shortLength:10, //简洁个数
userId:-1,
isAuth:false, //是否授权
AuthCode:'', //授权码
loadComplete:false, //是否加载完成
@@ -535,6 +620,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)
@@ -554,9 +641,10 @@ 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
@@ -569,6 +657,9 @@ const getters = {
if(tasks.length % state.length !== 0){
max += 1
}
if(max === 0)
return 1
return max
}
}