完成”绑定设备“功能

This commit is contained in:
CGD
2025-03-27 17:54:05 +08:00
parent 5bfc3efc9c
commit 3ca06f8d50
3 changed files with 74 additions and 26 deletions
@@ -33,16 +33,49 @@
export default {
name: 'AddDeviceDialog',
props: {
visible: { type: Boolean, required: true }
visible: { type: Boolean, required: true },
agentId: { type: String, required: true }
},
data() {
return { deviceCode: "" }
return {
deviceCode: "",
loading: false,
}
},
methods: {
confirm() {
this.$emit('update:visible', false)
this.$emit('added', this.deviceCode)
this.deviceCode = ""
// console.log(this.agentId)
// console.log("=========")
// console.log(this.$route.query.agentId)
if (!/^\d{6}$/.test(this.deviceCode)) {
this.$message.error('请输入6位数字验证码');
return;
}
this.loading = true;
import('@/apis/module/user').then(({ default: userApi }) => {
userApi.bindDevice(
this.agentId,
this.deviceCode, ({data}) => {
this.loading = false;
if (data.code === 0) {
this.$emit('refresh');
this.$message.success('设备绑定成功');
this.closeDialog();
} else {
this.$message.error(data.msg || '绑定失败');
}
}
);
}).catch((err) => {
this.loading = false;
console.error('API模块加载失败:', err);
this.$message.error('绑定服务不可用');
});
},
closeDialog() {
this.$emit('update:visible', false);
this.deviceCode = '';
},
cancel() {
this.$emit('update:visible', false)