1.添加升级OTA
2.我的添加更换网络入口 3.调试SDK中的删除用户接口
This commit is contained in:
@@ -181,13 +181,13 @@ Component({
|
||||
let rawList = Array.isArray(deviceUserIds) ? deviceUserIds : [];
|
||||
// 兼容对象数组和纯ID数组,统一转为字符串比对
|
||||
let deviceIds = rawList.map(item => ({
|
||||
userID: item.userID,
|
||||
memberID: item.memberID
|
||||
id: item,
|
||||
memberID: ""
|
||||
}));
|
||||
let localIds = userList.map(user => user.id);
|
||||
|
||||
|
||||
// 秤有、列表没有 → 需要从秤删除
|
||||
let needDeleteList = deviceIds.filter(d => !localIds.includes(d.userID));
|
||||
let needDeleteList = deviceIds.filter(d => !localIds.includes(d.id));
|
||||
|
||||
// 秤没有、列表有 → 需要下发到秤
|
||||
let needSyncList = userList.filter(user => !deviceIds.some(d => d.userID == user.id));
|
||||
@@ -257,7 +257,7 @@ Component({
|
||||
wx.showLoading({ title: "正在删除第" + (delIndex + 1) + "/" + needDeleteList.length + "个多余用户...", mask: true });
|
||||
let item = needDeleteList[delIndex];
|
||||
app.globalData.ppScale.activeProtocol.dataDeleteUser({
|
||||
userID: item.userID,
|
||||
userID: item.id,
|
||||
memberID: ""
|
||||
}, (status) => {
|
||||
if (status == 0) {
|
||||
|
||||
@@ -1,9 +1,141 @@
|
||||
const app = getApp();
|
||||
|
||||
Component({
|
||||
data: {
|
||||
otaProgress: 0,
|
||||
otaStatus: '', // 'upgrading' | 'success' | 'failed' | ''
|
||||
otaMessage: ''
|
||||
},
|
||||
|
||||
methods: {
|
||||
bindOk() {
|
||||
this.triggerEvent('deviceEvent', {
|
||||
status: true
|
||||
});
|
||||
},
|
||||
|
||||
// OTA 升级方法
|
||||
updateOta() {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '确定要进行 OTA 升级吗?升级过程中请保持设备与手机的连接,升级可能需要几分钟时间。',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.startOtaUpgrade();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 开始 OTA 升级
|
||||
startOtaUpgrade() {
|
||||
wx.showLoading({
|
||||
title: '正在升级...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
this.setData({
|
||||
otaProgress: 0,
|
||||
otaStatus: 'upgrading',
|
||||
otaMessage: '升级初始化中...'
|
||||
});
|
||||
|
||||
const activeProtocol = app.globalData.ppScale.activeProtocol;
|
||||
|
||||
if (!activeProtocol) {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '设备未连接,请重新连接',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用蓝牙插件的 OTA 升级接口
|
||||
activeProtocol.codeOtaUpdate((status) => {
|
||||
console.log('OTA 升级状态:', status);
|
||||
|
||||
// status 可能是进度百分比或状态码
|
||||
if (typeof status === 'object') {
|
||||
// 处理进度对象 { progress: 0-100, status: 0/1 }
|
||||
if (status.progress !== undefined) {
|
||||
this.setData({
|
||||
otaProgress: status.progress,
|
||||
otaMessage: `升级进度: ${status.progress}%`
|
||||
});
|
||||
}
|
||||
|
||||
// 升级完成或失败
|
||||
if (status.status === 0) {
|
||||
this.handleOtaSuccess();
|
||||
} else if (status.status === 1) {
|
||||
this.handleOtaFailed();
|
||||
}
|
||||
} else if (typeof status === 'number') {
|
||||
// 处理数字状态码
|
||||
if (status === 0) {
|
||||
this.handleOtaSuccess();
|
||||
} else if (status === 1) {
|
||||
this.handleOtaFailed();
|
||||
} else {
|
||||
// 当作进度百分比处理
|
||||
this.setData({
|
||||
otaProgress: Math.min(status, 100),
|
||||
otaMessage: `升级进度: ${Math.min(status, 100)}%`
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// OTA 升级成功处理
|
||||
handleOtaSuccess() {
|
||||
wx.hideLoading();
|
||||
this.setData({
|
||||
otaProgress: 100,
|
||||
otaStatus: 'success',
|
||||
otaMessage: '升级成功'
|
||||
});
|
||||
|
||||
wx.showToast({
|
||||
title: 'OTA 升级成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
|
||||
// 2秒后重置状态
|
||||
setTimeout(() => {
|
||||
this.setData({
|
||||
otaProgress: 0,
|
||||
otaStatus: '',
|
||||
otaMessage: ''
|
||||
});
|
||||
}, 2000);
|
||||
},
|
||||
|
||||
// OTA 升级失败处理
|
||||
handleOtaFailed() {
|
||||
wx.hideLoading();
|
||||
this.setData({
|
||||
otaProgress: 0,
|
||||
otaStatus: 'failed',
|
||||
otaMessage: '升级失败,请重试'
|
||||
});
|
||||
|
||||
wx.showToast({
|
||||
title: '升级失败,请重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
|
||||
// 2秒后重置状态
|
||||
setTimeout(() => {
|
||||
this.setData({
|
||||
otaProgress: 0,
|
||||
otaStatus: '',
|
||||
otaMessage: ''
|
||||
});
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -8,5 +8,15 @@
|
||||
|
||||
<view class="describe">随时随地同步测量数据</view>
|
||||
|
||||
<!-- OTA 升级进度显示 -->
|
||||
<view wx:if="{{otaStatus}}" class="ota-progress-container">
|
||||
<view class="ota-message">{{otaMessage}}</view>
|
||||
<view class="progress-bar">
|
||||
<view class="progress-fill" style="width: {{otaProgress}}%"></view>
|
||||
</view>
|
||||
<view class="progress-text">{{otaProgress}}%</view>
|
||||
</view>
|
||||
|
||||
<view class="btn" bind:tap="bindOk">完成</view>
|
||||
<view class="ota" bind:tap="updateOta">OTA升级</view>
|
||||
</view>
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
.icon {
|
||||
width: 100%;
|
||||
margin-bottom: 475rpx;
|
||||
margin-bottom: 400rpx;
|
||||
}
|
||||
|
||||
.icon>view:first-of-type {
|
||||
@@ -45,5 +45,58 @@
|
||||
line-height: 88rpx;
|
||||
text-align: center;
|
||||
border-radius: 44rpx;
|
||||
margin-bottom: 45rpx;
|
||||
background-color: #1385FA;
|
||||
}
|
||||
|
||||
.ota {
|
||||
color: #1385FA;
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
line-height: 86rpx;
|
||||
text-align: center;
|
||||
border-radius: 44rpx;
|
||||
box-sizing: border-box;
|
||||
border: 1rpx solid #1385FA;
|
||||
}
|
||||
|
||||
/* OTA 升级进度样式 */
|
||||
.ota-progress-container {
|
||||
width: 100%;
|
||||
margin-bottom: 30rpx;
|
||||
padding: 20rpx;
|
||||
background-color: #F5F5F5;
|
||||
border-radius: 12rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.ota-message {
|
||||
color: #252535;
|
||||
font-size: 28rpx;
|
||||
margin-bottom: 15rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
width: 100%;
|
||||
height: 8rpx;
|
||||
background-color: #E0E0E0;
|
||||
border-radius: 4rpx;
|
||||
overflow: hidden;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background-color: #1385FA;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
color: #1385FA;
|
||||
font-size: 24rpx;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,12 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
wifiChange() {
|
||||
wx.navigateTo({
|
||||
url: "/pages/searchDevice/searchDevice"
|
||||
})
|
||||
},
|
||||
|
||||
starLogin() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.login({
|
||||
|
||||
@@ -13,6 +13,13 @@
|
||||
<view class="content">
|
||||
<view class="service">
|
||||
<view class="title">我的服务</view>
|
||||
<view class="list arrowAfter" bind:tap="wifiChange">
|
||||
<view>
|
||||
<image src="/images/my/1.png" />
|
||||
</view>
|
||||
<view>更换网络</view>
|
||||
<view></view>
|
||||
</view>
|
||||
<view class="list arrowAfter">
|
||||
<view>
|
||||
<image src="/images/my/3.png" />
|
||||
|
||||
Reference in New Issue
Block a user