加入标签搜索,优化搜索逻辑以及代码,加入部分注释,抽取简短名称的处理函数(同步更新)

This commit is contained in:
chuzhongzai 2022-12-30 12:51:14 +08:00
parent 9aca694f68
commit 69d45dd6ef
3 changed files with 373 additions and 419 deletions

View File

@ -3,24 +3,29 @@
<span>E站额度本周已用:{{weekUsed.weekUsedAmount}} 上次重置时间:{{weekUsed.lastResetAmountTime}}</span><br>
<el-button @click="queryWeekUsedAmount">查询用量</el-button>
<hr>
<el-input v-model="link" placeholder="输入链接"/>
<br>
<el-button @click="queryTask">查询远程任务</el-button>
<el-button @click="searchByLink">查找当前页任务</el-button>
<br>
<hr>
<br>
<el-input v-model="keyword" placeholder="输入关键字"/>
<br>
<el-button @click="searchRemoteByKeyword">查找所有任务</el-button>
<el-button @click="searchLocalByKeyword">查找当前页任务</el-button>
<el-row>
<el-col>
查询参数类型: <el-select style="width: 125px" v-model="type">
<el-option value="link" label="链接"/>
<el-option value="keyword" label="关键字"/>
<el-option value="tag" label="标签"/>
</el-select>
参数:
<el-input style="width: 250px;" v-model="param"></el-input>
</el-col>
<el-col>
<el-button @click="queryRemoteTask" v-show="type === 'link'">远程查询</el-button>
<el-button @click="queryLocalTask">当前页查询</el-button>
</el-col>
</el-row>
<br>
<hr>
<el-button @click="isAlterAuthCode = true">修改授权码</el-button>
<hr>
<div v-show="thumbnailGallery !== {}">
<span>
{{thumbnailGallery.shortName}}
{{thumbnailGallery.shortName}}<br>
<el-space v-show="thumbnailGallery.tag !== ''">标签:{{thumbnailGallery.tag}}</el-space>
</span><br>
<picture>
<el-image :src="thumbnailGallery.url" :preview-src-list="[thumbnailGallery.url,]" :initial-index="0" class="preview"></el-image>
@ -98,186 +103,167 @@
</div>
</template>
<script>
<script setup>
import store from "../store";
import {computed, ref, onMounted} from "vue";
import {ElMessage} from "element-plus"
export default {
name: "DashBoard",
setup(){
let AuthCode = ref("")
let isRemember = ref(false)
let isAlterAuthCode = ref(false)
let newAuthCode = ref("")
let tempAuthCode = ref("")
let keyword = ref("")
let link = ref("")
let targetResolution = ref("")
let realAuthCode = computed(() => {
return store.state.AuthCode
})
let AuthCode = ref("")
let isRemember = ref(false)
let isAlterAuthCode = ref(false)
let newAuthCode = ref("")
let tempAuthCode = ref("")
let chosenGallery = computed(() => {
return store.state.chosenGallery
})
let chosenVideo = computed(() => {
return store.state.chosenVideo
})
let type = ref("link")
let param = ref("")
let loadComplete = computed(() => {
return store.state.loadComplete
})
let targetResolution = ref("")
let maskDomain = computed(() => {
return store.state.maskDomain
})
let realAuthCode = computed(() => {
return store.state.AuthCode
})
let weekUsed = computed(() => {
return store.state.weekUsed
})
let chosenGallery = computed(() => {
return store.state.chosenGallery
})
let chosenVideo = computed(() => {
return store.state.chosenVideo
})
let thumbnailGallery = computed(() => {
return store.state.thumbnailGallery
})
let loadComplete = computed(() => {
return store.state.loadComplete
})
let maskDomain = computed(() => {
return store.state.maskDomain
})
let weekUsed = computed(() => {
return store.state.weekUsed
})
function alterAuthCode(){
if(newAuthCode.value.trim() === "" || tempAuthCode.value.trim() === "" || newAuthCode.value !== tempAuthCode.value)
ElMessage("请检查授权码输入是否错误")
else {
store.dispatch("alterAuthCode", newAuthCode.value)
isAlterAuthCode.value = false
newAuthCode.value = ""
tempAuthCode.value = ""
}
}
let thumbnailGallery = computed(() => {
return store.state.thumbnailGallery
})
function queryWeekUsedAmount(){
store.dispatch("loadWeekUsedAmount")
}
function postTask(){
if(!validateLink(link.value)){
ElMessage("链接错误")
return
}
if(targetResolution.value === ''){
ElMessage("请选择分辨率再提交")
return
}
let tempLink = coverLink(link.value)
if(link.value.includes("hentai")) {
store.dispatch("postGalleryTask", {link: tempLink, targetResolution: targetResolution.value})
targetResolution.value = ""
}
else {
store.dispatch("postVideoTask", {link: tempLink, targetResolution: targetResolution.value})
targetResolution.value = ""
}
}
function queryTask(){
if(!validateLink(link.value)){
ElMessage("链接错误")
return
}
let tempLink
if(link.value.includes("hentai")) {
tempLink = coverLink(link.value)
store.dispatch("queryGalleryTask", tempLink)
}
else{
tempLink = coverLink(link.value)
store.dispatch("queryVideoTask", tempLink)
}
}
function deleteVideo(){
store.dispatch("deleteVideo", chosenVideo.value.id)
}
function deleteGallery(){
store.dispatch("deleteGallery", chosenGallery.value.gid)
}
function validate(){
if(AuthCode.value.trim() === ""){
ElMessage("请输入授权码后再验证")
}
else{
store.dispatch("validate", AuthCode.value)
if(isRemember.value)
localStorage.setItem("auth", AuthCode.value)
}
}
function validateLink(rawLink){
if(rawLink.trim() === "")
return false
if(rawLink.includes("hentai")){
return rawLink.includes("/g/")
}
else if(rawLink.includes("xvideos.com")){
return true
}
else if(rawLink.includes("pornhub.com")){
return rawLink.includes("view_video.php")
}
}
function coverLink(rawLink){
let url = new URL(rawLink)
maskDomain.value.forEach((mask) => {
if(url.host === mask['raw'])
rawLink = rawLink.replace(mask['raw'], mask['mask'])
})
return rawLink;
}
function searchByLink() {
if(!validateLink(link.value)){
ElMessage("请检查输入的链接")
}
else {
store.dispatch("searchByLink", link.value)
}
}
function searchLocalByKeyword(){
console.log(keyword.value)
store.dispatch("searchLocalByKeyword",keyword.value)
}
function searchRemoteByKeyword(){
store.dispatch("searchRemoteByKeyword", keyword.value)
}
function onlineGalleryReader(name){
window.open("http://zfile.lionwebsite.xyz/1/gallery/" + encodeURI(name))
}
function showThumbnailGallery(gallery){
store.commit("_changeThumbnailGallery", gallery)
document.querySelector(".preview > img").click()
}
onMounted(() => {
const auth = localStorage.getItem("auth")
if(auth !== null){
store.dispatch("validate", auth)
AuthCode.value = localStorage.getItem("auth")
}
})
return {postTask, queryTask, validate, searchByLink, searchLocalByKeyword, searchRemoteByKeyword,
queryWeekUsedAmount, deleteVideo, deleteGallery, onlineGalleryReader, showThumbnailGallery, alterAuthCode,
link, loadComplete, AuthCode, realAuthCode, keyword, isRemember, chosenGallery, chosenVideo, targetResolution, weekUsed,
thumbnailGallery, isAlterAuthCode, newAuthCode, tempAuthCode,
store
}
//
function alterAuthCode(){
if(newAuthCode.value.trim() === "" || tempAuthCode.value.trim() === "" || newAuthCode.value !== tempAuthCode.value)
ElMessage("请检查授权码输入是否错误")
else {
store.dispatch("alterAuthCode", newAuthCode.value)
isAlterAuthCode.value = false
newAuthCode.value = ""
tempAuthCode.value = ""
}
}
//
function queryWeekUsedAmount(){
store.dispatch("loadWeekUsedAmount")
}
//
function postTask(){
if(!validateLink(param.value)){
ElMessage("链接错误")
return
}
if(targetResolution.value === ''){
ElMessage("请选择分辨率再提交")
return
}
let tempLink = coverLink(param.value)
if(param.value.includes("hentai"))
store.dispatch("postGalleryTask", {link: tempLink, targetResolution: targetResolution.value})
else
store.dispatch("postVideoTask", {link: tempLink, targetResolution: targetResolution.value})
targetResolution.value = ""
}
//
function queryRemoteTask(){
if(!validateLink(param.value)){
ElMessage("链接错误")
return
}
let tempLink = coverLink(param.value)
if(param.value.includes("hentai"))
store.dispatch("queryGalleryTask", tempLink)
else
store.dispatch("queryVideoTask", tempLink)
}
function queryLocalTask(){
switch (type.value){
case "link":
store.commit("_searchLocalByLink", param.value)
break
case "keyword":
store.commit("_searchLocalByKeyword", param.value)
break
case "tag":
store.commit("_searchLocalByTag", param.value.includes(",") ? param.value.split(","): [param.value])
break
}
}
//
function deleteVideo(){
store.dispatch("deleteVideo", chosenVideo.value.id)
}
function deleteGallery(){
store.dispatch("deleteGallery", chosenGallery.value.gid)
}
//
function validate(){
if(AuthCode.value.trim() === ""){
ElMessage("请输入授权码后再验证")
}
else{
store.dispatch("validate", AuthCode.value)
if(isRemember.value)
localStorage.setItem("auth", AuthCode.value)
}
}
//
function validateLink(rawLink){
if(rawLink.trim() === "")
return false
if(rawLink.includes("hentai")){
return rawLink.includes("/g/")
}
else if(rawLink.includes("xvideos.com")){
return true
}
else if(rawLink.includes("pornhub.com")){
return rawLink.includes("view_video.php")
}
}
function coverLink(rawLink){
let url = new URL(rawLink)
maskDomain.value.forEach((mask) => {
if(url.host === mask['raw'])
rawLink = rawLink.replace(mask['raw'], mask['mask'])
})
return rawLink;
}
//线
function onlineGalleryReader(name){
window.open("http://zfile.lionwebsite.xyz/1/gallery/" + encodeURI(name))
}
function showThumbnailGallery(gallery){
store.commit("_changeThumbnailGallery", gallery)
document.querySelector(".preview > img").click()
}
onMounted(() => {
const auth = localStorage.getItem("auth")
if(auth !== null){
store.dispatch("validate", auth)
AuthCode.value = localStorage.getItem("auth")
}
})
</script>
<style scoped>
@ -287,7 +273,6 @@ export default {
background-color: ghostwhite;
text-align: center;
}
.el-input{
width: 300px;
}

View File

@ -133,173 +133,158 @@
</div>
</template>
<script>
<script setup>
import store from "../store";
import {computed, ref} from "vue";
export default {
name: "Side",
setup(){
let inputNode = ref(null)
let isEditingPage = ref(false)
let isEditingTag = ref(false)
let tempTag = ref("")
let tempGid = ref("")
let showNameType = ref("shortName") // shortName name
let showType = ref("gallery") // gallery video collect
let sortType = ref("shortName") // shortName name createTime
let targetPage = ref(1)
let debounceTimer = 0
let loadComplete = computed(() => {
return store.state.loadComplete
})
//
let inputNode = ref(null)
//
let isEditingPage = ref(false)
//
let isEditingTag = ref(false)
//
let tempTag = ref("")
let tempGid = ref("")
let galleryTasks = computed(() => {
return store.getters.galleryTasks ? store.getters.galleryTasks: null
})
let videoTasks = computed(() => {
return store.getters.videoTasks ? store.getters.videoTasks: null
})
let showNameType = ref("shortName") // shortName name
let showType = ref("gallery") // gallery video collect
let sortType = ref("shortName") // shortName name createTime
let targetPage = ref(1)
let isShowVideoHistory = computed(() => {
return store.state.showType === "video"
})
//
let debounceTimer = 0
//
let loadComplete = computed(() => {
return store.state.loadComplete
})
let isShowGalleryHistory = computed(() => {
return store.state.showType === "gallery" || store.state.showType === "collect"
})
let galleryTasks = computed(() => {
return store.getters.galleryTasks ? store.getters.galleryTasks: null
})
let videoTasks = computed(() => {
return store.getters.videoTasks ? store.getters.videoTasks: null
})
let min = computed(() => {
return store.getters.min
})
let isShowVideoHistory = computed(() => {
return store.state.showType === "video"
})
let isShowGalleryHistory = computed(() => {
return store.state.showType === "gallery" || store.state.showType === "collect"
})
let max = computed(() => {
if(targetPage.value > store.getters.max)
store.commit("_changePage", store.getters.max)
return store.getters.max
})
let min = computed(() => {
return store.getters.min
})
let max = computed(() => {
if(targetPage.value > store.getters.max)
store.commit("_changePage", store.getters.max)
return store.getters.max
})
let page = computed(() => {
targetPage.value = store.state.page
return store.state.page
})
let page = computed(() => {
targetPage.value = store.state.page
return store.state.page
})
function next() {
if(targetPage.value < max.value) {
targetPage.value++
store.commit("_changePage", targetPage.value)
}
}
function previous() {
if(targetPage.value > min.value) {
targetPage.value--
store.commit("_changePage", targetPage.value)
}
}
function toMax() {
store.commit("_changePage", max.value)
targetPage.value = max.value
}
function toMin(){
store.commit("_changePage", min.value)
targetPage.value = min.value
}
function changePage(){
if(targetPage.value >= min.value && targetPage.value <= max.value)
store.commit("_changePage", targetPage.value)
}
function changeShowType(){
store.commit("_setShowType", showType.value)
}
function changeShowNameType(){
store.commit("_setShowNameType", showNameType.value)
if(showNameType.value !== sortType.value){
store.commit("_setSortType", showNameType.value)
sortType.value = showNameType.value
}
}
function changeSortType(){
store.commit("_setSortType", sortType.value)
if(sortType.value !== showNameType.value && sortType.value !== "createTime") {
store.commit("_setShowNameType", sortType.value)
showNameType.value = sortType.value
}
}
function changeCollect(gid, isCollect){
if(isCollect)
store.dispatch("disCollectGallery", gid)
else
store.dispatch("collectGallery", gid)
}
function editTag(gid, tag){
tempTag.value = tag
tempGid.value = gid
isEditingTag.value = true
}
function submitTag(){
store.dispatch("updateTag", {gid:tempGid.value, tag:tempTag.value})
tempTag.value = ''
tempGid.value = ''
isEditingTag.value = false
}
function reverseEditMode(){
isEditingPage.value = !isEditingPage.value
if(isEditingPage.value){
inputNode.value.focus()
}
targetPage.value = page.value
}
function downloadTask(link){
window.open(link)
}
function deleteGallery(gid){
store.dispatch("deleteGallery", gid)
}
function deleteVideo(id){
store.dispatch("deleteVideo", id)
}
function onlineGalleryReader(name){
window.open("http://zfile.lionwebsite.xyz/1/gallery/" + encodeURI(name))
}
function onlineVideoViewer(){
window.open("http://zfile.lionwebsite.xyz/1/video/")
}
function showThumbnail(gallery){
if(gallery.download !== undefined)
clearTimeout(debounceTimer)
debounceTimer = setTimeout(() => {
store.commit("_changeThumbnailGallery", gallery)
}, 500)
}
return {galleryTasks, videoTasks, min, max, targetPage, loadComplete, page, isEditingPage, isEditingTag, inputNode, isShowVideoHistory,
isShowGalleryHistory, showType, showNameType, sortType, tempTag, tempGid,
reverseEditMode, changePage, changeShowType, changeShowNameType, changeSortType, changeCollect, toMax, toMin, previous, next, downloadTask, deleteGallery,
deleteVideo, onlineGalleryReader, onlineVideoViewer, showThumbnail, editTag, submitTag,
store
}
//
function next() {
if(targetPage.value < max.value) {
targetPage.value++
store.commit("_changePage", targetPage.value)
}
}
function previous() {
if(targetPage.value > min.value) {
targetPage.value--
store.commit("_changePage", targetPage.value)
}
}
function toMax() {
store.commit("_changePage", max.value)
targetPage.value = max.value
}
function toMin(){
store.commit("_changePage", min.value)
targetPage.value = min.value
}
function changePage(){
if(targetPage.value >= min.value && targetPage.value <= max.value)
store.commit("_changePage", targetPage.value)
}
function reverseEditMode(){
isEditingPage.value = !isEditingPage.value
if(isEditingPage.value){
inputNode.value.focus()
}
targetPage.value = page.value
}
//
function changeShowType(){
store.commit("_setShowType", showType.value)
}
function changeShowNameType(){
store.commit("_setShowNameType", showNameType.value)
if(showNameType.value !== sortType.value){
store.commit("_setSortType", showNameType.value)
sortType.value = showNameType.value
}
}
function changeSortType(){
store.commit("_setSortType", sortType.value)
if(sortType.value !== showNameType.value && sortType.value !== "createTime") {
store.commit("_setShowNameType", sortType.value)
showNameType.value = sortType.value
}
}
//,,
function changeCollect(gid, isCollect){
if(isCollect)
store.dispatch("disCollectGallery", gid)
else
store.dispatch("collectGallery", gid)
}
function editTag(gid, tag){
tempTag.value = tag
tempGid.value = gid
isEditingTag.value = true
}
function submitTag(){
store.dispatch("updateTag", {gid:tempGid.value, tag:tempTag.value})
tempTag.value = ''
tempGid.value = ''
isEditingTag.value = false
}
//线
function downloadTask(link){
window.open(link)
}
function deleteGallery(gid){
store.dispatch("deleteGallery", gid)
}
function deleteVideo(id){
store.dispatch("deleteVideo", id)
}
function onlineGalleryReader(name){
window.open("http://zfile.lionwebsite.xyz/1/gallery/" + encodeURI(name))
}
function onlineVideoViewer(){
window.open("http://zfile.lionwebsite.xyz/1/video/")
}
//
function showThumbnail(gallery){
if(gallery.download !== undefined)
clearTimeout(debounceTimer)
debounceTimer = setTimeout(() => {
store.commit("_changeThumbnailGallery", gallery)
}, 500)
}
</script>
<style scoped>
@ -311,8 +296,9 @@ export default {
display: block;
}
.pageChanger{
position: absolute;
top: 85vh;
/*position: absolute;*/
/*top: 85vh;*/
margin-top: 5vh;
}
.el-select{
width: 125px;

View File

@ -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
}
}