diff --git a/pages/gather/gather.vue b/pages/gather/gather.vue index ddce5f4..854967f 100644 --- a/pages/gather/gather.vue +++ b/pages/gather/gather.vue @@ -15,43 +15,45 @@ - - - - 更多功能 - {{editFlag?'完成':'编辑'}} + + + + 更多功能 + {{editFlag?'完成':'编辑'}} + + + + + + + + + {{item.name}} + + + + 还没有应用,点我添加应用 + - - - - - - - - {{item.name}} + + + 编辑功能 + 完成 + + + + + + + + {{item.name}} - - 还没有应用,点我添加应用 + - - - - 编辑功能 - 完成 - - - - - - - - {{item.name}} - - - - + diff --git a/utils/uniMP.js b/utils/uniMP.js index 3b09d3e..85accba 100644 --- a/utils/uniMP.js +++ b/utils/uniMP.js @@ -1,8 +1,8 @@ import { getGXconfig } from "@/api/uniMP.js"; const mp = uni.requireNativePlugin('uniMP'); -let appid = ''; // 应用id -let wgtFile = ''; // 应用文件地址 +let appid = ''; // 应用id +let wgtFile = ''; // 应用文件地址 // 比较版本号大小 function compareVersions(version1, version2) { @@ -23,25 +23,47 @@ function compareVersions(version1, version2) { // 加载小程序 const loadMP = async (id) => { appid = id; - uni.showLoading({ - title: '加载中', - mask: true - }) let info = await getGXconfig(); console.log('最新版本', info.data); console.log(mp, uni); // return ; + uni.showLoading({ + title: '下载中...' + }) mp.getUniMPVersion(id, (ret) => { console.log('当前版本', ret); - if (0!=ret.code||compareVersions(info.data.version, ret.versionInfo.name) == 1||true) { - uni.downloadFile({ + if (0 != ret.code || compareVersions(info.data.version, ret.versionInfo.name) == 1 || true) { + let downloadTask = uni.downloadFile({ url: info.data.version_info?.dow_url, success(res) { wgtFile = res.tempFilePath; console.log('下载完成', wgtFile); 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 (count >= 90) { + clearInterval(timer); + timer = null; + uni.showLoading({ + title: '安装中...' + }) + } + // 满足测试条件,取消下载任务。 + // if (res.progress > 50) { + // downloadTask.abort(); + // } + }); } else { open() } @@ -80,6 +102,7 @@ const doInstallMP = () => { appid: appid, wgtFile: wgtFile }, (r) => { + uni.hideLoading(); if (0 == r.code) { // uni.showToast({ // title: '安装成功' @@ -87,7 +110,6 @@ const doInstallMP = () => { console.log('小程序安装成功'); open(); } else { - uni.hideLoading(); uni.showModal({ title: '安装失败', content: JSON.stringify(r), @@ -99,13 +121,18 @@ const doInstallMP = () => { }; const open = (id = null) => { + let token = uni.getStorageSync('LOGIN_STATUS_TOKEN'); + if (!token) return uni.showToast({ + icon: 'none', + title: '请先登录' + }) mp.openUniMP({ appid: id || appid, extraData: { - uniMP: true + uniMP: true, + token: token, } }, (ret) => { - uni.hideLoading(); if (0 != ret.code) { uni.showModal({ title: '启动失败',