1
0
forked from dyf/APP

670加入机器状态、设备详情加接口请求

This commit is contained in:
liub
2025-09-18 17:31:40 +08:00
parent 404e42a7d8
commit cb44810c6b
10 changed files with 454 additions and 221 deletions

View File

@ -83,10 +83,18 @@ function sendPic(data){
});
}
//设备详情
function getDetail(id){
return request({
url: '/api/xinghan/device/'+id,
method: 'get',
})
}
export default{
sendUsr:sendUsr,
warnMsg:warnMsg,
sendPic:sendPic
sendPic:sendPic,
getDetail:getDetail
}

View File

@ -328,7 +328,7 @@
});
if (!f) {
these.getDetail();
these.showBleUnConnect();
return;
}
@ -347,7 +347,7 @@
these.formData.deviceId = f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
these.setBleFormData();
these.getDetail();
});
@ -1203,7 +1203,22 @@
setTimeout(task, 0);
},
getDetail() {
var that = this;
usrApi.getDetail(this.device.id).then(res => {
if (res && res.code == 200) {
res = res.data;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
these.formData.textLines[2] = personnelInfo.unitName;
these.formData.textLines[1] = personnelInfo.name;
these.formData.textLines[0] = personnelInfo.position;
}
}
});
},
ack: function() {

View File

@ -255,10 +255,10 @@
cMode: false,
modeCurr: 'low',
company: '黄石消防支队',
name: '菜英俊',
job: '小队长',
id: 'HSXF01061',
company: '',
name: '',
job: '',
id: '',
iswarn: false
},
rgb565Data: [],
@ -314,6 +314,7 @@
these.showBleUnConnect();
these.getDetail();
return;
}
let form = f.formData;
@ -331,7 +332,7 @@
these.formData.deviceId = f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
these.setBleFormData();
these.getDetail();
});
@ -457,6 +458,23 @@
return f;
},
getDetail() {
var that = this;
usrApi.getDetail(this.device.id).then(res => {
if (res && res.code == 200) {
res = res.data;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
that.formData.company = personnelInfo.unitName;
that.formData.name = personnelInfo.name;
that.formData.job = personnelInfo.position;
that.formData.id = personnelInfo.code
}
}
});
},
setBleFormData() {
ble.data.LinkedList.find((v) => {
if (v.deviceId == these.formData.deviceId) {
@ -959,8 +977,8 @@
}
uni.uploadFile({
// url: 'http://114.55.111.217/video/upload',
url: baseURL+"app/video/upload",
url: 'http://114.55.111.217/video/upload',
// url: baseURL+"app/video/upload",
filePath: videoPath,
name: 'file',
header: {

View File

@ -34,11 +34,28 @@
<text class="value">{{device.deviceName}}</text>
</view>
<view class="item">
<text class="lbl">定位信息</text>
<view>
<view>{{formData.lon}}&nbsp;&nbsp;{{formData.lat}}</view>
<text class="value">{{formData.address}}</text>
<text class="lbl">设备状态</text>
<text class="value">{{formData.sta_system}}</text>
</view>
<view class="item">
<text class="lbl">定位信息</text>
<view class="multiValue">
<view class="valueItem">
{{formData.Lon}}
</view>
<view class="valueItem">
{{formData.Lat}}
</view>
<view class="valueItem">
<view style="width:80%;float: right;text-align: right;">{{formData.address}}</view>
<view class="clear"></view>
</view>
</view>
</view>
</view>
@ -358,7 +375,8 @@
warnLevel: "", //报警级别
staticWarn: false, //静止报警
fourGStrenth: 0, //4G信号强度
deviceId: ""
deviceId: "",
sta_system: "" //设备状态0关机1仅充电2开机未充电,3开机且充电
},
device: {
id: "",
@ -413,6 +431,7 @@
var device = data.data;
these.Status.apiType = data.apiType;
these.device = device;
if (these.device.deviceImei) {
these.initMQ();
}
@ -425,6 +444,7 @@
return false;
});
if (!f) {
these.getDetail();
return;
}
let form = f.formData;
@ -440,6 +460,7 @@
} else if (these.device.deviceImei) {
these.formData['imei'] = these.device.deviceImei;
}
these.getDetail();
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
});
@ -454,6 +475,74 @@
},
methods: {
getDetail() {
var that = this;
api.getDetail(this.device.id).then(res => {
if (res && res.code == 200) {
res = res.data;
let json=res;
console.log("res=",res);
that.formData.Lon = res.longitude;
that.formData.Lat = res.latitude;
that.formData.address = res.address;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
that.formData.company = personnelInfo.unitName;
that.formData.usrname = personnelInfo.name;
that.formData.job = personnelInfo.position;
that.formData.usrid = personnelInfo.code
}
let dic = {
"3": "hight",
"2": "center",
"1": "low",
"0": "close",
};
let staticLevelText = dic[json.staDetectGrade];
that.formData.modeCurr = staticLevelText;
dic = {
"0": "none",
"1": "ruo",
"2": "center",
"3": "hight",
"4": "veryhight",
};
let warn = dic[json.staDetectResult];
that.formData.warnLevel = warn;
let lightingLevelText = json.staLightGrade === 1 ? 'hight' : json.staLightGrade === 2 ? 'low' :
'close';
that.formData.lightCurr = lightingLevelText;
that.formData.battary = json.staPowerPercent
let hours = Math.floor(json.staPowerTime / 60);
let remainingMinutes = json.staPowerTime % 60;
let xuhang = '0分';
// 处理不同情况的显示
if (hours === 0) {
xuhang = `${remainingMinutes}`;
} else if (remainingMinutes === 0) {
xuhang = `${hours}小时`;
} else {
xuhang = `${hours}小时${remainingMinutes}`;
}
that.formData.xuhang = xuhang;
let sosText = json.staSOSGrade === 2 ? 'rb' : json.staSOSGrade === 1 ? "sg" : "close";
that.formData.SOS = sosText;
}
});
},
getWarnStyle(index) {
let className = "";
@ -540,6 +629,7 @@
console.log("收到设备上报的数据", payload);
this.parseDataMQ(json);
}
//以下操作已改到后端
// else if (keys.indexOf('sta_PicTrans') > -1) { //发送开机画面
// console.log("收到开机画面答复", payload);
// // this.SendImgMQ(json);
@ -598,23 +688,29 @@
},
parseDataMQ(json) {
let receiveData = {};
let staticLevelText = "";
let dic = {
let dic = {};
if ("sta_DetectGrade" in json) {
dic = {
"3": "hight",
"2": "center",
"1": "low",
"0": "close",
};
staticLevelText = dic[json.sta_DetectGrade];
let staticLevelText = dic[json.sta_DetectGrade];
receiveData.modeCurr = staticLevelText;
}
let lightingLevelText = json.sta_LightGrade ===
1 ? 'hight' :
json.sta_LightGrade ===
2 ?
'low' :
if ("sta_LightGrade" in json) {
let lightingLevelText = json.sta_LightGrade === 1 ? 'hight' : json.sta_LightGrade === 2 ? 'low' :
'close';
let warn = "";
receiveData.lightCurr = lightingLevelText;
}
if ("sta_DetectResult" in json) {
dic = {
"0": "none",
"1": "ruo",
@ -622,32 +718,50 @@
"3": "hight",
"4": "veryhight",
};
warn = dic[json.sta_DetectResult];
let sosText = null;
if (json.sta_SOSGrade !== undefined) {
sosText = json.sta_SOSGrade === 2 ? 'rb' :
json.sta_SOSGrade === 1 ? "sg" : "close"
let warn = dic[json.sta_DetectResult];
receiveData.warnLevel = warn;
}
if ("sta_SOSGrade" in json) {
let sosText = json.sta_SOSGrade === 2 ? 'rb' : json.sta_SOSGrade === 1 ? "sg" : "close";
receiveData.SOS = sosText;
}
if ("sta_ShakeBit" in json) {
let staticWarn = json.sta_ShakeBit === 1;
receiveData.modeCurr = staticLevelText;
receiveData.lightCurr = lightingLevelText;
receiveData.xuhang = json.sta_PowerTime + "分钟";
receiveData.battary = json.sta_PowerPercent;
receiveData.warnLevel = warn;
receiveData.staticWarn = staticWarn;
receiveData.fourGStrenth = json.sta_4gSinal;
receiveData.imei = json.sta_imei;
receiveData.Lon = json.sta_longitude;
receiveData.Lat = json.sta_latitude;
}
if ("sta_PowerTime" in json) {
let hours = Math.floor(json.sta_PowerTime / 60);
let remainingMinutes = json.sta_PowerTime % 60;
let xuhang = '0分';
// 处理不同情况的显示
if (hours === 0) {
xuhang = `${remainingMinutes}`;
} else if (remainingMinutes === 0) {
xuhang = `${hours}小时`;
} else {
xuhang = `${hours}小时${remainingMinutes}`;
}
receiveData.xuhang = xuhang;
}
("sta_PowerPercent" in json) && (receiveData.battary = json.sta_PowerPercent);
("sta_4gSinal" in json) && (receiveData.fourGStrenth = json.sta_4gSinal);
("sta_imei" in json) && (receiveData.imei = json.sta_imei);
("sta_longitude" in json) && (receiveData.Lon = json.sta_longitude);
("sta_latitude" in json) && (receiveData.Lat = json.sta_latitude);
if ("sta_system" in json) {
dic = {
"0": "关机",
"1": "仅充电",
"2": "开机未充电",
"3": "开机且充电"
}
receiveData.sta_system = dic[json.sta_system];
}
this.refreshFormData(receiveData, 'auto');
return receiveData;
},
@ -686,14 +800,14 @@
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
if (key in these.formData) {
these.formData[key] = data[key];
this.formData[key] = data[key];
}
}
if (this.formData.imei) {
this.initMQ();
}
if (this.formData.staticWarn) { //有静止报警
these.showPop({
this.showPop({
message: "设备静止报警中",
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
borderColor: "#e034344d",
@ -701,8 +815,6 @@
buttonText: "确定",
clickEvt: "staticWarn"
});
}
this.setBleFormData();
@ -1576,8 +1688,8 @@
}
console.log("baseURL=", baseURL);
uni.uploadFile({
// url: 'http://114.55.111.217/video/upload',
url: baseURL + "/app/video/upload",
url: 'http://114.55.111.217/video/upload',
// url: baseURL + "/app/video/upload",
filePath: videoPath,
name: 'file',
header: {
@ -1617,7 +1729,7 @@
} else {
console.log("服务器未返回正确的数据");
console.log("服务器未返回正确的数据", arr);
these.showPop({
@ -2187,7 +2299,8 @@
.eqinfo .item {
width: 100%;
height: 60rpx;
min-height: 60rpx;
height: auto;
line-height: 60rpx;
padding: 0rpx 28rpx;
box-sizing: border-box;
@ -2204,7 +2317,7 @@
font-family: PingFang SC;
font-size: 28rpx;
font-weight: 400;
width: 140rpx;
letter-spacing: 0.07px;
text-align: left;
}
@ -2219,6 +2332,26 @@
text-align: left;
}
.eqinfo .multiValue {
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: flex-end;
align-items: flex-end;
justify-content: flex-start;
width: calc(100% - 140rpx)
}
.eqinfo .valueItem {
height: auto;
line-height: 40rpx;
color: rgba(255, 255, 255, 0.6);
font-family: PingFang SC;
font-size: 14px;
font-weight: 400;
letter-spacing: 0.07px;
}
.lamp {
margin-top: 24rpx;
}

View File

@ -328,7 +328,7 @@
});
if (!f) {
these.getDetail();
these.showBleUnConnect();
return;
}
@ -347,7 +347,7 @@
these.formData.deviceId = f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
these.setBleFormData();
these.getDetail();
});
@ -529,17 +529,17 @@
}
});
},
showBleUnConnect(){
showBleUnConnect() {
this.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
buttonText:'去连接',
okCallback:function(){
buttonText: '去连接',
okCallback: function() {
console.log("1111");
uni.navigateTo({
url:"/pages/common/addBLE/addEquip",
url: "/pages/common/addBLE/addEquip",
events: {
BindOver: function(data) {
console.log(data)
@ -547,10 +547,12 @@
},
success: function(res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('detailData', { data: these.device })
res.eventChannel.emit('detailData', {
data: these.device
})
},
fail(ex){
console.log("跳转失败",ex);
fail(ex) {
console.log("跳转失败", ex);
}
})
}
@ -642,8 +644,8 @@
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
});
resolve();
@ -974,7 +976,7 @@
if (this.Status.Pop.clickEvt == 'SendUsr') {
}
if(this.Status.Pop.okCallback){
if (this.Status.Pop.okCallback) {
this.Status.Pop.okCallback();
}
this.Status.Pop.showPop = false;
@ -992,7 +994,7 @@
okCallback: null,
cancelCallback: null,
popType: 'custom',
buttonText:'确定',
buttonText: '确定',
clickEvt: ''
};
if (!option) {
@ -1172,8 +1174,8 @@
this.showPop({
message: "发送成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
borderColor : '#BBE600',
buttonBgColor : '#BBE600'
borderColor: '#BBE600',
buttonBgColor: '#BBE600'
});
@ -1199,7 +1201,22 @@
setTimeout(task, 0);
},
getDetail() {
var that = this;
usrApi.getDetail(this.device.id).then(res => {
if (res && res.code == 200) {
res = res.data;
let personnelInfo = res.personnelInfo;
if (personnelInfo) {
these.formData.textLines[2] = personnelInfo.unitName;
these.formData.textLines[1] = personnelInfo.name;
these.formData.textLines[0] = personnelInfo.position;
}
}
});
},
ack: function() {

View File

@ -56,6 +56,7 @@
<view class="w50 fleft">静止报警状态:{{receiveData.staticWarn}}</view>
<view class="w50 fleft">4G信号强度:{{receiveData.fourGStrenth}}</view>
<view class="w50 fleft">SOS模式:{{receiveData.SOS}}</view>
<view class="w50 fleft">设备状态:{{receiveData.sta_system}}</view>
<view class="clear"></view>
</view>
<view>重发包序号{{reSendNumber}}</view>
@ -226,7 +227,7 @@
<script>
import gbk from '@/utils/gbk.js';
import MqttClient from '@/utils/mqtt.js';
import request,{
import request, {
baseURL
} from '@/utils/request.js';
var videoChannel = null;
@ -294,7 +295,8 @@
IMEI: "",
Lon: "",
Lat: "",
SOS: ""
SOS: "",
sta_system: ""
},
subscits: [],
videoPath: "",
@ -363,14 +365,16 @@
"0": "关闭",
};
staticLevelText = dic[json.sta_DetectGrade];
if ("sta_DetectGrade" in json) {
staticLevelText = dic[json.sta_DetectGrade.toString()];
}
let lightingLevelText = "";
if ("sta_LightGrade" in json) {
lightingLevelText = json.sta_LightGrade === 1 ? '强光' : json.sta_LightGrade === 2 ? '弱光' : '关闭';
}
let lightingLevelText = json.sta_LightGrade ===
1 ? '强光' :
json.sta_LightGrade ===
2 ?
'弱光' :
'关闭';
let warn = "";
dic = {
"0": "无预警",
@ -379,25 +383,47 @@
"3": "强预警",
"4": "非常强预警",
};
warn = dic[json.sta_DetectResult];
if ("sta_DetectResult" in json) {
warn = dic[json.sta_DetectResult.toString()];
}
let sosText = json.sta_SOSGrade === 2 ? '红蓝模式' :
json.sta_SOSGrade === 1 ? "爆闪模式" : "关闭"
let staticWarn = json.sta_ShakeBit === 1 ? '正在报警' : '未报警';
let sosText = "";
if ("sta_SOSGrade" in json) {
sosText=json.sta_SOSGrade === 2 ? '红蓝模式' : json.sta_SOSGrade === 1 ? "爆闪模式" : "关闭"
}
let staticWarn = "";
if ("sta_ShakeBit" in json) {
json.sta_ShakeBit === 1 ? '正在报警' : '未报警';
}
if ("sta_system" in json) {
dic = {
"0": "关机",
"1": "仅充电",
"2": "开机未充电",
"3": "开机且充电"
}
this.receiveData.sta_system = dic[json.sta_system.toString()];
}
this.receiveData.staticLevel = staticLevelText;
this.receiveData.lightingLevel = lightingLevelText;
this.receiveData.lightingTime = json.sta_PowerTime + "分钟";
this.receiveData.batteryLevel = json.sta_PowerPercent + "%";
("sta_PowerTime" in json) && (this.receiveData.lightingTime = json.sta_PowerTime + "分钟");
("sta_PowerPercent" in json) && (this.receiveData.batteryLevel = json.sta_PowerPercent + "%");
this.receiveData.SOS = sosText;
this.receiveData.warnLevel = warn;
this.receiveData.staticWarn = staticWarn;
this.receiveData.fourGStrenth = json.sta_4gSinal;
this.receiveData.IMEI = json.sta_imei;
this.receiveData.Lon = json.sta_longitude;
this.receiveData.Lat = json.sta_latitude;
("sta_4gSinal" in json) && (this.receiveData.fourGStrenth = json.sta_4gSinal);
("sta_imei" in json ) && (this.receiveData.IMEI = json.sta_imei);
("sta_longitude" in json) && (this.receiveData.Lon = json.sta_longitude);
("sta_latitude" in json) && (this.receiveData.Lat = json.sta_latitude);
},
parseData(receive) {
@ -1285,6 +1311,7 @@
setTimeout(() => {
uni.onBLECharacteristicValueChange((
receive) => {
console.log("收到设备数据",receive);
these.parseData(receive);
});
}, 100)
@ -2101,7 +2128,7 @@
let json = JSON.parse(payload);
let keys = Object.keys(json);
console.log("keys=", keys);
if (keys.indexOf('sta_DetectGrade') > -1) { //上报的报文
if (keys.indexOf('sta_system') > -1) { //上报的报文
console.log("收到设备上报的数据", payload);
this.parseDataMQ(json);
} else if (keys.indexOf('sta_PicTrans') > -1) { //发送开机画面

View File

@ -30,7 +30,7 @@
<script>
import Common from '@/utils/Common';
import request,{ baseURL } from '@/utils/request.js';
export default {
data() {
return {
@ -123,15 +123,19 @@
let p2 = new Promise((resolve, reject) => {
let start = new Date();
console.log("Common.baseURL=" + Common.baseURL);
console.log("baseURL=" + baseURL);
const token ="";// uni.getStorageSync('token');
const clientid ="";// uni.getStorageSync('clientID');
uni.uploadFile({
// url: Common.baseURL + 'video/upload',
url:'http://192.168.110.56:8000/app/video/upload',
url: 'http://114.55.111.217/video/upload',
// url:baseURL+"/app/video/upload",
filePath: this.videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data"
"Content-Type": "multipart/form-data",
"Authorization": 'Bearer ' + token,
"clientid": clientid
},
timeout: 600000,
fail: (ex) => {

View File

@ -31,6 +31,7 @@
<script>
import Common from '../../../utils/Common';
import { baseURL } from '../../../utils/request';
var mqttClient=null;
export default {
data() {
@ -127,14 +128,19 @@ var mqttClient=null;
let p2=new Promise((resolve,reject)=>{
let start = new Date();
console.log("Common.baseURL="+Common.baseURL);
console.log("baseURL="+baseURL);
const token ="";// uni.getStorageSync('token');
const clientid ="";// uni.getStorageSync('clientID');
uni.uploadFile({
url:Common.baseURL+'video/upload',
url: 'http://114.55.111.217/video/upload',
// url:baseURL+"/app/video/upload",
filePath: this.videoPath,
name: 'file',
header: {
"Method": "POST",
"Content-Type": "multipart/form-data"
"Content-Type": "multipart/form-data",
"Authorization": 'Bearer ' + token,
"clientid": clientid
},
timeout: 600000,
fail: (ex) => {

View File

@ -415,6 +415,9 @@ class BleHelper {
uni.onBluetoothAdapterStateChange((state) => {
console.log('蓝牙状态发生变化:' + JSON.stringify(state));
if(this.data.available==state.available){
return;
}
this.data.available = state.available;
this.data.discovering = state.discovering;
if (this.data.available && this.data
@ -1095,7 +1098,7 @@ class BleHelper {
},
fail: (ex) => {
ex = this.getError(ex);
console.log("蓝牙连接失败" + JSON.stringify(ex));
console.log("蓝牙"+deviceId+"连接失败" + JSON.stringify(ex));
// 连接超时后自动重试
if (ex.code === 10012 && retryCount < maxRetries) {

View File

@ -15,90 +15,92 @@ function checkAndUpdateWgt(updateUrl) {
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
const currentVersion = widgetInfo.version;
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=>{
console.log("检查更新失败:",ex);
});
// 2. 调用后端接口检查是否有更新
// uni.request({
// url: updateUrl,
// method: 'GET',
// data: {
// currentVersion: currentVersion,
// platform: uni.getSystemInfoSync().platform
// },
// success: (res) => {
// uni.hideLoading();
// console.log("res=", res)
// if (res.statusCode === 200) {
// const updateInfo = res.data.data;
// if (!updateInfo.hasUpdate) {
// request({
// url:'/app/auth/version',
// method: 'get'
// }).then(res=>{
// console.log("检查版本更新:",res);
// let os=plus.os.name.toLowerCase();
// if(res.code!=200){
// return;
// }
// // 3. 显示更新提示
// 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: updateInfo.description || '有新版本可用,是否立即更新?',
// content: '当前版本“'+currentVersion+'”,发现新版本“'+f.dictValue+'”,是否立即更新?',
// confirmText: '立即更新',
// cancelText: '稍后更新',
// success: (modalRes) => {
// if (modalRes.confirm) {
// downloadAndInstallWgt(updateInfo.downloadUrl);
// downloadAndInstallWgt(f.remark);
// }
// }
// });
// } else {
// uni.showToast({
// title: '当前已是最新版本',
// icon: 'none',
// duration: 2000
// });
// }
// },
// fail: (err) => {
// uni.hideLoading();
// uni.showToast({
// title: '检查更新失败',
// icon: 'none',
// duration: 2000
// });
// console.error('检查更新失败:', err);
// }
// }).catch(ex=>{
// console.log("检查更新失败:",ex);
// });
// 2. 调用后端接口检查是否有更新
uni.request({
url: updateUrl,
method: 'GET',
data: {
currentVersion: currentVersion,
platform: uni.getSystemInfoSync().platform
},
success: (res) => {
uni.hideLoading();
console.log("检查更新成功=", res)
if (res.statusCode === 200) {
const updateInfo = res.data.data;
if (!updateInfo.hasUpdate) {
return;
}
// 3. 显示更新提示
uni.showModal({
title: '检测到更新',
content: updateInfo.description || '有新版本可用,是否立即更新?',
confirmText: '立即更新',
cancelText: '稍后更新',
success: (modalRes) => {
if (modalRes.confirm) {
downloadAndInstallWgt(updateInfo.downloadUrl);
}
}
});
} else {
uni.showToast({
title: '当前已是最新版本',
icon: 'none',
duration: 2000
});
}
},
fail: (err) => {
uni.hideLoading();
uni.showToast({
title: '检查更新失败',
icon: 'none',
duration: 2000
});
console.error('检查更新失败:', err);
}
});
});
}