- 重构 configureDevice 步骤0:新增双条件控制(deviceInfo + codeSyncTime),确保连接完成且 mac 就绪后才进入下一步 - 重构 configureDevice_2:移除 userInfo 缓存读取,改为接口获取用户列表,支持动态渲染、删除用户 - 新增 configureDevice_2_addUser 组件:支持工号查询用户信息并添加到设备 - 优化用户下发逻辑:先通过 dataFetchUserID 获取设备端已有用户,仅下发新增用户 - 删除废弃页面 deviceInfo、userInfo Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
145 lines
4.1 KiB
JavaScript
145 lines
4.1 KiB
JavaScript
import $ from "../../utils/request";
|
|
const app = getApp();
|
|
|
|
Component({
|
|
properties: {
|
|
|
|
},
|
|
data: {
|
|
animationData: null,
|
|
modalStatus: false,
|
|
workNo: "",
|
|
userInfo: null,
|
|
},
|
|
lifetimes: {
|
|
// 在组件实例进入页面节点树时执行
|
|
attached() {
|
|
|
|
},
|
|
|
|
// 在组件实例被从页面节点树移除时执行
|
|
detached() {
|
|
|
|
},
|
|
},
|
|
methods: {
|
|
// 显示对话框
|
|
showModal() {
|
|
// 显示遮罩层
|
|
let animation = wx.createAnimation({
|
|
duration: 200,
|
|
timingFunction: "linear",
|
|
delay: 0
|
|
})
|
|
this.animation = animation;
|
|
animation.translateY(1100).step();
|
|
this.setData({
|
|
animationData: animation.export(),
|
|
modalStatus: true
|
|
})
|
|
setTimeout(() => {
|
|
animation.translateY(0).step();
|
|
this.setData({
|
|
animationData: animation.export()
|
|
})
|
|
}, 200);
|
|
},
|
|
|
|
//隐藏对话框
|
|
hideModal() {
|
|
// 隐藏遮罩层
|
|
let animation = wx.createAnimation({
|
|
duration: 200,
|
|
timingFunction: "linear",
|
|
delay: 0
|
|
})
|
|
this.animation = animation;
|
|
animation.translateY(1100).step();
|
|
this.setData({
|
|
animationData: animation.export(),
|
|
})
|
|
setTimeout(() => {
|
|
animation.translateY(0).step();
|
|
this.setData({
|
|
animationData: animation.export(),
|
|
modalStatus: false
|
|
})
|
|
}, 200);
|
|
},
|
|
|
|
// 关闭弹窗并重置数据
|
|
closeModal() {
|
|
this.setData({
|
|
workNo: "",
|
|
userInfo: null,
|
|
});
|
|
this.hideModal();
|
|
},
|
|
|
|
// 监听工号输入
|
|
onWorkNoInput(e) {
|
|
this.setData({ workNo: e.detail.value });
|
|
},
|
|
|
|
// 根据工号查询用户信息
|
|
searchUser() {
|
|
let workNo = this.data.workNo.trim();
|
|
if (!workNo) {
|
|
wx.showToast({
|
|
title: "请输入工号",
|
|
icon: "none"
|
|
})
|
|
return;
|
|
}
|
|
$.ajax("weighingScale/v2/getUserInfoByWkno", { workNo }, "GET", true, "正在查询...").then(res => {
|
|
if (res.result) {
|
|
this.setData({ userInfo: res.result });
|
|
} else {
|
|
this.setData({ userInfo: null });
|
|
wx.showToast({
|
|
title: "未查询到该工号的用户信息",
|
|
icon: "none"
|
|
})
|
|
}
|
|
}).catch(() => {
|
|
wx.showToast({
|
|
title: "查询失败,请重试",
|
|
icon: "none"
|
|
})
|
|
})
|
|
},
|
|
|
|
// 确定提交
|
|
submit() {
|
|
if (!this.data.userInfo) {
|
|
wx.showToast({
|
|
title: "请先查询用户信息",
|
|
icon: "none"
|
|
})
|
|
return;
|
|
}
|
|
let sn = app.globalData.ppScale.device.mac.replace(/:/g, '');
|
|
let user = this.data.userInfo;
|
|
$.ajax("weighingScale/v2/edit/user", {
|
|
sn,
|
|
realname: user.realname,
|
|
sex: user.sex,
|
|
birthday: user.birthday,
|
|
height: user.height,
|
|
weight: user.weight
|
|
}, "POST", true, "正在添加...").then(res => {
|
|
wx.showToast({
|
|
title: "添加成功",
|
|
icon: "success"
|
|
})
|
|
this.triggerEvent('returnDate', { userInfo: user });
|
|
this.closeModal();
|
|
}).catch(() => {
|
|
wx.showToast({
|
|
title: "添加失败,请重试",
|
|
icon: "none"
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}); |