139 lines
2.9 KiB
JavaScript
139 lines
2.9 KiB
JavaScript
/**
|
||
* 软件升级管理类
|
||
*
|
||
* @author terrfly
|
||
* @site https://www.jeequan.com
|
||
* @date 2022/04/13 15:18
|
||
*/
|
||
|
||
import { $versionDetection } from '@/http/apiManager.js';
|
||
import appConfig from '@/config/appConfig.js'
|
||
|
||
// app更新
|
||
function appPlusUpdate(value){
|
||
let isCheck = value //点击检查更新时是否检查
|
||
// 获取版本号
|
||
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(isCheck){
|
||
uni.showToast({
|
||
icon:'none',
|
||
title:'已是最新版本'
|
||
})
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// // 版本号一致
|
||
// if(){
|
||
// return false;
|
||
// }
|
||
|
||
// 是否强制更新
|
||
let isForceUpdate = bizData.forceUpdate == 1
|
||
uni.showModal({
|
||
title:'当前本:V'+ inf.versionCode.split('').join('.') +';发现新版本:' + 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(value) {
|
||
|
||
// #ifdef APP-PLUS
|
||
switch(uni.getSystemInfoSync().platform){
|
||
case 'android':
|
||
appPlusUpdate(value) //仅安卓更新
|
||
break;
|
||
case 'ios':
|
||
console.log('运行iOS上')
|
||
break;
|
||
default:
|
||
console.log('运行在开发者工具上')
|
||
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')
|
||
}
|
||
} |