64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
// #ifdef APP
|
|
import Updater from '@/uni_modules/guyue-updater/index';
|
|
// #endif
|
|
|
|
function compareVersions(version1, version2) {
|
|
const arr1 = version1.split('.').map(Number);
|
|
const arr2 = version2.split('.').map(Number);
|
|
for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) {
|
|
const num1 = i < arr1.length ? arr1[i] : 0;
|
|
const num2 = i < arr2.length ? arr2[i] : 0;
|
|
|
|
if (num1 > num2) {
|
|
return 1;
|
|
} else if (num1 < num2) {
|
|
return -1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
export const inUpdate = () => {
|
|
uni.request({
|
|
url: 'http://192.168.1.22:8546/api/app_update',
|
|
method: 'GET',
|
|
success: (res) => {
|
|
console.log('更新');
|
|
console.log('======', res);
|
|
// #ifdef APP-PLUS
|
|
let os = uni.getSystemInfoSync();
|
|
if (Object.keys(res.data.data).length > 0) {
|
|
// 版本更新
|
|
if (compareVersions(res.data.data.version||'1.0.0', os.appWgtVersion) == 1) {
|
|
try {
|
|
let info = res.data.data || {};
|
|
let version = {
|
|
title: info.title || '发现新版本',
|
|
content: info.content || '修复了部分BUG',
|
|
versionName: info.version || '1.0.1',
|
|
brand: os.brand,
|
|
downUrl: info.dow_url || '',
|
|
force: info.force == 1 ? true : false, // 是否强制更新
|
|
quiet: info.quiet == 1 ? true : false // 是否静默更新
|
|
}
|
|
Updater.update(version);
|
|
} catch (e) {
|
|
uni.showToast({
|
|
title: '更新失败'
|
|
})
|
|
}
|
|
// uni.hideLoading();
|
|
}
|
|
|
|
}
|
|
// #endif
|
|
},
|
|
fail: (err) => {
|
|
console.log('err', err);
|
|
},
|
|
complete: (res) => {
|
|
console.log('结束', res);
|
|
}
|
|
})
|
|
|
|
} |