diff --git a/main/manager-web/src/apis/module/user.js b/main/manager-web/src/apis/module/user.js index 88a77623..66fefdbc 100755 --- a/main/manager-web/src/apis/module/user.js +++ b/main/manager-web/src/apis/module/user.js @@ -5,7 +5,8 @@ import {getServiceUrl} from '../api' export default { // 登录 login(loginForm, callback) { - RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/login`) + RequestService.sendRequest() + .url(`${getServiceUrl()}/api/v1/user/login`) .method('POST') .data(loginForm) .success((res) => { @@ -40,7 +41,9 @@ export default { }, // 注册账号 register(registerForm, callback) { - RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/register`).method('POST') + RequestService.sendRequest() + .url(`${getServiceUrl()}/api/v1/user/register`) + .method('POST') .data(registerForm) .success((res) => { RequestService.clearRequestTime() @@ -132,11 +135,11 @@ export default { // 修改用户密码 changePassword(oldPassword, newPassword, successCallback, errorCallback) { RequestService.sendRequest() - .url(`${getServiceUrl()}/api/v1/user/change-password`) // 修改URL - .method('PUT') // 修改方法为PUT + .url(`${getServiceUrl()}/api/v1/user/change-password`) + .method('PUT') .data({ - old_password: oldPassword, // 修改参数名 - new_password: newPassword // 修改参数名 + old_password: oldPassword, + new_password: newPassword, }) .success((res) => { RequestService.clearRequestTime(); @@ -183,6 +186,7 @@ export default { }, // 已绑设备 getAgentBindDevices(agentId, callback) { + console.log("77777777777777777777777") RequestService.sendRequest() .url(`${getServiceUrl()}/api/v1/user/agent/device/bind/${agentId}`) .method('GET') @@ -197,4 +201,38 @@ export default { }); }).send(); }, + // 解绑设备 + unbindDevice(device_id, callback) { + RequestService.sendRequest() + .url(`${getServiceUrl()}/api/v1/user/device/unbind/${device_id}`) + .method('PUT') + .success((res) => { + RequestService.clearRequestTime(); + callback(res); + }) + .fail((err) => { + console.error('解绑设备失败:', err); + RequestService.reAjaxFun(() => { + this.unbindDevice(device_id, callback); + }); + }).send(); + }, + // 绑定设备 + bindDevice(agentId, code, callback) { + console.log("32323234343434344340000") + RequestService.sendRequest() + .url(`${getServiceUrl()}/api/v1/user/agent/device/bind/${agentId}`) + .method('POST') + .data({ code }) + .success((res) => { + RequestService.clearRequestTime(); + callback(res); + }) + .fail((err) => { + // console.error('绑定设备失败:', err); + // RequestService.reAjaxFun(() => { + // this.bindDevice(agentId, code, callback); + // }); + }).send(); + }, } diff --git a/main/manager-web/src/components/AddDeviceDialog.vue b/main/manager-web/src/components/AddDeviceDialog.vue index e7ba492e..6c99a038 100644 --- a/main/manager-web/src/components/AddDeviceDialog.vue +++ b/main/manager-web/src/components/AddDeviceDialog.vue @@ -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) diff --git a/main/manager-web/src/views/DeviceManagement.vue b/main/manager-web/src/views/DeviceManagement.vue index 9135a3e6..2e853f17 100644 --- a/main/manager-web/src/views/DeviceManagement.vue +++ b/main/manager-web/src/views/DeviceManagement.vue @@ -31,7 +31,7 @@ @@ -51,7 +51,7 @@
©2025 xiaozhi-esp32-server
- + @@ -59,16 +59,17 @@