121 lines
2.6 KiB
JavaScript
121 lines
2.6 KiB
JavaScript
import { $versionDetection } from '@/http/apiManager.js';
|
|
import appConfig from '@/config/appConfig.js'
|
|
|
|
// app更新
|
|
function appPlusUpdate(sign){
|
|
|
|
// 获取版本号
|
|
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
|
|
|
|
// 调起接口查询
|
|
$versionDetection({versionNumber: inf.versionCode})
|
|
.then(({ bizData }) => {
|
|
|
|
//返回data为空或者版本号一致
|
|
if (!bizData || Object.keys(bizData).length == 0 || !bizData.versionSerialNumber || bizData.versionSerialNumber == inf.versionCode) {
|
|
if(sign === 'checked') {
|
|
uni.showToast({
|
|
title: '已是最新版本'
|
|
})
|
|
}
|
|
return false;
|
|
}
|
|
// 是否强制更新
|
|
let isForceUpdate = bizData.forceUpdate == 1
|
|
uni.showModal({
|
|
title: '发现新版本:' + bizData.versionName,
|
|
showCancel: !isForceUpdate ,
|
|
content: bizData.versionDesc,
|
|
confirmText: '立即更新',
|
|
confirmColor: '#108EE9',
|
|
success: function(r) {
|
|
if (r.confirm) {
|
|
downLoad(bizData.downloadUrl);
|
|
}else{
|
|
// 强制更新也需要更新
|
|
if(isForceUpdate){
|
|
downLoad(bizData.downloadUrl);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
//下载更新包
|
|
function downLoad(url) {
|
|
|
|
if (!url) {
|
|
uni.showToast({icon: 'none',title: '下载地址错误'});
|
|
return false;
|
|
}
|
|
// 下载文件
|
|
uni.showLoading({title: '更新中'});
|
|
uni.downloadFile({
|
|
url: url,
|
|
success: res => {
|
|
uni.hideLoading();
|
|
if (res.statusCode === 200) {
|
|
uni.showToast({title: '下载成功'});
|
|
plus.runtime.install(res.tempFilePath);
|
|
}
|
|
},
|
|
fail: res => {
|
|
uni.hideLoading();
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// 获取当前版本 & 检查
|
|
export function getCurrentVersionPromise() {
|
|
let isApp = false
|
|
|
|
// #ifdef APP-PLUS
|
|
isApp = true
|
|
// #endif
|
|
|
|
if(!isApp){
|
|
return Promise.reject()
|
|
}
|
|
|
|
// 获取版本号
|
|
return new Promise((resolve, reject) => {
|
|
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
|
|
resolve(inf)
|
|
})
|
|
})
|
|
|
|
}
|
|
|
|
// 获取当前版本 & 检查
|
|
export function checkCurrVersion(sign) {
|
|
// #ifdef APP-PLUS
|
|
switch(uni.getSystemInfoSync().platform){
|
|
case 'android':
|
|
appPlusUpdate(sign) //仅安卓更新
|
|
break;
|
|
case 'ios':
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
// #endif
|
|
}
|
|
|
|
|
|
//同步取出ext.json对象
|
|
export function getExtStoreId(){
|
|
try{
|
|
const extConfig = uni.getExtConfigSync()
|
|
if(extConfig.domain){
|
|
appConfig.env.JEEPAY_BASE_URL = extConfig.domain
|
|
}
|
|
// uni.showToast({title: JSON.stringify(extConfig),icon:"none",duration:3000});
|
|
console.log(extConfig,'extJson对象');
|
|
return extConfig;
|
|
}catch(err){
|
|
console.log(err,'getExtStoreId__error')
|
|
}
|
|
} |