[AI Generated]: refactor(*): 重构用户初始化流程,接口化用户管理并支持增量下发设备
- 重构 configureDevice 步骤0:新增双条件控制(deviceInfo + codeSyncTime),确保连接完成且 mac 就绪后才进入下一步 - 重构 configureDevice_2:移除 userInfo 缓存读取,改为接口获取用户列表,支持动态渲染、删除用户 - 新增 configureDevice_2_addUser 组件:支持工号查询用户信息并添加到设备 - 优化用户下发逻辑:先通过 dataFetchUserID 获取设备端已有用户,仅下发新增用户 - 删除废弃页面 deviceInfo、userInfo Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1e3f1934b1
commit
e20638030b
@@ -28,6 +28,8 @@ Page({
|
||||
ppScale.plugin.bus.subscribe("deviceInfo", (res) => {
|
||||
console.log("===》deviceInfo", res);
|
||||
ppScale.device.mac = res.serialNumber;
|
||||
this._macReady = true;
|
||||
this._tryProgress();
|
||||
});
|
||||
|
||||
ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
|
||||
@@ -59,99 +61,20 @@ Page({
|
||||
return;
|
||||
}
|
||||
|
||||
// 步骤 0:首次连接设备,走完整的绑定检查链路
|
||||
// 步骤 0:首次连接设备
|
||||
ppScale.activeProtocol.codeUpdateMTU((res) => {
|
||||
console.log("===》codeUpdateMTU", res);
|
||||
|
||||
ppScale.activeProtocol.codeFetchBindingState((res) => {
|
||||
console.log("===》codeFetchBindingState", res);
|
||||
ppScale.activeProtocol.codeSyncTime((codeSyncTime) => {
|
||||
console.log("===》codeSyncTime", codeSyncTime)
|
||||
|
||||
ppScale.activeProtocol.codeSyncTime((codeSyncTime) => {
|
||||
console.log("===》codeSyncTime", codeSyncTime)
|
||||
|
||||
wx.hideLoading();
|
||||
if (res === 1) {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '当前设备已被绑定,你确定要覆盖绑定吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.showLoading({
|
||||
title: "正在初始化设备...",
|
||||
mask: true
|
||||
});
|
||||
ppScale.activeProtocol.codeClearDeviceData("00", (res) => {
|
||||
console.log("deviceInfo === codeClearDeviceData", res);
|
||||
wx.hideLoading();
|
||||
|
||||
if (res === 0) {
|
||||
let scaleDeviceId = ppScale.device.mac.replace(/:/g, '');
|
||||
let params = {
|
||||
equipmentCode: scaleDeviceId,
|
||||
};
|
||||
$.ajax("weighingScale/del/device", params, "POST", true, "正在初始化设备...").then(res => {
|
||||
ppScale.plugin.Blue.stop();
|
||||
wx.showToast({
|
||||
icon: "none",
|
||||
title: "设备初始化成功,请重新绑定。",
|
||||
})
|
||||
setTimeout(() => {
|
||||
wx.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
}, 1500);
|
||||
});
|
||||
} else {
|
||||
ppScale.plugin.Blue.stop();
|
||||
wx.showToast({
|
||||
icon: "none",
|
||||
title: "设备初始化失败。",
|
||||
})
|
||||
}
|
||||
})
|
||||
} else if (res.cancel) {
|
||||
ppScale.plugin.Blue.stop();
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
ppScale.device.name = this.data.device.name;
|
||||
ppScale.device.connection = this.data.device;
|
||||
const nameArr = this.data.device.name.split("-");
|
||||
ppScale.version = nameArr.length === 5 ? "domain2" : "domain1";
|
||||
if (this.data.progressNext) {
|
||||
// 立即重置,防止最小化后重连时重复推进进度
|
||||
this.setData({ progressNext: false });
|
||||
let scaleDeviceId = ppScale.device.mac.replace(/:/g, '');
|
||||
let params = {
|
||||
sn: scaleDeviceId,
|
||||
};
|
||||
$.ajax("weighingScale/getUserInfoBySn", params, "GET", true, "正在同步用户信息...").then(res => {
|
||||
if (res.result) {
|
||||
wx.setStorageSync("userInfo", res.result);
|
||||
this.setProgress();
|
||||
} else {
|
||||
wx.removeStorageSync("userInfo");
|
||||
wx.showToast({
|
||||
title: "暂无用户信息,请手动补充",
|
||||
icon: "none"
|
||||
})
|
||||
setTimeout(() => {
|
||||
this.setProgress();
|
||||
}, 1500)
|
||||
}
|
||||
}).catch(() => {
|
||||
wx.showToast({
|
||||
title: "用户信息同步失败,请手动补充",
|
||||
icon: "none"
|
||||
})
|
||||
setTimeout(() => {
|
||||
this.setProgress();
|
||||
}, 1500)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
wx.hideLoading();
|
||||
ppScale.device.name = this.data.device.name;
|
||||
ppScale.device.connection = this.data.device;
|
||||
const nameArr = this.data.device.name.split("-");
|
||||
ppScale.version = nameArr.length === 5 ? "domain2" : "domain1";
|
||||
this._connectReady = true;
|
||||
this._tryProgress();
|
||||
})
|
||||
});
|
||||
});
|
||||
@@ -214,7 +137,7 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
setDeviceUserInfo(e) {
|
||||
setDeviceUserList(e) {
|
||||
let status = e.detail.status;
|
||||
if (status) {
|
||||
this.setProgress();
|
||||
@@ -241,6 +164,18 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
// 连接完成 + mac 获取完成,双条件满足后才进入下一步
|
||||
_connectReady: false,
|
||||
_macReady: false,
|
||||
_tryProgress() {
|
||||
if (this._connectReady && this._macReady && this.data.progressNext) {
|
||||
this._connectReady = false;
|
||||
this._macReady = false;
|
||||
this.setData({ progressNext: false });
|
||||
this.setProgress();
|
||||
}
|
||||
},
|
||||
|
||||
checkBluetoothPermissionAndInit() {
|
||||
wx.getSetting({
|
||||
success: (res) => {
|
||||
@@ -313,6 +248,8 @@ Page({
|
||||
}
|
||||
app.resetReconnectCount();
|
||||
app.setGlobalData('ppScale.device.connectState', null);
|
||||
this._connectReady = false;
|
||||
this._macReady = false;
|
||||
ppScale.plugin.Blue.stop();
|
||||
},
|
||||
|
||||
@@ -320,6 +257,8 @@ Page({
|
||||
console.log("configureDevice onUnload");
|
||||
app.resetReconnectCount();
|
||||
app.setGlobalData('ppScale.device.connectState', null);
|
||||
this._connectReady = false;
|
||||
this._macReady = false;
|
||||
ppScale.plugin.Blue.stop();
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user