<template>
|
<div class="updateDownloadInfo" v-if="showUpdateInfo">
|
<el-alert
|
:title="`检测到新版本,正在下载安装包${
|
updateDownloadInfo?.percent ? ',进度:' + updateDownloadInfo?.percent + '%' : '...'
|
}`"
|
type="info"
|
effect="dark"
|
/>
|
</div>
|
<RouterView />
|
</template>
|
|
<script setup lang="ts">
|
import { ref, reactive, inject } from 'vue'
|
import { RouterView, useRouter } from 'vue-router'
|
import { useDownloadTask, useExportTask } from '@/store'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
const router = useRouter()
|
|
const request = inject('request')
|
|
const downloadTask = useDownloadTask()
|
const ExportTask = useExportTask()
|
|
if (window.electronAPI) {
|
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) {
|
router.replace({
|
path: '/transmission'
|
})
|
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) {
|
router.replace({
|
path: '/home'
|
})
|
// request({
|
// url: '/identity/User/GetCurrentUser',
|
// method: 'post'
|
// }).then((res) => {
|
// // console.log(res)
|
// })
|
} else {
|
router.replace({
|
path: '/login'
|
})
|
}
|
</script>
|
|
<style>
|
.updateDownloadInfo {
|
position: fixed;
|
top: 2px;
|
left: 82px;
|
right: 2px;
|
z-index: 999;
|
}
|
</style>
|