123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- module.exports = {
- updateManager,
- }
- function updateManager() {
-
- // #ifdef APP-PLUS
- const updated = uni.getStorageSync('updated'); // 尝试读取storage
- // 如果上次刚更新过----删除 updated成功标志
- // console.log(updated)
- if (updated.completed === true) {
- // 删除安装包及安装记录
-
- console.log('安装记录被删除,更新成功');
- uni.removeSavedFile({
- filePath: updated.packgePath,
- success: res => {
- uni.removeStorageSync('updated');
- }
- });
- } else if (updated.completed === false) {
-
- uni.removeStorageSync('updated');
- plus.runtime.install(updated.packgePath, {
- force: true
- });
- uni.setStorage({
- key: 'updated',
- data: {
- completed: true,
- packgePath: updated.packgePath
- },
- success: res => {
- console.log('成功安装上次的更新,应用需要重启才能继续完成');
- }
- });
- uni.showModal({
- title: '提示',
- content: '应用将重启以完成更新',
- showCancel: false,
- complete: () => {
- plus.runtime.restart();
- }
- });
- }
- // #endif
-
- //checkUpdater();
- };
- import CONFIG from "./../config/global.config"
- export function checkUpdater(currentId, updaterPage) {
-
-
-
- let version=null
- plus.runtime.getProperty(plus.runtime.appid, (wgtinfo)=>{
- version=wgtinfo.versionCode;
- console.log("当前版本"+version)
-
- uni.request({
- url: CONFIG.baseUrl+ "/app/config/info",
- method: 'get',
-
- success:(res)=>{
-
- if (res.data.code != 200 ) {
- uni.showModal({
- title: '提示',
- content: res.data.msg
- })
- return;
- }
-
-
- let upgradeInfo = res.data.data;
-
- console.log("res"+JSON.stringify(upgradeInfo))
-
- if (Number(version) <Number( upgradeInfo.number)) {
-
- uni.showModal({
- title: '发现新版本',
- content: '有新版本可用 (版本号:' + upgradeInfo.ver + '),请问您是否更新?',
- showCancel:false,
- success: (res) => {
- if (res.confirm) {
- console.log(plus.os.name.toLowerCase())
- if (plus.os.name.toLowerCase() === 'ios') {
- let appleId=1538532925; //app的appleId id1538532925
- plus.runtime.launchApplication({
- action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
- }, function(e) {
- console.log('Open system default browser failed: ' + e.message);
- });
- } else {
- if(upgradeInfo.status){
- uni.redirectTo({
- url: '/pages/index/update',
- success(res) {
- console.log(res);
- },
- fail(err) {
- console.log(err);
- }
- })
- }else{
- uni.navigateTo({
- url: '/pages/index/update',
- success(res) {
- console.log(res);
- },
- fail(err) {
- console.log(err);
- }
- })
- }
-
- }
-
- // downLoad();
- } else if (res.cancel) {
- console.log('取消')
- }
- },
-
- })
- }
- }
-
- });
- })
-
-
-
-
- }
|