diff --git a/src/api/device.js b/src/api/device.js
index 7017a2e..b45e29c 100644
--- a/src/api/device.js
+++ b/src/api/device.js
@@ -16,12 +16,20 @@ export const updateDeviceService = (data) => {
return request.post('/device/update_device', params, { "headers": { 'token': data.token } });
}
+export const deleteDeviceService = (data) => {
+ const params = new URLSearchParams();
+ for (let key in data) {
+ params.append(key, data[key])
+ }
+ return request.post('/device/delete_device', params, { "headers": { 'token': data.token } });
+}
+
export const addDeviceService = (data) => {
const params = new URLSearchParams();
for (let key in data) {
params.append(key, data[key])
}
- return request.post('/device/add_device', params, { "headers": { 'token': data.token } });
+ return request.post('/device/add_device', params, { "headers": { 'token': data.token },'Content-Type': 'application/json' });
}
export const getDeviceListService = (data) => {
diff --git a/src/views/DeviceList.vue b/src/views/DeviceList.vue
index 6bad8e6..580f17b 100644
--- a/src/views/DeviceList.vue
+++ b/src/views/DeviceList.vue
@@ -4,6 +4,8 @@ import { inject } from "vue";
import { getDeviceListService } from "@/api/device.js";
import { restartDeviceService } from "@/api/device.js";
import { addDeviceService } from "@/api/device.js";
+import { deleteDeviceService } from "@/api/device.js";
+import { updateDeviceService } from "@/api/device.js";
import router from "@/router/index.js";
export default {
@@ -18,6 +20,7 @@ export default {
username: localStorage.getItem("username"),
},
addDialogVisible: false,
+ updateDialogVisible: false,
searchForm: {
hour: 0,
entrydate: [],
@@ -32,6 +35,17 @@ export default {
auth_id: -1,
token: localStorage.getItem("token"),
},
+ updateForm: {
+ id:0,
+ device_name: "",
+ device_ip: "",
+ device_status: "",
+ device_info: "",
+ device_location: "",
+ device_type: "",
+ auth_id: -1,
+ token: localStorage.getItem("token"),
+ },
};
},
@@ -87,18 +101,65 @@ export default {
console.log(e);
}
},
+ async deleteDevice(index) {
+ var id = this.tableData[index].ID;
+ var delete_data = {
+ id: id,
+ userId: this.tokenData.userId,
+ token: this.tokenData.token,
+ };
+ try {
+ var d_re = await deleteDeviceService(delete_data);
+ if (d_re.code == 0) {
+ alert("删除成功");
+ //刷新页面
+ this.getDeviceList();
+ } else {
+ alert("操作失败");
+ }
+ } catch (e) {
+ console.log(e);
+ }
+ },
+ async updateButtonDevice(index) {
+ var id = this.tableData[index].ID;
+ this.updateForm.device_name = this.tableData[index].DeviceName;
+ this.updateForm.device_ip = this.tableData[index].DeviceIP;
+ this.updateForm.device_status = this.tableData[index].DeviceStatus;
+ this.updateForm.device_info = this.tableData[index].DeviceInfo;
+ this.updateForm.device_location = this.tableData[index].DeviceLocation;
+ this.updateForm.device_type = this.tableData[index].DeviceType;
+ this.updateForm.auth_id = this.tableData[index].AuthID;
+ this.updateForm.id = id;
+ this.updateDialogVisible= true;
+ },
async addDevice() {
- this.addDialogVisible = true;
- let result ={}
- try{
+ this.addDialogVisible = false;
+ let result = {};
+ try {
result = await addDeviceService(this.addForm);
- if(result.code == 0){
+ if (result.code == 0) {
alert("添加成功");
} else {
alert("添加失败");
}
- }catch (e) {
- console.log(e)
+ } catch (e) {
+ console.log(e);
+ }
+ },
+ async updateDevice() {
+ this.updateDialogVisible = false;
+ let result = {};
+ try {
+ result = await updateDeviceService(this.updateForm);
+ if (result.code == 0) {
+ alert("修改成功");
+ this.getDeviceList()
+ } else {
+ alert("修改失败");
+ }
+ } catch (e) {
+ console.log(e);
}
},
async restartAllDevice() {
@@ -204,7 +265,9 @@ export default {
>
- 添加设备
+ 添加设备
-
+
-
+
-
+
@@ -255,6 +321,59 @@ export default {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -299,6 +418,18 @@ export default {
@click.prevent="restartDevice(scope.$index)"
>重启
+ 修改
+ 删除
diff --git a/src/views/UserList.vue b/src/views/UserList.vue
index ad1182b..e87e431 100644
--- a/src/views/UserList.vue
+++ b/src/views/UserList.vue
@@ -57,6 +57,10 @@ export default {
// to_user_name: this.tableData[index].Name,
// };
//转到聊天页面
+ if(id == localStorage.getItem("userId")){
+ alert("不能和自己聊天");
+ return;
+ }
localStorage.setItem("to_user_id", id);
localStorage.setItem("to_user_name", name);
router.push("/im");