This commit is contained in:
2025-09-30 09:42:43 +08:00
parent 9719228d6d
commit c5ac27cdec
15 changed files with 222 additions and 139 deletions

View File

@@ -106,11 +106,13 @@ type Stage = 'check' | 'downloading' | 'completed'
const stage = ref<Stage>('check')
const appName = ref('我了个电商')
const version = ref('2.0.0')
const prog = ref({ percentage: 0, current: '0 MB', total: '0 MB', speed: '' as string | undefined })
const prog = ref({ percentage: 0, current: '0 MB', total: '0 MB', speed: '' })
const info = ref({
latestVersion: '2.4.8',
downloadUrl: '',
updateNotes: '• 优化了用户界面体验\n• 修复了已知问题\n• 提升了系统稳定性\n• 增加了新的功能模块\n• 优化了数据处理性能'
updateNotes: '• 优化了用户界面体验\n• 修复了已知问题\n• 提升了系统稳定性\n• 增加了新的功能模块\n• 优化了数据处理性能',
currentVersion: '',
hasUpdate: false
})
async function autoCheck() {
@@ -143,26 +145,24 @@ async function autoCheck() {
async function start() {
if (!info.value.downloadUrl) {
ElMessage({ message: '下载链接不可用', type: 'error' })
return
ElMessage({ message: '下载链接不可用', type: 'error' });
return;
}
stage.value = 'downloading'
prog.value = { percentage: 0, current: '0 MB', total: '0 MB', speed: '' }
stage.value = 'downloading';
prog.value = { percentage: 0, current: '0 MB', total: '0 MB', speed: '' };
window.electronAPI.onDownloadProgress((progress) => {
(window as any).electronAPI.onDownloadProgress((progress: any) => {
prog.value = {
percentage: progress.percentage || 0,
current: progress.current || '0 MB',
total: progress.total || '0 MB',
speed: progress.speed || ''
}
})
};
});
try {
const response = await window.electronAPI.downloadUpdate(info.value.downloadUrl)
const response = await (window as any).electronAPI.downloadUpdate(info.value.downloadUrl)
if (response.success) {
stage.value = 'completed'
@@ -181,10 +181,8 @@ async function start() {
async function cancelDownload() {
try {
if (window.electronAPI) {
window.electronAPI.removeDownloadProgressListener()
await window.electronAPI.cancelDownload()
}
(window as any).electronAPI.removeDownloadProgressListener()
await (window as any).electronAPI.cancelDownload()
show.value = false
stage.value = 'check'
} catch (error) {
@@ -205,7 +203,7 @@ async function installUpdate() {
type: 'warning'
}
)
const response = await window.electronAPI.installUpdate()
const response = await (window as any).electronAPI.installUpdate()
if (response.success) {
ElMessage({ message: '应用即将重启', type: 'success' })
@@ -231,9 +229,7 @@ onMounted(async () => {
})
onUnmounted(() => {
if (window.electronAPI) {
window.electronAPI.removeDownloadProgressListener()
}
(window as any).electronAPI.removeDownloadProgressListener()
})
</script>