[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:
17792275749
2026-03-10 14:32:47 +08:00
co-authored by Claude Opus 4.6
parent 1e3f1934b1
commit e20638030b
27 changed files with 775 additions and 1646 deletions
+6 -89
View File
@@ -2,93 +2,25 @@ import $ from "../../utils/request";
Page({
data: {
userInfo: null,
token: null,
deviceInfo: null
token: null
},
onShow() {
let token = wx.getStorageSync("token") || null;
let userInfo = wx.getStorageSync("userInfo") || null;
this.setData({
userInfo: userInfo,
token: token
})
if(token) {
this.getDevice(false);
}
},
openLoginOrReg() {
if(this.data.token) {
this.openLoginOrReg_();
} else {
if (!this.data.token) {
this.starLogin().then(() => {
this.getDevice(true);
}).catch(() => {
wx.showToast({
title: "登录失败,请重试!",
icon: "none"
})
})
}
},
openLoginOrReg_() {
let deviceInfo = this.data.deviceInfo;
if(deviceInfo) {
wx.navigateTo({
url: "/pages/userInfo/userInfo"
})
} else {
wx.showModal({
title: "提示",
content: "当前用户暂未绑定设备,需要绑定吗?",
confirmText: "去绑定",
success: (res) => {
if (res.confirm) {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
}
}
})
}
},
// 打开设备详情
openDeviceInfo() {
if(this.data.token) {
this.openDeviceInfo_();
} else {
this.starLogin().then(() => {
this.openDeviceInfo_();
}).catch(() => {
wx.showToast({
title: "登录失败,请重试!",
icon: "none"
})
})
}
},
openDeviceInfo_ () {
let deviceInfo = this.data.deviceInfo;
if(deviceInfo) {
wx.navigateTo({
url: "/pages/deviceInfo/deviceInfo"
})
} else {
wx.showModal({
title: "提示",
content: "当前暂未绑定设备,需要绑定吗?",
confirmText: "去绑定",
success: (res) => {
if (res.confirm) {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
}
}
title: "登录失败,请重试!",
icon: "none"
})
})
}
},
@@ -101,12 +33,10 @@ Page({
let params = {
code: res.code
};
$.ajax("weighingScale/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => {
wx.setStorageSync("userInfo", res.result.user);
$.ajax("weighingScale/v2/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => {
wx.setStorageSync("token", res.result.token);
this.setData({
token: res.result.token,
userInfo: res.result.user
})
resolve();
}).catch((err) => {
@@ -120,19 +50,6 @@ Page({
})
},
// 获取已经绑定的设备列表
getDevice(bol) {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", false).then((res) => {
this.setData({
deviceInfo: res.result && res.result.length ? res.result[0] : null
})
if(bol) {
this.openLoginOrReg_();
}
})
},
// 退出登录
exitLogin() {
wx.showModal({
+2 -27
View File
@@ -1,43 +1,18 @@
<view class="userInfo">
<view class="user {{userInfo || token ? 'arrowAfter' : ''}}" bind:tap="openLoginOrReg">
<view class="user" bind:tap="openLoginOrReg">
<view>
<image src="/images/my/user.png" />
</view>
<view>
<block wx:if="{{userInfo || token}}">
{{userInfo ? userInfo.realname : '已登录'}}
</block>
<block wx:if="{{token}}">已登录</block>
<block wx:else>未登录</block>
</view>
</view>
<view class="info">
<view>
<view>身高(cm)</view>
<view>{{userInfo && userInfo.height ? userInfo.height : '--'}}</view>
</view>
<view></view>
<view>
<view>体重(kg)</view>
<view>{{userInfo && userInfo.weight ? userInfo.weight : '--'}}</view>
</view>
<view></view>
<view>
<view>BMI</view>
<view>{{userInfo && userInfo.bmi ? userInfo.bmi : '--'}}</view>
</view>
</view>
</view>
<view class="content">
<view class="service">
<view class="title">我的服务</view>
<view class="list arrowAfter" bind:tap="openDeviceInfo">
<view>
<image src="/images/my/1.png" />
</view>
<view>设备绑定</view>
<view>{{deviceInfo ? '已绑定('+ deviceInfo.equipmentName +')' : '未绑定'}}</view>
</view>
<view class="list arrowAfter">
<view>
<image src="/images/my/3.png" />
+5 -3
View File
@@ -1,6 +1,6 @@
.userInfo {
width: 100%;
height: 488rpx;
/* height: 488rpx; */
margin-bottom: 24rpx;
box-sizing: border-box;
padding: 185rpx 40rpx 0;
@@ -12,7 +12,8 @@
height: 136rpx;
display: flex;
flex-wrap: nowrap;
margin-bottom: 46rpx;
padding-bottom: 23px;
/* margin-bottom: 46rpx; */
}
.user>view:first-of-type {
@@ -75,7 +76,8 @@
width: 100%;
padding: 0 30rpx;
box-sizing: border-box;
margin-bottom: 480rpx;
margin-bottom: 600rpx;
/* margin-bottom: 480rpx; */
}
.content .arrowAfter::after {