mirror of
https://gitee.com/HuLaSpark/HuLa.git
synced 2024-12-01 19:28:07 +08:00
fix(layout): 🐛 修复更新进度条显示异常bug
This commit is contained in:
parent
3158c85630
commit
45e2bfce66
@ -128,6 +128,8 @@ export const CheckUpdate = defineComponent(() => {
|
|||||||
const versionTime = ref('')
|
const versionTime = ref('')
|
||||||
const newVersionTime = ref('')
|
const newVersionTime = ref('')
|
||||||
const percentage = ref(0)
|
const percentage = ref(0)
|
||||||
|
const total = ref(0)
|
||||||
|
const downloaded = ref(0)
|
||||||
|
|
||||||
// const commitTypeMap: { [key: string]: string } = {
|
// const commitTypeMap: { [key: string]: string } = {
|
||||||
// feat: 'feat',
|
// feat: 'feat',
|
||||||
@ -203,40 +205,37 @@ export const CheckUpdate = defineComponent(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleUpdate = async () => {
|
const handleUpdate = async () => {
|
||||||
updating.value = true
|
|
||||||
if (!(await window.confirm('确定更新吗'))) {
|
if (!(await window.confirm('确定更新吗'))) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
updating.value = true
|
||||||
checkLoading.value = true
|
checkLoading.value = true
|
||||||
await check()
|
await check()
|
||||||
.then(async (e) => {
|
.then(async (e) => {
|
||||||
if (!e?.available) {
|
if (!e?.available) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let contentLength = 0
|
|
||||||
let downloaded = 0
|
|
||||||
|
|
||||||
await e.downloadAndInstall((event) => {
|
await e.downloadAndInstall((event) => {
|
||||||
switch (event.event) {
|
switch (event.event) {
|
||||||
case 'Started':
|
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`)
|
console.log(`started downloading ${event.data.contentLength} bytes`)
|
||||||
break
|
break
|
||||||
case 'Progress':
|
case 'Progress':
|
||||||
downloaded += event.data.chunkLength
|
downloaded.value += event.data.chunkLength
|
||||||
//console.log(`downloaded ${downloaded} from ${contentLength}`);
|
percentage.value = parseFloat(((downloaded.value / total.value) * 100 + '').substring(0, 4))
|
||||||
percentage.value = contentLength / downloaded
|
|
||||||
break
|
break
|
||||||
case 'Finished':
|
case 'Finished':
|
||||||
console.log('download finished')
|
console.log('download finished')
|
||||||
|
window.$message.success('安装包下载成功,3s后重启并安装')
|
||||||
|
setTimeout(() => {
|
||||||
|
updating.value = false
|
||||||
|
relaunch()
|
||||||
|
}, 3000)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
window.$message.success('安装包下载成功,3s后重启并安装')
|
|
||||||
setTimeout(() => {
|
|
||||||
updating.value = false
|
|
||||||
relaunch()
|
|
||||||
}, 3000)
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
window.$message.error('检查更新错误,请稍后再试')
|
window.$message.error('检查更新错误,请稍后再试')
|
||||||
@ -388,6 +387,7 @@ export const CheckUpdate = defineComponent(() => {
|
|||||||
{text.value === '立即更新' ? (
|
{text.value === '立即更新' ? (
|
||||||
<NButton loading={checkLoading.value} onClick={handleUpdate} secondary type="primary">
|
<NButton loading={checkLoading.value} onClick={handleUpdate} secondary type="primary">
|
||||||
{text.value}
|
{text.value}
|
||||||
|
{total.value > 0 && parseFloat(total.value / 1024 / 1024 + '').toFixed(2) + 'M'}
|
||||||
</NButton>
|
</NButton>
|
||||||
) : (
|
) : (
|
||||||
<NButton loading={checkLoading.value} onClick={checkUpdate} secondary type="tertiary">
|
<NButton loading={checkLoading.value} onClick={checkUpdate} secondary type="tertiary">
|
||||||
|
Loading…
Reference in New Issue
Block a user