1
This commit is contained in:
@@ -11,10 +11,10 @@ import {deviceApi, type DeviceItem, type DeviceQuota} from './api/device'
|
||||
const LoginDialog = defineAsyncComponent(() => import('./components/auth/LoginDialog.vue'))
|
||||
const RegisterDialog = defineAsyncComponent(() => import('./components/auth/RegisterDialog.vue'))
|
||||
const NavigationBar = defineAsyncComponent(() => import('./components/layout/NavigationBar.vue'))
|
||||
// const UpdateDialog = defineAsyncComponent(() => import('./components/common/UpdateDialog.vue'))
|
||||
const RakutenDashboard = defineAsyncComponent(() => import('./components/rakuten/RakutenDashboard.vue'))
|
||||
const AmazonDashboard = defineAsyncComponent(() => import('./components/amazon/AmazonDashboard.vue'))
|
||||
const ZebraDashboard = defineAsyncComponent(() => import('./components/zebra/ZebraDashboard.vue'))
|
||||
const UpdateDialog = defineAsyncComponent(() => import('./components/common/UpdateDialog.vue'))
|
||||
|
||||
const dashboardsMap: Record<string, Component> = {
|
||||
rakuten: RakutenDashboard,
|
||||
@@ -48,9 +48,8 @@ const devices = ref<DeviceItem[]>([])
|
||||
const deviceQuota = ref<DeviceQuota>({limit: 0, used: 0})
|
||||
const userPermissions = ref<string>('')
|
||||
|
||||
// 更新状态
|
||||
const updateStatus = ref<any>(null)
|
||||
const showUpdateNotification = ref(false)
|
||||
// 更新对话框状态
|
||||
const showUpdateDialog = ref(false)
|
||||
|
||||
// 菜单配置 - 复刻ERP客户端格式
|
||||
const menuConfig = [
|
||||
@@ -417,127 +416,20 @@ async function confirmRemoveDevice(row: DeviceItem & { isCurrent?: boolean }) {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新相关功能
|
||||
function setupUpdateHandler() {
|
||||
if (!(window as any).electronAPI) return
|
||||
|
||||
(window as any).electronAPI.onUpdateStatus((status: any) => {
|
||||
updateStatus.value = status
|
||||
handleUpdateStatus(status)
|
||||
})
|
||||
}
|
||||
|
||||
function handleUpdateStatus(status: any) {
|
||||
switch (status.type) {
|
||||
case 'checking':
|
||||
console.log('正在检查更新...')
|
||||
break
|
||||
case 'available':
|
||||
showUpdateAvailableNotification(status)
|
||||
break
|
||||
case 'not-available':
|
||||
console.log('当前已是最新版本')
|
||||
break
|
||||
case 'error':
|
||||
ElMessage({
|
||||
message: `更新检查失败: ${status.error}`,
|
||||
type: 'error'
|
||||
})
|
||||
break
|
||||
case 'download-progress':
|
||||
// 可以在这里显示下载进度
|
||||
console.log(`下载进度: ${status.progress}%`)
|
||||
break
|
||||
case 'downloaded':
|
||||
showUpdateReadyNotification()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function showUpdateAvailableNotification(status: any) {
|
||||
ElMessage({
|
||||
message: `发现新版本 ${status.version},是否立即下载?`,
|
||||
type: 'info'
|
||||
})
|
||||
// 可以在这里添加确认对话框
|
||||
ElMessageBox.confirm(`新版本 ${status.version} 已发布,是否立即下载?`, '发现新版本', {
|
||||
confirmButtonText: '立即下载',
|
||||
cancelButtonText: '稍后提醒',
|
||||
type: 'info'
|
||||
}).then(() => {
|
||||
downloadUpdate()
|
||||
}).catch(() => {
|
||||
// 用户取消
|
||||
})
|
||||
}
|
||||
|
||||
function showUpdateReadyNotification() {
|
||||
ElMessageBox.confirm('更新已下载完成,是否重启应用以安装更新?', '更新准备就绪', {
|
||||
confirmButtonText: '立即重启',
|
||||
cancelButtonText: '稍后重启',
|
||||
type: 'success'
|
||||
}).then(() => {
|
||||
installUpdate()
|
||||
}).catch(() => {
|
||||
// 用户取消
|
||||
})
|
||||
}
|
||||
|
||||
// 启动时检查更新
|
||||
async function checkForUpdates() {
|
||||
if (!(window as any).electronAPI) return
|
||||
|
||||
try {
|
||||
const result = await (window as any).electronAPI.checkForUpdates()
|
||||
if (!result.success) {
|
||||
console.log('更新检查:', result.message || result.error)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检查更新失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadUpdate() {
|
||||
if (!(window as any).electronAPI) return
|
||||
|
||||
try {
|
||||
ElMessage({
|
||||
message: '开始下载更新...',
|
||||
type: 'info'
|
||||
})
|
||||
const result = await (window as any).electronAPI.downloadUpdate()
|
||||
if (!result.success) {
|
||||
ElMessage({
|
||||
message: `下载失败: ${result.error}`,
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage({
|
||||
message: '下载更新失败',
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function installUpdate() {
|
||||
if (!(window as any).electronAPI) return
|
||||
|
||||
try {
|
||||
(window as any).electronAPI.installUpdate()
|
||||
} catch (error) {
|
||||
ElMessage({
|
||||
message: '安装更新失败',
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
// 延迟3秒后自动检查更新
|
||||
setTimeout(() => {
|
||||
showUpdateDialog.value = true
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
showContent()
|
||||
await checkAuth()
|
||||
|
||||
// 设置更新处理器
|
||||
setupUpdateHandler()
|
||||
// 启动时检查更新
|
||||
await checkForUpdates()
|
||||
|
||||
// 监听页面关闭,断开SSE连接(会自动设置离线)
|
||||
window.addEventListener('beforeunload', () => {
|
||||
@@ -545,11 +437,6 @@ onMounted(async () => {
|
||||
})
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if ((window as any).electronAPI) {
|
||||
(window as any).electronAPI.removeUpdateStatusListener()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -621,6 +508,9 @@ onUnmounted(() => {
|
||||
@register-success="handleRegisterSuccess"
|
||||
@back-to-login="backToLogin"/>
|
||||
|
||||
<!-- 更新对话框 -->
|
||||
<UpdateDialog v-model="showUpdateDialog" />
|
||||
|
||||
<!-- 设备管理弹框 -->
|
||||
<el-dialog
|
||||
v-model="showDeviceDialog"
|
||||
|
||||
Reference in New Issue
Block a user