自动更新,从多个接口更新,避免单一的接口挂掉了无法更新
This commit is contained in:
2
App.vue
2
App.vue
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
uni.getSystemInfo({success:function(res){
|
uni.getSystemInfo({success:function(res){
|
||||||
if(res.uniPlatform=='app'){
|
if(res.uniPlatform=='app'){
|
||||||
upgrade.checkAndUpdateWgt("http://114.55.111.217/app/CheckUpdate");
|
upgrade.checkAndUpdateWgt();
|
||||||
bleTool.getBleTool();
|
bleTool.getBleTool();
|
||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
|
|||||||
@ -148,7 +148,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
linkAllDevices() {
|
linkAllDevices() {
|
||||||
console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
||||||
|
|
||||||
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
||||||
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import config from '../config/index.js';
|
import config from '../config/index.js';
|
||||||
const env = 'production'; //production development //开发of线上 改这里就行
|
const env = 'development'; //production development //开发of线上 改这里就行
|
||||||
const BASE = config[env];
|
const BASE = config[env];
|
||||||
const request = (options) => {
|
const request = (options) => {
|
||||||
console.log("options"+JSON.stringify(options),BASE.BASE_URL)
|
console.log("options"+JSON.stringify(options),BASE.BASE_URL)
|
||||||
|
|||||||
161
utils/update.js
161
utils/update.js
@ -1,66 +1,29 @@
|
|||||||
import request,{baseURL} from '@/utils/request.js'
|
import request, {
|
||||||
|
baseURL
|
||||||
|
} from '@/utils/request.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查并执行wgt热更新
|
* 检查并执行wgt热更新
|
||||||
* @param {String} updateUrl - 检查更新的接口地址
|
* @param {String} updateUrl - 检查更新的接口地址
|
||||||
*/
|
*/
|
||||||
function checkAndUpdateWgt(updateUrl) {
|
function checkAndUpdateWgt(updateUrl) {
|
||||||
if(!plus){
|
if (!plus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 显示加载提示
|
// 显示加载提示
|
||||||
|
|
||||||
|
let urls = ['http://114.55.111.217/app/CheckUpdate', 'https://t3v3e2xsjv.by.takin.cc/app/CheckUpdate'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 1. 获取当前应用版本信息
|
// 1. 获取当前应用版本信息
|
||||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||||
const currentVersion = widgetInfo.version;
|
const currentVersion = widgetInfo.version;
|
||||||
console.log("当前版本:" + currentVersion);
|
console.log("当前版本:" + currentVersion);
|
||||||
// request({
|
|
||||||
// url:'/app/auth/version',
|
|
||||||
// method: 'get'
|
|
||||||
// }).then(res=>{
|
|
||||||
// console.log("检查版本更新:",res);
|
|
||||||
// let os=plus.os.name.toLowerCase();
|
|
||||||
// if(res.code!=200){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// let f=res.data.find(v=>{
|
|
||||||
// if(v.dictLabel.toLowerCase()==os){
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// });
|
|
||||||
// if(f){
|
|
||||||
// if(f.dictValue==currentVersion){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// uni.showModal({
|
|
||||||
// title: '检测到更新',
|
|
||||||
// content: '当前版本“'+currentVersion+'”,发现新版本“'+f.dictValue+'”,是否立即更新?',
|
|
||||||
// confirmText: '立即更新',
|
|
||||||
// cancelText: '稍后更新',
|
|
||||||
// success: (modalRes) => {
|
|
||||||
// if (modalRes.confirm) {
|
|
||||||
// downloadAndInstallWgt(f.remark);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// }).catch(ex=>{
|
let callbck = (res) => {
|
||||||
// console.log("检查更新失败:",ex);
|
|
||||||
// });
|
|
||||||
// 2. 调用后端接口检查是否有更新
|
|
||||||
uni.request({
|
|
||||||
url: updateUrl,
|
|
||||||
method: 'GET',
|
|
||||||
data: {
|
|
||||||
currentVersion: currentVersion,
|
|
||||||
platform: uni.getSystemInfoSync().platform
|
|
||||||
},
|
|
||||||
success: (res) => {
|
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
console.log("检查更新成功=", res)
|
console.log("检查更新成功=", res)
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
@ -88,18 +51,104 @@ function checkAndUpdateWgt(updateUrl) {
|
|||||||
duration: 2000
|
duration: 2000
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let Update = (url) => {
|
||||||
|
console.log("url=",url);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.request({
|
||||||
|
url: url,
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
currentVersion: currentVersion,
|
||||||
|
platform: uni.getSystemInfoSync().platform
|
||||||
|
},
|
||||||
|
success: (res) => {
|
||||||
|
console.log("res=>",res)
|
||||||
|
res.type='1';
|
||||||
|
resolve(res);
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
uni.hideLoading();
|
console.log("err=",err);
|
||||||
uni.showToast({
|
reject(err);
|
||||||
title: '检查更新失败',
|
},
|
||||||
icon: 'none',
|
complete:()=>{
|
||||||
duration: 2000
|
console.log("complete");
|
||||||
});
|
|
||||||
console.error('检查更新失败:', err);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let Callback1 = (res) => {
|
||||||
|
console.log("检查版本更新:", res);
|
||||||
|
let os = plus.os.name.toLowerCase();
|
||||||
|
if (res.code != 200) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let f = res.data.find(v => {
|
||||||
|
if (v.dictLabel.toLowerCase() == os) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (f) {
|
||||||
|
if (f.dictValue == currentVersion) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.showModal({
|
||||||
|
title: '检测到更新',
|
||||||
|
content: '当前版本“' + currentVersion + '”,发现新版本“' + f.dictValue + '”,是否立即更新?',
|
||||||
|
confirmText: '立即更新',
|
||||||
|
cancelText: '稍后更新',
|
||||||
|
success: (modalRes) => {
|
||||||
|
if (modalRes.confirm) {
|
||||||
|
downloadAndInstallWgt(f.remark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let Update1 = () => {
|
||||||
|
return request({
|
||||||
|
url: '/app/auth/version',
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let promises = [];
|
||||||
|
for (var i = 0; i < urls.length; i++) {
|
||||||
|
promises.push(Update(urls[i]));
|
||||||
|
}
|
||||||
|
promises.push(Update1());
|
||||||
|
|
||||||
|
Promise.allSettled(promises).then(results => {
|
||||||
|
let length = results.length;
|
||||||
|
let flag=false;
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
console.log('results[i]=',results[i]);
|
||||||
|
if (results[i].status == 'fulfilled' && results[i].value.type==='1' ) {
|
||||||
|
flag=true;
|
||||||
|
callbck(results[i].value)
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(results[i].status == 'fulfilled' && results[i].value.type!=='1'){
|
||||||
|
flag=true;
|
||||||
|
Callback1(results[i].value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!flag){
|
||||||
|
console.log("检查更新失败了");
|
||||||
|
}else{
|
||||||
|
console.log("检查更新成功");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -110,8 +159,8 @@ function checkAndUpdateWgt(updateUrl) {
|
|||||||
*/
|
*/
|
||||||
function downloadAndInstallWgt(wgtUrl) {
|
function downloadAndInstallWgt(wgtUrl) {
|
||||||
// 显示下载进度
|
// 显示下载进度
|
||||||
var wating=plus.nativeUI.showWaiting({
|
var wating = plus.nativeUI.showWaiting({
|
||||||
title:"下载中0%"
|
title: "下载中0%"
|
||||||
});
|
});
|
||||||
// uni.showLoading({
|
// uni.showLoading({
|
||||||
// title: '更新下载中...',
|
// title: '更新下载中...',
|
||||||
@ -184,7 +233,7 @@ function downloadAndInstallWgt(wgtUrl) {
|
|||||||
// 监听下载进度
|
// 监听下载进度
|
||||||
downloadTask.onProgressUpdate((progress) => {
|
downloadTask.onProgressUpdate((progress) => {
|
||||||
console.log('下载进度: ' + progress.progress + '%');
|
console.log('下载进度: ' + progress.progress + '%');
|
||||||
wating.setTitle("下载中"+ progress.progress + '%');
|
wating.setTitle("下载中" + progress.progress + '%');
|
||||||
// 可以在这里更新自定义进度条
|
// 可以在这里更新自定义进度条
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user