mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
完成”绑定设备“功能
This commit is contained in:
@@ -186,6 +186,7 @@ export default {
|
||||
},
|
||||
// 已绑设备
|
||||
getAgentBindDevices(agentId, callback) {
|
||||
console.log("77777777777777777777777")
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/agent/device/bind/${agentId}`)
|
||||
.method('GET')
|
||||
@@ -202,19 +203,36 @@ export default {
|
||||
},
|
||||
// 解绑设备
|
||||
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();
|
||||
}
|
||||
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();
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<div style="font-size: 12px; font-weight: 400; margin-top: auto; padding-top: 30px; color: #979db1;">
|
||||
©2025 xiaozhi-esp32-server
|
||||
</div>
|
||||
<AddDeviceDialog :visible.sync="addDeviceDialogVisible" @added="handleDeviceAdded" />
|
||||
<AddDeviceDialog :visible.sync="addDeviceDialogVisible" :agent-id="currentAgentId" @refresh="fetchBindDevices(currentAgentId)" />
|
||||
</el-main>
|
||||
</div>
|
||||
</template>
|
||||
@@ -59,12 +59,12 @@
|
||||
<script>
|
||||
import HeaderBar from "@/components/HeaderBar.vue";
|
||||
import AddDeviceDialog from "@/components/AddDeviceDialog.vue";
|
||||
import { userApi } from '@/apis/module/user';
|
||||
export default {
|
||||
components: {HeaderBar, AddDeviceDialog },
|
||||
data() {
|
||||
return {
|
||||
addDeviceDialogVisible: false,
|
||||
currentAgentId: this.$route.query.agentId || '',
|
||||
currentPage: 1,
|
||||
pageSize: 5,
|
||||
deviceList: [],
|
||||
@@ -118,9 +118,6 @@ export default {
|
||||
});
|
||||
});
|
||||
},
|
||||
handleDeviceAdded(deviceCode) {
|
||||
console.log('添加的智能体名称:', deviceCode);
|
||||
},
|
||||
handleSizeChange(val) {
|
||||
this.pageSize = val;
|
||||
},
|
||||
@@ -133,7 +130,7 @@ export default {
|
||||
userApi.getAgentBindDevices(agentId, ({ data }) => {
|
||||
this.loading = false;
|
||||
if (data.code === 0) {
|
||||
this.deviceList = data.data[0]?.list.map(device => ({
|
||||
this.deviceList = data.data[0].list.map(device => ({
|
||||
device_id: device.id,
|
||||
model: device.device_type,
|
||||
firmwareVersion: device.app_version,
|
||||
|
||||
Reference in New Issue
Block a user