| | |
| | | const downloadTask = useDownloadTask() |
| | | const ExportTask = useExportTask() |
| | | |
| | | window.electronAPI.onLogout((data) => { |
| | | localStorage.clear() |
| | | router.replace({ |
| | | path: '/login' |
| | | }) |
| | | }) |
| | | |
| | | window.electronAPI.onOpenUrl((data) => { |
| | | let taskInfo = null |
| | | let downloadInfo = decodeURI(data) |
| | | console.log(downloadInfo, '接受到的taskInfo') |
| | | try { |
| | | taskInfo = JSON.parse(downloadInfo) |
| | | } catch (error) { |
| | | taskInfo = null |
| | | } |
| | | if (taskInfo) { |
| | | if (window.electronAPI) { |
| | | window.electronAPI.onLogout((data) => { |
| | | localStorage.clear() |
| | | router.replace({ |
| | | path: '/transmission' |
| | | path: '/login' |
| | | }) |
| | | window.electronAPI.newDownloadTask(taskInfo) |
| | | } |
| | | }) |
| | | |
| | | // 绑定消息提醒 |
| | | window.electronAPI.onShowMessage((data) => { |
| | | // 获取到消息后修改全局数据,页面监听全局数据进行变化 |
| | | if (data.showType) { |
| | | switch (data.showType) { |
| | | case 'DownloadTask': |
| | | downloadTask.setMsgData(data) |
| | | break |
| | | case 'ExportTask': |
| | | ExportTask.setMsgData(data) |
| | | break |
| | | } |
| | | } else { |
| | | downloadTask.setMsgData(data) |
| | | } |
| | | }) |
| | | |
| | | // 绑定下载任务变化更新 |
| | | window.electronAPI.onDownloadTaskChange((task) => { |
| | | downloadTask.setUpdateList() |
| | | }) |
| | | |
| | | // 绑定导出任务变化更新 |
| | | window.electronAPI.onExportTaskChange((task) => { |
| | | ExportTask.setUpdateList() |
| | | }) |
| | | |
| | | const showUpdateInfo = ref(false) |
| | | const updateDownloadInfo = ref() |
| | | |
| | | // 监听程序更新下载 |
| | | window.electronAPI.onUpdateDownloadProgress((data) => { |
| | | showUpdateInfo.value = true |
| | | console.log(data, 'updateDownloadInfo') |
| | | updateDownloadInfo.value = data |
| | | }) |
| | | |
| | | // 监听程序更新下载完成 |
| | | window.electronAPI.onUpdateDownloadSuccess((data) => { |
| | | showUpdateInfo.value = false |
| | | ElMessageBox.confirm('检测到新版本,安装包已下载完成,是否立即更新?', '检查更新', { |
| | | confirmButtonText: '更新', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }) |
| | | .then(() => { |
| | | window.electronAPI.updateApp() |
| | | }) |
| | | .catch(() => {}) |
| | | }) |
| | | |
| | | const token = localStorage.getItem('token') |
| | | if (token) { |
| | | request({ |
| | | url: '/identity/User/GetCurrentUser', |
| | | method: 'post' |
| | | }).then((res) => { |
| | | // console.log(res) |
| | | window.electronAPI.onOpenUrl((data) => { |
| | | let taskInfo = null |
| | | let downloadInfo = decodeURI(data) |
| | | console.log(downloadInfo, '接受到的taskInfo') |
| | | try { |
| | | taskInfo = JSON.parse(downloadInfo) |
| | | } catch (error) { |
| | | taskInfo = null |
| | | } |
| | | if (taskInfo) { |
| | | router.replace({ |
| | | path: '/home' |
| | | }) |
| | | window.electronAPI.newDownloadTask(taskInfo) |
| | | } |
| | | }) |
| | | |
| | | // 绑定消息提醒 |
| | | window.electronAPI.onShowMessage((data) => { |
| | | // 获取到消息后修改全局数据,页面监听全局数据进行变化 |
| | | if (data.showType) { |
| | | switch (data.showType) { |
| | | case 'DownloadTask': |
| | | downloadTask.setMsgData(data) |
| | | break |
| | | case 'ExportTask': |
| | | ExportTask.setMsgData(data) |
| | | break |
| | | } |
| | | } else { |
| | | downloadTask.setMsgData(data) |
| | | } |
| | | }) |
| | | |
| | | // 绑定下载任务变化更新 |
| | | window.electronAPI.onDownloadTaskChange((task) => { |
| | | downloadTask.setUpdateList() |
| | | }) |
| | | |
| | | // 绑定导出任务变化更新 |
| | | window.electronAPI.onExportTaskChange((task) => { |
| | | ExportTask.setUpdateList() |
| | | }) |
| | | |
| | | const showUpdateInfo = ref(false) |
| | | const updateDownloadInfo = ref() |
| | | |
| | | // 监听程序更新下载 |
| | | window.electronAPI.onUpdateDownloadProgress((data) => { |
| | | showUpdateInfo.value = true |
| | | console.log(data, 'updateDownloadInfo') |
| | | updateDownloadInfo.value = data |
| | | }) |
| | | |
| | | // 监听程序更新下载完成 |
| | | window.electronAPI.onUpdateDownloadSuccess((data) => { |
| | | showUpdateInfo.value = false |
| | | ElMessageBox.confirm('检测到新版本,安装包已下载完成,是否立即更新?', '检查更新', { |
| | | confirmButtonText: '更新', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }) |
| | | .then(() => { |
| | | window.electronAPI.updateApp() |
| | | }) |
| | | .catch(() => {}) |
| | | }) |
| | | } |
| | | const getUrlParam = (paraName) => { |
| | | var url = window.location.toString() |
| | | var arrObj = url.split('?') |
| | | if (arrObj.length > 1) { |
| | | var arrPara = arrObj[1].split('&') |
| | | var arr |
| | | for (var i = 0; i < arrPara.length; i++) { |
| | | arr = arrPara[i].split('=') |
| | | if (arr != null && arr[0] == paraName) { |
| | | return arr[1] |
| | | } |
| | | } |
| | | return '' |
| | | } else { |
| | | return '' |
| | | } |
| | | } |
| | | |
| | | let tokens = getUrlParam('token') |
| | | let bookId = getUrlParam('bookId') |
| | | let tryPageCount = getUrlParam('tryPageCount') |
| | | localStorage.setItem('bookId', bookId) |
| | | localStorage.setItem('tryPageCount', tryPageCount) |
| | | const token = localStorage.getItem('token') || tokens |
| | | localStorage.setItem('token', token) |
| | | if (tokens && bookId) { |
| | | router.replace({ |
| | | path: '/home', |
| | | query: { bookId: bookId } |
| | | }) |
| | | } else { |
| | | router.replace({ |