[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
+3 -30
View File
@@ -3,22 +3,14 @@ import $ from "../../utils/request";
Page({
data: {
token: null,
userInfo: null,
deviceList: []
},
onShow() {
let userInfo = wx.getStorageSync("userInfo") || null;
let token = wx.getStorageSync("token") || null;
this.setData({
token: token,
userInfo: userInfo,
deviceList: []
// deviceList: []
})
if(token) {
this.getDevice();
}
},
// 点击登录或注册
@@ -43,12 +35,10 @@ Page({
let params = {
code: 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
token: res.result.token
})
if(bol) {
@@ -57,27 +47,10 @@ Page({
})
},
// 获取已经绑定的设备列表
getDevice() {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", true, "获取设备列表").then((res) => {
this.setData({
deviceList: res.result
})
})
},
// 添加设备
openSearchDevice() {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
},
// 打开设备详情
openDeviceInfo() {
wx.navigateTo({
url: "/pages/deviceInfo/deviceInfo"
})
}
})
+12 -22
View File
@@ -8,8 +8,8 @@
<view>
<image src="/images/home/user.png" />
</view>
<block wx:if="{{userInfo || token}}">
<view>{{userInfo ? userInfo.realname : '已登录'}}</view>
<block wx:if="{{token}}">
<view>已登录</view>
</block>
<block wx:else>
<view class="arrowAfter" data-bol="{{false}}" bind:tap="openLoginOrReg">登录/注册</view>
@@ -19,24 +19,14 @@
<view>注重更好的健康生活品质</view>
<view></view>
</view>
<block wx:if="{{deviceList && deviceList.length}}">
<view class="device" bind:tap="openDeviceInfo">
<view>
<image src="/images/devices/{{deviceList[0].type}}.png" />
</view>
<view>设备名称:{{deviceList[0].equipmentName}}</view>
</view>
</block>
<block wx:else>
<view class="addDevice">
<view>请添加设备</view>
<view>添加设备后,解锁更多体验</view>
<block wx:if="{{userInfo && token}}">
<view bind:tap="openSearchDevice">添加设备</view>
</block>
<block wx:else>
<view data-bol="{{true}}" bind:tap="openLoginOrReg">添加设备</view>
</block>
</view>
</block>
<view class="addDevice">
<view>请添加设备</view>
<view>添加设备后,解锁更多体验</view>
<block wx:if="{{token}}">
<view bind:tap="openSearchDevice">添加设备</view>
</block>
<block wx:else>
<view data-bol="{{true}}" bind:tap="openLoginOrReg">添加设备</view>
</block>
</view>
</view>
-20
View File
@@ -79,26 +79,6 @@
background-color: #FFFFFF;
}
.device {
width: 100%;
}
.device>view:nth-of-type(1) {
width: 500rpx;
height: 500rpx;
margin: 0 auto 16rpx;
}
.device>view:nth-of-type(2) {
color: #ffffff;
width: 100%;
height: 32rpx;
font-weight: bold;
font-size: 32rpx;
line-height: 32rpx;
text-align: center;
}
.addDevice {
width: 580rpx;
margin: 0 auto;