123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- import store from '../store/index.js'
- const baseurl = store.state.baseURL
- const getUpAppUrl = baseurl + '/api/version';
- const getIosUpAppUrl = 'https://itunes.apple.com/cn/lookup?id=6474850968'
- const iosAppStroeUrl =
- 'https://apps.apple.com/cn/app/%E6%98%93%E8%B6%A3cbb/id=6474850968';
- export function getUpApp() {
-
- let hj = uni.getSystemInfoSync().platform;
-
- if (hj === 'ios') {
- uni.request({
- url: getIosUpAppUrl,
- method: 'POST',
- data: {},
- success: res => {
- let r = res.data;
- isUp(r, hj)
- },
- });
-
- return
- }
-
- if (hj === 'android') {
- uni.request({
- url: getUpAppUrl,
- method: 'GET',
- data: {},
- success: res => {
- let r = res.data.data;
- console.log(r, '234')
- isUp(r, hj)
- },
- fail: res => {
- console.log(res, 'shib');
- }
- });
- }
- }
- function isUp(r, hj) {
- plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
- let version = '';
- let arr = '';
- if (hj == "android") {
- console.log(r,555);
-
- version = r.version_code;
-
- arr = r.version_code.split('.');
- console.log(arr);
- }
- if (hj == "ios") {
-
- version = r.results[0].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) {
- console.log('数据隐藏');
-
- store.commit('changeState', false);
- return
- }
-
- else if (x > y) {
- uni.showModal({
- title: '提示',
- content: '请更新应用',
- showCancel: false,
- success(e) {
- if (hj == "android") {
-
- uni.navigateTo({
- url:'/pages/index/downLoad?apk='+r.apk,
- fail(er) {
- console.log(er,'eee');
- }
- })
-
- }
- if (hj == "ios") {
- plus.runtime.openURL(
- iosAppStroeUrl
- );
- }
- }
- });
- return
- }
-
- else if (x == y && i == arr.length - 1) {
- store.commit('changeState', true);
- return
- }
- }
- });
- }
- 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);
- }
- );
- }
|