diff --git a/utils/update.js b/utils/update.js index b49af82..5f81c6d 100644 --- a/utils/update.js +++ b/utils/update.js @@ -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