Files
bodyWeight/pages/my/my.js
T
17792275749andClaude Opus 4.6 e20638030b [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>
2026-03-10 14:32:47 +08:00

76 lines
1.8 KiB
JavaScript

import $ from "../../utils/request";
Page({
data: {
token: null
},
onShow() {
let token = wx.getStorageSync("token") || null;
this.setData({
token: token
})
},
openLoginOrReg() {
if (!this.data.token) {
this.starLogin().then(() => {
}).catch(() => {
wx.showToast({
title: "登录失败,请重试!",
icon: "none"
})
})
}
},
starLogin() {
return new Promise((resolve, reject) => {
wx.login({
success: (res) => {
if (res.code) {
let params = {
code: res.code
};
$.ajax("weighingScale/v2/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => {
wx.setStorageSync("token", res.result.token);
this.setData({
token: res.result.token,
})
resolve();
}).catch((err) => {
reject();
})
} else {
reject();
}
}
})
})
},
// 退出登录
exitLogin() {
wx.showModal({
title: "提示",
content: "你确定要退出登录吗?",
success: (res) => {
if (res.confirm) {
$.ajax("weighingScale/logout", {}, "POST", true, "正在退出登录...").then(res => {
wx.showToast({
icon: "none",
title: res.message
})
setTimeout(() => {
wx.clearStorageSync();
wx.switchTab({
url: "/pages/home/home"
})
}, 1500)
})
}
}
})
}
})