diff --git a/src/components/DashBoard.vue b/src/components/DashBoard.vue index 86624f1..d5dffdf 100644 --- a/src/components/DashBoard.vue +++ b/src/components/DashBoard.vue @@ -45,7 +45,7 @@ + :src="chosenGallery.thumb_link !== undefined ? 'https://downloader.lionwebsite.xyz/GalleryManage/ehThumbnail?path=' + chosenGallery.thumb_link: ''"/> 本子名字:{{chosenGallery.name}}本子页数:{{chosenGallery.pages}} @@ -62,10 +62,9 @@
@@ -111,7 +110,6 @@ 在线预览
在线预览分页页数: - (建议为3的倍数,因为固定了一行三张) -
- +
{{lengthPerPage * index + i + 1}}
- -
diff --git a/src/components/Side.vue b/src/components/Side.vue index afe2ccb..c3a61eb 100644 --- a/src/components/Side.vue +++ b/src/components/Side.vue @@ -35,9 +35,9 @@ @@ -102,8 +102,6 @@ import axios from "axios"; import {ElMessage} from "element-plus"; import OnlineReader from "./OnlineReader.vue"; -let GalleryManagePrefix = "https://downloader.lionwebsite.xyz/GalleryManage/" - //输入 let inputNode = ref(null) //是否正在编辑页数 diff --git a/src/store/index.js b/src/store/index.js index bd1baa6..dd57281 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -6,32 +6,15 @@ const BaseUrl = "https://downloader.lionwebsite.xyz/" const GalleryManageUrl = BaseUrl + "GalleryManage" const actions = { - updateGalleryTasks(context, type){ + updateGalleryTasks(context){ axios.get(GalleryManageUrl, { params:{ - type, - AuthCode: state.AuthCode + AuthCode: state.AuthCode, + type: 'all' } }).then((res) => { - if(res.data.result === "success") { - let tasks = JSON.parse(res.data.data) - if (type === "all" && state.galleryRefreshTimer === 0) { //判断是否有未下载完成的本子以及定时更新是否开启 - for (let i = tasks.length - 1; i > tasks.length - 11; i--) //从后往前遍历十个本子,查看是否有未下载完成的本子 - if (tasks[i].status !== "下载完成") { - state.galleryRefreshTimer = setInterval(() => { - context.dispatch("updateGalleryTasks", "undone").then() - }, 20000) - break - } - } - context.commit("_updateGalleryTasks", {tasks, type}) - } - - else if(type === 'undone') { - context.dispatch("updateGalleryTasks", "all").then() - clearInterval(state.galleryRefreshTimer) - state.galleryRefreshTimer = 0 - } + if(res.data.result === "success") + context.commit("_updateGalleryTasks", JSON.parse(res.data.data)) }) }, postGalleryTask(context, data){ @@ -43,17 +26,12 @@ const actions = { ElMessage("提交成功") context.commit("_setChosenGallery", {gallery: false, resolution:data.targetResolution}) - if(state.galleryRefreshTimer === 0) - state.galleryRefreshTimer = setInterval(() => { - context.dispatch("updateGalleryTasks", "undone").then() - }, 20000) } - else{ + else if(res.data.data) ElMessage(res.data.data) else ElMessage("提交失败") - } }) }, queryGalleryTask(context, link){ @@ -79,16 +57,31 @@ const actions = { context.commit("_authed", {AuthCode, ...data}) //初始化 context.dispatch("loadWeekUsedAmount").then() - context.dispatch("updateGalleryTasks", "all").then(() => confirmCurrentTask(context.state)) - - //写死图片合适宽度 - state.imageWidth = 27 + 'vw' - state.imagePadding = 1 + 'vw' + context.dispatch("updateGalleryTasks").then(() => confirmCurrentTask(context.state)) + context.dispatch("initWebsocket").then() } else context.commit("_unAuthed") }) }, + initWebsocket(context){ + state.websocket = new WebSocket("wss://downloader.lionwebsite.xyz/ws/") + state.websocket.onopen = () => { + state.websocket.send("DownloaderWebsocket") + } + + state.websocket.onmessage = (event) => { + let message = JSON.parse(event.data) + + switch (message.type){ + case "updateTasks": + context.commit("_updateGalleryTaskProceeding", message.data) + break + case "fullUpdate": + context.dispatch("updateGalleryTasks").then() + } + } + }, loadWeekUsedAmount(context){ axios.get(GalleryManageUrl + "/weekUsedAmount", { params: { @@ -184,95 +177,71 @@ const mutations = { state.collectGallery[index].isCollect = false state.collectGallery.splice(index, 1) }, - _updateGalleryTasks(state, data){ - let {tasks, type} = data - if(type === 'all') { - state.totalGalleryTask.splice(0) - state.collectGallery.slice(0) - state.downloadGallery.splice(0) + _updateGalleryTasks(state, tasks){ + state.totalGalleryTask.splice(0) + state.collectGallery.slice(0) + state.downloadGallery.splice(0) - tasks.forEach((task) => { - //处理名字 - task.shortName = getShortname(task.name) - task.thumb_link = GalleryManageUrl + "/ehThumbnail?path=" + task.thumb_link + tasks.forEach((task) => { + //处理名字 + task.shortName = getShortname(task.name) + task.thumb_link = GalleryManageUrl + "/ehThumbnail?path=" + task.thumb_link - //处理进度相关 - switch (task.status) { - case "已提交": - task.progress = "已提交" - break; - case "下载中": - task.progress = (Math.round((task.proceeding / task.pages) * 100)).toString() + "%" - break; - case "下载完成": - task.progress = "下载完成" - task.download = GalleryManageUrl + "/file/" + encodeURI(task.name) + ".zip?AuthCode=" + state.AuthCode + "&gid=" + task.gid - break; - case "压缩中": - task.progress = "压缩中" - break - } + //处理进度相关 + switch (task.status) { + case "已提交": + case "压缩中": + task.progress = task.status + break; + case "下载中": + task.progress = (Math.round((task.proceeding / task.pages) * 100)).toString() + "%" + break; + case "下载完成": + task.progress = task.status + task.download = GalleryManageUrl + "/file/" + encodeURI(task.name) + ".zip?AuthCode=" + state.AuthCode + "&gid=" + task.gid + break; + } - //处理时间戳 - task.createTimeDisplay = new Date(task.createTime * 1000).toLocaleString("zh") + //处理时间戳 + task.createTimeDisplay = new Date(task.createTime * 1000).toLocaleString("zh") - //处理是否收藏 - if('isCollect' in task) - state.collectGallery.push(task) - else - task.isCollect = false + //处理是否收藏 + if('isCollect' in task) + state.collectGallery.push(task) + else + task.isCollect = false - //处理是否下载 - if(task.downloader === state.userId) - state.downloadGallery.push(task) + //处理是否下载 + if(task.downloader === state.userId) + state.downloadGallery.push(task) - state.totalGalleryTask.push(task) - }) - } else { - let tempArray = Array.from(state.totalGalleryTask) - state.totalGalleryTask.splice(0) - let preDeleteIndex - tempArray.forEach((task) => { - preDeleteIndex = -1 - if(task.status !== "下载完成") - for(let i=0; i < tasks.length; i++) - if (tasks[i] !== undefined && tasks[i].name === task.name) { - preDeleteIndex = i - task.status = tasks[i].status - task.proceeding = tasks[i].proceeding - if (task.proceeding === 0) - task.progress = task.status - else - task.progress = (Math.round((task.proceeding / task.pages) * 100)).toString() + "%" - } + state.totalGalleryTask.push(task) + }) - if(preDeleteIndex !== -1) - delete tasks[preDeleteIndex] - state.totalGalleryTask.push(task) - }) - } - - switch (state.sortType) { - case "name": - state.totalGalleryTask = state.totalGalleryTask.sort((before, after) => { - return before.name > after.name ? 1: -1 - }) - break - case "shortName": - state.totalGalleryTask = state.totalGalleryTask.sort((before, after) => { - return before.shortName > after.shortName ? 1: -1 - }) - break - case "createTime": - state.totalGalleryTask = state.totalGalleryTask.sort((before, after) => { - return before.createTime - after.createTime - }) - } + sortTasks(state) if(state.isAuth && !state.loadComplete){ state.loadComplete = true ElMessage("加载完成") } }, + _updateGalleryTaskProceeding(state, tasks){ + let galleries = Array.from(state.totalGalleryTask) + state.totalGalleryTask.splice(0) + galleries.forEach((gallery) => { + if(gallery.status !== '下载完成') + tasks.forEach((task) => { + if(task.gid === gallery.gid){ + gallery.status = status[task.status] + gallery.proceeding = task.proceeding + if(gallery.status === '下载中') + gallery.progress = (Math.round((gallery.proceeding / gallery.pages) * 100)).toString() + "%" + else + gallery.progress = gallery.status + } + }) + state.totalGalleryTask.push(gallery) + }) + }, _changePage(state, targetPage){ state.page = targetPage }, @@ -352,6 +321,7 @@ const mutations = { state.chosenGallery.createTimeDisplay = "等待下载完成后再查看" state.chosenGallery.progress = "已提交" state.chosenGallery.downloader = state.userId + state.chosenGallery.thumb_link = GalleryManageUrl + "/ehThumbnail?path=" + state.chosenGallery.thumb_link state.totalGalleryTask.push(state.chosenGallery) state.downloadGallery.push(state.chosenGallery) } @@ -390,6 +360,8 @@ const mutations = { } const state = { + websocket: {}, //websocket + totalGalleryTask: [], //存放本子数据的数组 chosenGallery: false, //准备下载的本子 thumbnailGallery: {}, //缩略图本子 @@ -401,8 +373,6 @@ const state = { isReading: false, //是否正在看 currentGid: "", //当前GID - imageWidth: "", //图片宽度 - imagePadding: "", //图片padding lengthPerPage: 0, //在线预览每页图片数量 page: 1, //当前页数 @@ -526,7 +496,7 @@ function sortTasks(state){ }) break case "createTime": - state.currentTasks = state.currentTasks.sort((before, after) => { + state.currentTasks = state.currentTasks.sort((before, after) => { return before.createTime - after.createTime }) } @@ -539,4 +509,6 @@ function deleteTask(tasks, key, value){ tasks[j].splice(i, 1) break } -} \ No newline at end of file +} + +let status = ['已提交', '下载中', '等待压缩', '压缩中', '下载完成'] \ No newline at end of file