mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 17:13:54 +08:00
完成“解绑设备”
This commit is contained in:
@@ -5,7 +5,8 @@ import {getServiceUrl} from '../api'
|
|||||||
export default {
|
export default {
|
||||||
// 登录
|
// 登录
|
||||||
login(loginForm, callback) {
|
login(loginForm, callback) {
|
||||||
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/login`)
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/user/login`)
|
||||||
.method('POST')
|
.method('POST')
|
||||||
.data(loginForm)
|
.data(loginForm)
|
||||||
.success((res) => {
|
.success((res) => {
|
||||||
@@ -40,7 +41,9 @@ export default {
|
|||||||
},
|
},
|
||||||
// 注册账号
|
// 注册账号
|
||||||
register(registerForm, callback) {
|
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)
|
.data(registerForm)
|
||||||
.success((res) => {
|
.success((res) => {
|
||||||
RequestService.clearRequestTime()
|
RequestService.clearRequestTime()
|
||||||
@@ -132,11 +135,11 @@ export default {
|
|||||||
// 修改用户密码
|
// 修改用户密码
|
||||||
changePassword(oldPassword, newPassword, successCallback, errorCallback) {
|
changePassword(oldPassword, newPassword, successCallback, errorCallback) {
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
.url(`${getServiceUrl()}/api/v1/user/change-password`) // 修改URL
|
.url(`${getServiceUrl()}/api/v1/user/change-password`)
|
||||||
.method('PUT') // 修改方法为PUT
|
.method('PUT')
|
||||||
.data({
|
.data({
|
||||||
old_password: oldPassword, // 修改参数名
|
old_password: oldPassword,
|
||||||
new_password: newPassword // 修改参数名
|
new_password: newPassword,
|
||||||
})
|
})
|
||||||
.success((res) => {
|
.success((res) => {
|
||||||
RequestService.clearRequestTime();
|
RequestService.clearRequestTime();
|
||||||
@@ -197,4 +200,21 @@ export default {
|
|||||||
});
|
});
|
||||||
}).send();
|
}).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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" width="80">
|
<el-table-column label="操作" width="80">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button size="mini" type="text" @click="handleUnbind(scope.row)" style="color: #ff4949">
|
<el-button size="mini" type="text" @click="handleUnbind(scope.row.device_id)" style="color: #ff4949">
|
||||||
解绑
|
解绑
|
||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import HeaderBar from "@/components/HeaderBar.vue";
|
import HeaderBar from "@/components/HeaderBar.vue";
|
||||||
import AddDeviceDialog from "@/components/AddDeviceDialog.vue";
|
import AddDeviceDialog from "@/components/AddDeviceDialog.vue";
|
||||||
|
import { userApi } from '@/apis/module/user';
|
||||||
export default {
|
export default {
|
||||||
components: {HeaderBar, AddDeviceDialog },
|
components: {HeaderBar, AddDeviceDialog },
|
||||||
data() {
|
data() {
|
||||||
@@ -69,6 +69,7 @@ export default {
|
|||||||
pageSize: 5,
|
pageSize: 5,
|
||||||
deviceList: [],
|
deviceList: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
|
userApi: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -80,9 +81,12 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const agentId = this.$route.query.agentId;
|
const agentId = this.$route.query.agentId;
|
||||||
if (agentId) {
|
import('@/apis/module/user').then(({ default: userApi }) => {
|
||||||
this.fetchBindDevices(agentId);
|
this.userApi = userApi;
|
||||||
}
|
if (agentId) {
|
||||||
|
this.fetchBindDevices(agentId);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleAddDevice() {
|
handleAddDevice() {
|
||||||
@@ -94,8 +98,25 @@ export default {
|
|||||||
stopEditRemark(index) {
|
stopEditRemark(index) {
|
||||||
this.deviceList[index].isEdit = false;
|
this.deviceList[index].isEdit = false;
|
||||||
},
|
},
|
||||||
handleUnbind(device) {
|
handleUnbind(device_id) {
|
||||||
console.log('解绑设备', device);
|
if (!this.userApi) {
|
||||||
|
this.$message.error('功能模块加载失败');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.$confirm('确认要解绑该设备吗?', '警告', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
this.userApi.unbindDevice(device_id, ({ data }) => {
|
||||||
|
if (data.code === 0) {
|
||||||
|
this.$message.success('设备解绑成功');
|
||||||
|
this.fetchBindDevices(this.$route.query.agentId);
|
||||||
|
} else {
|
||||||
|
this.$message.error(data.msg || '设备解绑失败');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
handleDeviceAdded(deviceCode) {
|
handleDeviceAdded(deviceCode) {
|
||||||
console.log('添加的智能体名称:', deviceCode);
|
console.log('添加的智能体名称:', deviceCode);
|
||||||
@@ -113,7 +134,7 @@ export default {
|
|||||||
this.loading = false;
|
this.loading = false;
|
||||||
if (data.code === 0) {
|
if (data.code === 0) {
|
||||||
this.deviceList = data.data[0]?.list.map(device => ({
|
this.deviceList = data.data[0]?.list.map(device => ({
|
||||||
id: device.id,
|
device_id: device.id,
|
||||||
model: device.device_type,
|
model: device.device_type,
|
||||||
firmwareVersion: device.app_version,
|
firmwareVersion: device.app_version,
|
||||||
macAddress: device.mac_address,
|
macAddress: device.mac_address,
|
||||||
|
|||||||
Reference in New Issue
Block a user