123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import store from '../store'
- import {getAppVersion} from '@/api/index.js'
- const iosAppStroeUrl =
- 'https://apps.apple.com/cn/app/%E6%BB%A1%E5%9B%AD%E6%98%A5%E7%BA%BF%E4%B8%8A%E5%95%86%E5%9F%8E/id1524593346';
- export function getUpApp () {
-
- let hj = uni.getSystemInfoSync().platform;
-
-
-
- if (hj === 'android') {
-
-
-
-
-
-
- }
- console.log('开始升级');
- getAppVersion().then((res)=>{
- console.log(res,'回调');
- let r = res.data;
- plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
- console.log(r.version,'获取版本');
-
- let version = r.version;
-
- const arr = r.version.split('.');
-
- const arr1 = wgtinfo.version.split('.');
- console.log(version,'升级数据2');
- console.log(arr,'升级数据3');
- console.log(arr1,'升级数据4');
- let up = false;
-
- for (let i = 0; i < arr.length; i++) {
-
- const x = +arr[i];
-
- const y = +arr1[i];
-
- console.log(x,y,'循环');
- if (x >= y) {
-
-
-
-
-
-
-
-
-
-
- console.log(x,y);
- if(up==true){
- return;
- }
- if (x > y) {
- up = true;
- uni.showModal({
- title: '提示',
- content: '请更新应用',
- showCancel: false,
- success(e) {
-
-
-
-
-
- if (hj === 'android') {
-
- console.log(r.apk,'下載地址');
- downApp(r.apk);
- }
- }
- });
- }
-
- }
- }
- });
- }).catch((res)=>{
- console.log(res);
- })
- }
- export function downApp (version) {
- let url = '';
- if(version.indexOf('http')>-1){
- url = version;
- }else{
- url = store.state.baseURL+version
- }
- console.log(url);
- plus.nativeUI.showWaiting('下载升级包...');
- plus.downloader
- .createDownload(url, {}, (d, status) => {
- if (status == 200) {
- installApp(d.filename);
- } else {
- plus.nativeUI.alert('下载升级包失败!');
- }
- plus.nativeUI.closeWaiting();
- })
- .start();
- }
- export function installApp (path) {
- plus.nativeUI.showWaiting('安装升级包...');
- plus.runtime.install(
- path, {},
- function() {
- plus.nativeUI.closeWaiting();
- uni.showToast({
- icon: 'none',
- title: '升级完成,准备重新载入'
- });
- setTimeout(_ => {
- uni.hideToast();
- plus.runtime.restart();
- }, 1000);
- },
- function(e) {
- plus.nativeUI.closeWaiting();
- plus.nativeUI.alert('安装升级包失败[' + e.code + ']:' + e.message);
- }
- );
- }
|