优化效果

This commit is contained in:
weipengfei 2023-09-04 18:28:02 +08:00
parent af0d12bcbd
commit 2cc38a10c4

View File

@ -3,6 +3,7 @@ const mp = uni.requireNativePlugin('uniMP');
let appid = ''; // 应用id
let wgtFile = ''; // 应用文件地址
let timer = null; // 加载计时器
// 比较版本号大小
function compareVersions(version1, version2) {
@ -28,11 +29,23 @@ const loadMP = async (id) => {
console.log(mp, uni);
// return ;
uni.showLoading({
title: '下载中...'
title: '下载中...',
mask: true
})
mp.getUniMPVersion(id, (ret) => {
console.log('当前版本', ret);
if (0 != ret.code || compareVersions(info.data.version, ret.versionInfo.name) == 1 || true) {
let count = 0;
timer = setInterval(() => {
if (count < 100) uni.showLoading({
title: `下载中... ${count}%`,
mask: true
})
else uni.showLoading({
title: '安装中...',
mask: true
})
}, 600)
let downloadTask = uni.downloadFile({
url: info.data.version_info?.dow_url,
success(res) {
@ -41,23 +54,12 @@ const loadMP = async (id) => {
installMP();
}
});
let count = 0;
let timer = null;
timer = setInterval(()=>{
uni.showLoading({
title: `下载中... ${count}%`,
mask: true
})
}, 600)
downloadTask.onProgressUpdate((res) => {
console.log('下载进度' + res.progress);
if (res.progress > count + 10) count += 10;
if (res.progress > count) count += 10;
if (count >= 90) {
clearInterval(timer);
timer = null;
uni.showLoading({
title: '安装中...'
})
}
// 满足测试条件,取消下载任务。
// if (res.progress > 50) {
@ -102,7 +104,6 @@ const doInstallMP = () => {
appid: appid,
wgtFile: wgtFile
}, (r) => {
uni.hideLoading();
if (0 == r.code) {
// uni.showToast({
// title: '安装成功'
@ -110,6 +111,7 @@ const doInstallMP = () => {
console.log('小程序安装成功');
open();
} else {
uni.hideLoading();
uni.showModal({
title: '安装失败',
content: JSON.stringify(r),
@ -133,6 +135,7 @@ const open = (id = null) => {
token: token,
}
}, (ret) => {
uni.hideLoading();
if (0 != ret.code) {
uni.showModal({
title: '启动失败',