修复下载问显示问题

This commit is contained in:
WindowBird 2025-11-22 11:16:28 +08:00
parent df607ffb91
commit 2aad4a89fa

View File

@ -185,15 +185,26 @@ export const downloadAndInstall = (downloadUrl, versionName = '') => {
// 显示下载进度
let downloadTask = null
let progressModal = null
uni.showLoading({
title: '下载中',
mask: true
})
// 创建下载任务
downloadTask = uni.downloadFile({
url: downloadUrl,
//
// if (progress === 100) {
// uni.hideLoading()
// }
success: (res) => {
if (res.statusCode === 200) {
// 下载成功,安装 APK
uni.hideLoading()
installApk(res.tempFilePath)
} else {
uni.hideLoading()
uni.showToast({
title: '下载失败',
icon: 'none'
@ -201,6 +212,7 @@ export const downloadAndInstall = (downloadUrl, versionName = '') => {
}
},
fail: (err) => {
uni.hideLoading()
console.error('下载失败:', err)
uni.showToast({
title: '下载失败:' + (err.errMsg || '未知错误'),
@ -210,22 +222,22 @@ export const downloadAndInstall = (downloadUrl, versionName = '') => {
}
})
// 监听下载进度
downloadTask.onProgressUpdate((res) => {
const progress = res.progress
const received = (res.totalBytesWritten / 1024 / 1024).toFixed(2)
const total = (res.totalBytesExpectedToWrite / 1024 / 1024).toFixed(2)
// 显示下载进度(使用 uni.showLoading
uni.showLoading({
title: `下载中 ${progress}%`,
mask: true
})
if (progress === 100) {
uni.hideLoading()
}
})
// // 监听下载进度
// downloadTask.onProgressUpdate((res) => {
// const progress = res.progress
// const received = (res.totalBytesWritten / 1024 / 1024).toFixed(2)
// const total = (res.totalBytesExpectedToWrite / 1024 / 1024).toFixed(2)
//
// // 显示下载进度(使用 uni.showLoading
// uni.showLoading({
// title: '下载中',
// mask: true
// })
//
// if (progress === 100) {
// uni.hideLoading()
// }
// })
// #endif
// #ifndef APP-PLUS