加入标签搜索,优化搜索逻辑以及代码,加入部分注释,抽取简短名称的处理函数(同步更新)
This commit is contained in:
+66
-83
@@ -155,9 +155,8 @@ const actions = {
|
||||
id:state.userId
|
||||
})).then((res) => {
|
||||
ElMessage(res.data.data)
|
||||
if(res.data.result === 'success'){
|
||||
if(res.data.result === 'success')
|
||||
context.commit("_collectGallery", gid)
|
||||
}
|
||||
})
|
||||
},
|
||||
disCollectGallery(context, gid){
|
||||
@@ -167,57 +166,17 @@ const actions = {
|
||||
id:state.userId
|
||||
})).then((res) => {
|
||||
ElMessage(res.data.data)
|
||||
if(res.data.result === 'success'){
|
||||
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'){
|
||||
if(res.data.result === 'success')
|
||||
context.commit("_updateTag", data)
|
||||
}
|
||||
})
|
||||
},
|
||||
searchByLink(context, link){
|
||||
context.commit("_searchByLink", link)
|
||||
},
|
||||
searchLocalByKeyword(context, keyword){
|
||||
context.commit("_searchLocalByKeyword", keyword)
|
||||
},
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
deleteGallery(context, gid){
|
||||
axios.delete(GalleryManageUrl, {
|
||||
params:{
|
||||
@@ -278,9 +237,8 @@ const mutations = {
|
||||
if(gallery.isCollect && gallery.gid === gid)
|
||||
gallery.isCollect = false
|
||||
|
||||
if(gallery.isCollect)
|
||||
else if(gallery.isCollect)
|
||||
state.collectGallery.push(gallery)
|
||||
|
||||
})
|
||||
},
|
||||
_updateTag(state, data){
|
||||
@@ -297,26 +255,7 @@ const mutations = {
|
||||
state.collectGallery.slice(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) {
|
||||
@@ -469,28 +408,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("已跳转到该任务所在页数")
|
||||
}
|
||||
},
|
||||
_searchLocalByKeyword(state, keyword){
|
||||
state.searchTask.splice(0)
|
||||
@@ -510,6 +448,29 @@ const mutations = {
|
||||
}
|
||||
}
|
||||
},
|
||||
_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){
|
||||
@@ -525,11 +486,12 @@ 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 = "等待下载完成后再查看"
|
||||
state.chosenGallery.progress = "已提交"
|
||||
state.chosenGallery.tag = ""
|
||||
state.totalGalleryTask.push(state.chosenGallery)
|
||||
}
|
||||
state.chosenGallery = data.gallery
|
||||
@@ -602,7 +564,7 @@ const state = {
|
||||
defaultLength:7, //默认个数
|
||||
shortLength:10, //简洁个数
|
||||
|
||||
userId:-1,
|
||||
userId:-1, //用户id
|
||||
isAuth:false, //是否授权
|
||||
AuthCode:'', //授权码
|
||||
loadComplete:false, //是否加载完成
|
||||
@@ -610,7 +572,6 @@ const state = {
|
||||
|
||||
isInclude:false, //是否搜索到任务
|
||||
searchTask:[], //搜索到的任务
|
||||
showHistory:'', //是否打开面板
|
||||
showType:'gallery', //展示类型
|
||||
sortType:'shortName', //排序类型
|
||||
weekUsed:{}, //每周用量
|
||||
@@ -651,12 +612,13 @@ const getters = {
|
||||
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
|
||||
@@ -671,3 +633,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