litian
2024-05-15 7b8f96254b90c8d9cb01092e8d6ab7263972fee1
src/App.vue
@@ -23,89 +23,94 @@
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()
  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'
    })
    .catch(() => {})
})
      .then(() => {
        window.electronAPI.updateApp()
      })
      .catch(() => {})
  })
}
const token = localStorage.getItem('token')
if (token) {
  request({
    url: '/identity/User/GetCurrentUser',
    method: 'post'
  }).then((res) => {
    // console.log(res)
  router.replace({
    path: '/home'
  })
  // request({
  //   url: '/identity/User/GetCurrentUser',
  //   method: 'post'
  // }).then((res) => {
  //   // console.log(res)
  // })
} else {
  router.replace({
    path: '/login'