From 45e2bfce669c76cbb72be641febf59509b3e6204 Mon Sep 17 00:00:00 2001
From: ZOL4789 <44133469+ZOL4789@users.noreply.github.com>
Date: Sun, 27 Oct 2024 21:19:28 +0800
Subject: [PATCH] =?UTF-8?q?fix(layout):=20:bug:=20=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BF=9B=E5=BA=A6=E6=9D=A1=E6=98=BE=E7=A4=BA?=
=?UTF-8?q?=E5=BC=82=E5=B8=B8bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/layout/left/model.tsx | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/layout/left/model.tsx b/src/layout/left/model.tsx
index 73c4b8f..71dfaaa 100644
--- a/src/layout/left/model.tsx
+++ b/src/layout/left/model.tsx
@@ -128,6 +128,8 @@ export const CheckUpdate = defineComponent(() => {
const versionTime = ref('')
const newVersionTime = ref('')
const percentage = ref(0)
+ const total = ref(0)
+ const downloaded = ref(0)
// const commitTypeMap: { [key: string]: string } = {
// feat: 'feat',
@@ -203,40 +205,37 @@ export const CheckUpdate = defineComponent(() => {
}
const handleUpdate = async () => {
- updating.value = true
if (!(await window.confirm('确定更新吗'))) {
return
}
+ updating.value = true
checkLoading.value = true
await check()
.then(async (e) => {
if (!e?.available) {
return
}
- let contentLength = 0
- let downloaded = 0
await e.downloadAndInstall((event) => {
switch (event.event) {
case 'Started':
- contentLength = event.data.contentLength ? event.data.contentLength : 0
+ total.value = event.data.contentLength ? event.data.contentLength : 0
console.log(`started downloading ${event.data.contentLength} bytes`)
break
case 'Progress':
- downloaded += event.data.chunkLength
- //console.log(`downloaded ${downloaded} from ${contentLength}`);
- percentage.value = contentLength / downloaded
+ downloaded.value += event.data.chunkLength
+ percentage.value = parseFloat(((downloaded.value / total.value) * 100 + '').substring(0, 4))
break
case 'Finished':
console.log('download finished')
+ window.$message.success('安装包下载成功,3s后重启并安装')
+ setTimeout(() => {
+ updating.value = false
+ relaunch()
+ }, 3000)
break
}
})
- window.$message.success('安装包下载成功,3s后重启并安装')
- setTimeout(() => {
- updating.value = false
- relaunch()
- }, 3000)
})
.catch(() => {
window.$message.error('检查更新错误,请稍后再试')
@@ -388,6 +387,7 @@ export const CheckUpdate = defineComponent(() => {
{text.value === '立即更新' ? (
{text.value}
+ {total.value > 0 && parseFloat(total.value / 1024 / 1024 + '').toFixed(2) + 'M'}
) : (