完成“解绑设备”

This commit is contained in:
CGD
2025-03-27 11:24:49 +08:00
parent 5c536e72df
commit 5bfc3efc9c
2 changed files with 55 additions and 14 deletions
+26 -6
View File
@@ -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();
@@ -197,4 +200,21 @@ 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();
}
}
@@ -31,7 +31,7 @@
</el-table-column>
<el-table-column label="操作" width="80">
<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>
</template>
@@ -59,7 +59,7 @@
<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() {
@@ -69,6 +69,7 @@ export default {
pageSize: 5,
deviceList: [],
loading: false,
userApi: null,
};
},
computed: {
@@ -80,9 +81,12 @@ export default {
},
mounted() {
const agentId = this.$route.query.agentId;
if (agentId) {
this.fetchBindDevices(agentId);
}
import('@/apis/module/user').then(({ default: userApi }) => {
this.userApi = userApi;
if (agentId) {
this.fetchBindDevices(agentId);
}
});
},
methods: {
handleAddDevice() {
@@ -94,8 +98,25 @@ export default {
stopEditRemark(index) {
this.deviceList[index].isEdit = false;
},
handleUnbind(device) {
console.log('解绑设备', device);
handleUnbind(device_id) {
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) {
console.log('添加的智能体名称:', deviceCode);
@@ -113,7 +134,7 @@ export default {
this.loading = false;
if (data.code === 0) {
this.deviceList = data.data[0]?.list.map(device => ({
id: device.id,
device_id: device.id,
model: device.device_type,
firmwareVersion: device.app_version,
macAddress: device.mac_address,