|
@@ -0,0 +1,149 @@
|
|
|
+import confige from '@/config/app.js'
|
|
|
+import {getAppVersion} from '@/api/api.js'
|
|
|
+const getIosUpAppUrl = 'https://itunes.apple.com/cn/lookup?id=6476127203'
|
|
|
+const iosAppStroeUrl =
|
|
|
+ 'https://apps.apple.com/cn/app/%E7%A5%9E%E8%8B%B1%E4%BC%98%E9%80%89/id6476127203';
|
|
|
+
|
|
|
+// 获取app是否需要升级
|
|
|
+export function getUpApp () {
|
|
|
+ // 获取当前运行系统
|
|
|
+ let hj = uni.getSystemInfoSync().platform;
|
|
|
+ // 隐藏显示内容
|
|
|
+ uni.setStorageSync("showAppHistary",false)
|
|
|
+ // 获取仓库app数据对象
|
|
|
+ if (hj === 'ios') {
|
|
|
+ uni.request({
|
|
|
+ url: getIosUpAppUrl,
|
|
|
+ method: 'POST',
|
|
|
+ data: {},
|
|
|
+ success: res => {
|
|
|
+ console.log(res)
|
|
|
+ let r = res.data;
|
|
|
+ isUp(r, hj)
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ // store.commit('changeState', true);
|
|
|
+ console.log(res, 'shib');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 设置显示数据
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 当前系统为安卓则显示数据
|
|
|
+ if (hj === 'android') {
|
|
|
+ getAppVersion().then((res)=>{
|
|
|
+ let r = res.data;
|
|
|
+ console.log(r,'rr')
|
|
|
+ isUp(r, hj)
|
|
|
+ }).catch((res)=>{
|
|
|
+ console.log(res);
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+function isUp(r, hj) {
|
|
|
+ plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
|
|
|
+ let version = '';
|
|
|
+ let arr = '';
|
|
|
+ if (hj == "android") {
|
|
|
+ // 保存线上版本号
|
|
|
+ version =r.version;
|
|
|
+ // store.commit('setappversion', r.version);
|
|
|
+ // 获取线上版本
|
|
|
+ arr = r.version.split('.');
|
|
|
+ }
|
|
|
+ if (hj == "ios") {
|
|
|
+ // 保存线上版本号
|
|
|
+ version = r.results[0].version;
|
|
|
+ // store.commit('setappversion', version);
|
|
|
+ // 获取线上版本
|
|
|
+ arr = r.results[0].version.split('.');
|
|
|
+ }
|
|
|
+ // 获取当前系统
|
|
|
+ const arr1 = wgtinfo.version.split('.');
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ // 线上版本号
|
|
|
+ const x = +arr[i];
|
|
|
+ // 本地版本号
|
|
|
+ const y = +arr1[i];
|
|
|
+ // 判断线上版本是否小于本地版本
|
|
|
+ console.log(x, y, '数据');
|
|
|
+ if (x < y) {
|
|
|
+ // 设置显示数据
|
|
|
+ uni.setStorageSync("showAppHistary",false)
|
|
|
+ console.log('222')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 判断线上版本是否大于本地版本
|
|
|
+ else if (x > y) {
|
|
|
+ uni.setStorageSync("showAppHistary",true)
|
|
|
+ console.log('223')
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '请更新应用',
|
|
|
+ showCancel: false,
|
|
|
+ success(e) {
|
|
|
+ if (hj == "android") {
|
|
|
+ downApp(r.apk);
|
|
|
+ }
|
|
|
+ if (hj == "ios") {
|
|
|
+ plus.runtime.openURL(
|
|
|
+ iosAppStroeUrl
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 判断是否本地版本等于线上版本
|
|
|
+ else if (x == y && i == arr.length - 1) {
|
|
|
+ uni.setStorageSync("showAppHistary",true)
|
|
|
+ console.log('===')
|
|
|
+ // store.commit('changeState', true);
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+// 下载app
|
|
|
+export function downApp (version) {
|
|
|
+ let url = '';
|
|
|
+ if(version.indexOf('http')>-1){
|
|
|
+ url = version;
|
|
|
+ }else{
|
|
|
+ url = confige.HTTP_REQUEST_URL+version
|
|
|
+ }
|
|
|
+ console.log(url);
|
|
|
+ plus.nativeUI.showWaiting('下载升级包...');
|
|
|
+ plus.downloader
|
|
|
+ .createDownload(url, {}, (d, status) => {
|
|
|
+ if (status == 200) {
|
|
|
+ installApp(d.filename); // 安装app
|
|
|
+ } else {
|
|
|
+ plus.nativeUI.alert('下载升级包失败!');
|
|
|
+ }
|
|
|
+ plus.nativeUI.closeWaiting();
|
|
|
+ })
|
|
|
+ .start();
|
|
|
+}
|
|
|
+// 安装app
|
|
|
+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);
|
|
|
+ }
|
|
|
+ );
|
|
|
+}
|