修复下载问显示问题

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