From 34b1fdaadfe93b248066d14dfb5a458cedee10df Mon Sep 17 00:00:00 2001 From: emm Date: Tue, 6 Sep 2022 23:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=EF=BC=8C=E8=AF=A5=E9=A1=B9=E7=9B=AE=E4=B8=BALionWebsite?= =?UTF-8?q?=E7=9A=84=E7=A7=BB=E5=8A=A8=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 13 ++ src/App.vue | 23 ++ src/components/DashBoard.vue | 251 ++++++++++++++++++++++ src/components/Side.vue | 271 +++++++++++++++++++++++ src/main.js | 7 + src/store/index.js | 402 +++++++++++++++++++++++++++++++++++ 6 files changed, 967 insertions(+) create mode 100644 index.html create mode 100644 src/App.vue create mode 100644 src/components/DashBoard.vue create mode 100644 src/components/Side.vue create mode 100644 src/main.js create mode 100644 src/store/index.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..795e4fb --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + Vue + + +
+ + + diff --git a/src/App.vue b/src/App.vue new file mode 100644 index 0000000..fd6366c --- /dev/null +++ b/src/App.vue @@ -0,0 +1,23 @@ + + + + + diff --git a/src/components/DashBoard.vue b/src/components/DashBoard.vue new file mode 100644 index 0000000..7385705 --- /dev/null +++ b/src/components/DashBoard.vue @@ -0,0 +1,251 @@ + + + + + \ No newline at end of file diff --git a/src/components/Side.vue b/src/components/Side.vue new file mode 100644 index 0000000..bb78b5b --- /dev/null +++ b/src/components/Side.vue @@ -0,0 +1,271 @@ + + + + + \ No newline at end of file diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..90dbba4 --- /dev/null +++ b/src/main.js @@ -0,0 +1,7 @@ +import { createApp } from 'vue' +import App from './App.vue' +import 'element-plus/dist/index.css' +import element from "element-plus" +import "./reset.css" + +createApp(App).use(element).mount('#app') diff --git a/src/store/index.js b/src/store/index.js new file mode 100644 index 0000000..5a4bd7d --- /dev/null +++ b/src/store/index.js @@ -0,0 +1,402 @@ +import vuex from "vuex" +import axios from "axios" +import {ElMessage} from "element-plus" +import qs from "qs" +const BaseUrl = "http://100.42.234.138:8888/" +const GalleryTaskHandlerUrl = BaseUrl + "GalleryTaskHandler/" +const VideoTaskHandlerUrl = BaseUrl + "VideoTaskHandler/" + +const actions = { + updateGalleryTasks(context){ + const AuthCode = context.state.AuthCode + axios.get(GalleryTaskHandlerUrl, { + params:{ + param:"", + type:"all", + AuthCode + } + }).then((res) => { + let temp = [] + context.commit("_emptyGalleryTasks") + JSON.parse(res.data.data).forEach((task) => { + temp.push(task) + }) + context.commit("_updateGalleryTasks", temp) + + }) + }, + updateVideoTasks(context){ + const AuthCode = context.state.AuthCode + axios.get(VideoTaskHandlerUrl, { + params:{ + param:"123", + type:"all", + AuthCode + } + }).then(res => { + let temp = [] + context.commit("_emptyVideoTasks") + JSON.parse(res.data.data).forEach(task => { + temp.push(task) + }) + context.commit("_updateVideoTasks", temp) + }) + }, + postGalleryTask(context, data){ + axios.post(GalleryTaskHandlerUrl, qs.stringify({ + AuthCode:context.state.AuthCode, + link:data.link, + targetResolution:data.targetResolution + })).then((res) => { + if(res.data.result === "success") { + ElMessage("提交成功") + context.commit("_setPreDownloadGallery", {gallery:false, resolution:data.targetResolution}) + } + else{ + if(res.data.data) + ElMessage(res.data.data) + else{ + ElMessage("提交失败") + } + } + }) + }, + postVideoTask(context, data){ + axios.post(VideoTaskHandlerUrl, qs.stringify({ + AuthCode:context.state.AuthCode, + link: data.link, + targetResolution: data.targetResolution + })).then((res) => { + if(res.data.result === "success") { + ElMessage("提交成功") + context.commit("_setPreDownloadVideo", {video:false, resolution:data.targetResolution}) + } + else{ + if(res.data.data) + ElMessage(res.data.data) + else{ + ElMessage("提交失败") + } + } + }) + }, + queryGalleryTask(context, link){ + const AuthCode = context.state.AuthCode + axios.get(GalleryTaskHandlerUrl, { + params:{ + param:link, + type:'link', + AuthCode + } + }).then((res) => { + if(res.data.result === 'success'){ + const gallery = JSON.parse(res.data.data) + context.commit("_setPreDownloadGallery", {gallery}) + } + else + ElMessage("查询失败") + }) + }, + queryVideoTask(context, link){ + const AuthCode = context.state.AuthCode + axios.get(VideoTaskHandlerUrl, { + params:{ + param: link, + type:"link", + AuthCode + } + }).then((res) => { + if(res.data.result === 'success'){ + const video = JSON.parse(res.data.data) + context.commit("_setPreDownloadVideo", {video}) + } + else + ElMessage("查询失败") + }) + }, + validate(context, AuthCode){ + axios.post(BaseUrl + "validate?AuthCode=" + AuthCode).then((res)=>{ + if(res.data.result === 'success'){ + context.commit("_authed", AuthCode, context) + context.dispatch("updateGalleryTasks").then() + context.dispatch("updateVideoTasks").then() + setInterval(() => { + context.dispatch("update").then() + }, 30000) + } + else{ + context.commit("_unAuthed") + } + }) + }, + update(context){ + if(context.state.showType === "video") + context.dispatch("updateVideoTasks").then() + else + context.dispatch("updateGalleryTasks").then() + }, + searchByLink(context, link){ + context.commit("_searchByLink", link) + }, + searchByKeyword(context, keyword){ + context.commit("_searchByKeyword", keyword) + }, + deleteGallery(context, gid){ + axios.delete(GalleryTaskHandlerUrl, { + params:{ + AuthCode:state.AuthCode, + gid + }}).then((res) => { + if(res.data.result === "success"){ + ElMessage("删除成功") + context.commit("_deleteGallery", gid) + } + else{ + ElMessage(res.data.data) + } + }) + }, + deleteVideo(context, id){ + axios.delete(VideoTaskHandlerUrl, { + params:{ + AuthCode:state.AuthCode, + id + } + }).then((res) => { + if(res.data.result === "success"){ + ElMessage("删除成功") + context.commit("_deleteVideo", id) + } + else{ + ElMessage(res.data.data) + } + }) + } +} + +const mutations = { + _emptyGalleryTasks(state){ + state.totalGalleryTask.splice(0) + }, + _emptyVideoTasks(state){ + state.totalVideoTask.splice(0) + }, + _updateGalleryTasks(state, tasks){ + const download_url = GalleryTaskHandlerUrl + "file?link=" + tasks.forEach((task) => { + if(task.status === "已提交"){ + task.progress = "已提交" + } + else if(task.status === "下载中"){ + task.progress = (Math.round((task.proceeding / task.pages)*100)).toString() + "%" + } + else if(task.status === "下载完成"){ + task.progress = "下载完成" + task.download = download_url + task.link + "&AuthCode=" + state.AuthCode + } + state.totalGalleryTask.push(task) + }) + if(state.isAuth && !state.loadComplete){ + state.loadComplete = true + ElMessage("加载完成") + } + }, + _updateVideoTasks(state, tasks){ + const downloadUrl = VideoTaskHandlerUrl + "file?link=" + tasks.forEach((task) => { + task.progress = task.status + if(task.status === "下载完成"){ + let tempLink + if(task.link.includes("xvideos.com")) + tempLink = task.link.replace("xvideos", "xiaomi") + else if(task.link.includes("cn.pornhub")) + tempLink = task.link.replace("cn.pornhub", "pixiv") + else + tempLink = task.link.replace("pornhub", "pixiv") + task.download = downloadUrl + tempLink + "&AuthCode=" + state.AuthCode + } + state.totalVideoTask.push(task) + }) + }, + _changePage(state, targetPage){ + state.page = targetPage + }, + _authed(state, AuthCode){ + state.AuthCode = AuthCode + state.isAuth = true + ElMessage("验证成功,加载中") + }, + _unAuthed(state){ + state.isAuth = false + state.AuthCode = "" + ElMessage("授权码错误") + localStorage.removeItem("auth") + }, + _searchByLink(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 (tasks[i].link === link) { + state.page = Math.floor(i / state.length) + 1 + found = true + break + } + } + if(!found){ + ElMessage("未找到此任务") + } + else{ + ElMessage("已跳转到该任务所在页数") + } + }, + _searchByKeyword(state, keyword){ + state.searchTask.splice(0) + state.page = 1 + let tasks + if(state.showType === "video") + tasks = state.totalVideoTask + else + tasks = state.totalGalleryTask + tasks.forEach((task) => { + if(task.name.includes(keyword)) + state.searchTask.push(task) + }) + if(state.searchTask.length === 0){ + ElMessage("未找到该关键字的任务") + } + }, + _deleteGallery(state, gid){ + state.totalGalleryTask.forEach((item, index, arr) => { + if(item.gid === gid){ + arr.splice(index, 1) + } + }) + }, + _deleteVideo(state, id){ + state.totalVideoTask.forEach((item, index, arr) => { + if(item.id === id) + arr.splice(index, 1) + }) + }, + _setPreDownloadGallery(state,data){ + if(data.gallery === false) { + state.preDownloadGallery.resolution = data.resolution + state.preDownloadGallery.fileSize = "等待下载完成后再查看" + state.totalGalleryTask.push(state.preDownloadGallery) + } + state.preDownloadGallery = data.gallery + }, + _setPreDownloadVideo(state,data){ + if(data.video === false) { + state.preDownloadVideo.resolution = data.resolution + state.preDownloadVideo.fileSize = "下载完成后再查看" + state.preDownloadVideo.duration = "下载完成后再查看" + state.totalVideoTask.push(state.preDownloadVideo) + } + state.preDownloadVideo = data.video + }, + _setShowType(state, showType){ + state.showType = showType + }, + _openHistoryPanel(state){ + state.isShowHistory = true + }, + _closeHistoryPanel(state){ + state.isShowHistory = false + } +} + +const state = { + totalGalleryTask:[], //存放本子数据的数组 + preDownloadGallery:false, //准备下载的本子 + + totalVideoTask:[], //存放视频数据的数组 + preDownloadVideo:false, //准备下载的视频 + + page:1, //当前页数 + length:8, //每页能有多少个链接 + + isAuth:false, //是否授权 + AuthCode:'', //授权码 + loadComplete:false, //是否加载完成 + + isInclude:false, //是否搜索到任务 + searchTask:[], //搜索到的任务 + isShowHistory:false, //是否打开面板 + showType:"gallery" +} + +const getters = { + galleryTasks(state){ + if(state.searchTask.length !== 0) + return state.searchTask.slice((state.page-1)*state.length, state.page*state.length) + if(state.totalGalleryTask.length !== 0) + return state.totalGalleryTask.slice((state.page-1)*state.length, state.page*state.length) + return null + }, + videoTasks(state){ + if(state.searchTask.length !== 0) + return state.searchTask.slice((state.page-1)*state.length, state.page*state.length) + if(state.totalVideoTask.length !== 0) + return state.totalVideoTask.slice((state.page-1)*state.length, state.page*state.length) + return null + }, + min(){ + return 1 + }, + max(state){ + let max = 0 + let tasks + if(state.searchTask.length !== 0){ + tasks = state.searchTask + } + else if(state.showHistory === "gallery") + if(state.totalGalleryTask.length !== 0) + tasks = state.totalGalleryTask + else if(state.showHistory === "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){ + max += 1 + } + return max + }, + isAuth(state){ + return state.isAuth + }, + page(state){ + return state.page + }, + loadComplete(state){ + return state.loadComplete + }, + preDownloadGallery(state){ + return state.preDownloadGallery + }, + preDownloadVideo(state){ + return state.preDownloadVideo + }, + isShowHistory(state){ + return state.isShowHistory + }, + showType(state){ + return state.showType + } +} + +export default new vuex.Store({ + actions, + mutations, + state, + getters +}) +