diff --git a/package-lock.json b/package-lock.json index 47d9e48..c3543cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "cors": "^2.8.5", "crypto-js": "^4.2.0", "element-plus": "^2.4.4", + "js-cookie": "^3.0.5", "js-md5": "^0.8.3", "qrcode": "^1.5.3", "video.js": "^8.9.0", @@ -1463,6 +1464,14 @@ "resolved": "https://registry.npmjs.org/js-binary-schema-parser/-/js-binary-schema-parser-2.0.3.tgz", "integrity": "sha512-xezGJmOb4lk/M1ZZLTR/jaBHQ4gG/lqQnJqdIv4721DMggsa1bDVlHXNeHYogaIEHD9vCRv0fcL4hMA+Coarkg==" }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "engines": { + "node": ">=14" + } + }, "node_modules/js-md5": { "version": "0.8.3", "resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.8.3.tgz", diff --git a/package.json b/package.json index 9290346..7ff764d 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "cors": "^2.8.5", "crypto-js": "^4.2.0", "element-plus": "^2.4.4", + "js-cookie": "^3.0.5", "js-md5": "^0.8.3", "qrcode": "^1.5.3", "video.js": "^8.9.0", diff --git a/src/api/device.js b/src/api/device.js index ed8461c..7017a2e 100644 --- a/src/api/device.js +++ b/src/api/device.js @@ -5,7 +5,7 @@ export const restartDeviceService = (data) => { for (let key in data) { params.append(key, data[key]) } - return request.post('/device/restart', params, { "headers":{'token': data.token }}); + return request.post('/device/restart', params, { "headers": { 'token': data.token } }); } export const updateDeviceService = (data) => { @@ -13,7 +13,7 @@ export const updateDeviceService = (data) => { for (let key in data) { params.append(key, data[key]) } - return request.post('/device/update', params,{ "headers":{'token': data.token }}); + return request.post('/device/update_device', params, { "headers": { 'token': data.token } }); } export const addDeviceService = (data) => { @@ -21,12 +21,12 @@ export const addDeviceService = (data) => { for (let key in data) { params.append(key, data[key]) } - return request.post('/device/add', params,{ "headers":{'token': data.token }}); + return request.post('/device/add_device', params, { "headers": { 'token': data.token } }); } export const getDeviceListService = (data) => { const params = new URLSearchParams(); - for(let d in data) { + for (let d in data) { params.append(d, data[d]); } // request.headers["Content-Type"] = "application/json"; diff --git a/src/views/DeviceList.vue b/src/views/DeviceList.vue index b278dc4..6bad8e6 100644 --- a/src/views/DeviceList.vue +++ b/src/views/DeviceList.vue @@ -3,6 +3,7 @@ import axios from "axios"; import { inject } from "vue"; import { getDeviceListService } from "@/api/device.js"; import { restartDeviceService } from "@/api/device.js"; +import { addDeviceService } from "@/api/device.js"; import router from "@/router/index.js"; export default { @@ -16,10 +17,21 @@ export default { userId: localStorage.getItem("userId"), username: localStorage.getItem("username"), }, + addDialogVisible: false, searchForm: { hour: 0, entrydate: [], }, + addForm: { + device_name: "", + device_ip: "", + device_status: "", + device_info: "", + device_location: "", + device_type: "", + auth_id: -1, + token: localStorage.getItem("token"), + }, }; }, @@ -75,6 +87,20 @@ export default { console.log(e); } }, + async addDevice() { + this.addDialogVisible = true; + let result ={} + try{ + result = await addDeviceService(this.addForm); + if(result.code == 0){ + alert("添加成功"); + } else { + alert("添加失败"); + } + }catch (e) { + console.log(e) + } + }, async restartAllDevice() { var restart_data = { id: id, @@ -150,7 +176,10 @@ export default { @click.prevent="handleMenuSelect('/device')" >设备管理 - 用户 @@ -169,19 +198,63 @@ export default { >查询 - - 退出登录 - - - 返回监控视频 - 重启全部设备 + + 添加设备 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/views/Im.vue b/src/views/Im.vue index 4b2f21a..33b1c05 100644 --- a/src/views/Im.vue +++ b/src/views/Im.vue @@ -18,7 +18,9 @@ @click.prevent="handleMenuSelect('/User')" >用户 - +
- Web聊天室({{ chatUser }}) + ({{ chatUser }})
30) { //暂停定时器 this.stopInterval(); - alert("连接失败,请重试!"); + confirm("连接失败,请重试!"); router.push("/user"); } } @@ -285,7 +285,6 @@ export default { // 将解密后的 WordArray 转换为 UTF-8 字符串 const decryptedText = decrypted.toString(CryptoJS.enc.Utf8); - console.log("decryptedText: " + decryptedText,secretKey, iv,encryptedData); return decryptedText; } catch (error) { // 捕获并处理异常 @@ -306,7 +305,7 @@ export default { "&token=" + this.tokenData.token; - console.log("socketUrl:", socketUrl); + // console.log("socketUrl:", socketUrl); if (this.socket != null) { this.socket.close(); this.socket = null; @@ -315,19 +314,29 @@ export default { this.socket = new WebSocket(socketUrl); //打开事件 this.socket.onopen = function () { - alert("websocket已打开"); + confirm("连接成功"); + this.loading = false; }; this.socket.onerror = (error) => { console.error("WebSocket Error:", error); }; + //关闭事件 + this.socket.onclose = function () { + alert("连接已关闭!"); + router.push("/user"); + }; // 浏览器端收消息,获得从服务端发送过来的文本消息 this.socket.onmessage = async function (msg) { - console.log("收到数据====" + msg.data); + //console.log("收到数据====" + msg.data); let data = JSON.parse(msg.data); // 对收到的json数据进行解析, 类似这样的: // 如果服务器端发送过来的json数据 不包含 users 这个key,那么发送过来的就是聊天文本json数据 - data.data=await _this.decryptAES(data.data, _this.imKey, _this.imKey) + data.data = await _this.decryptAES( + data.data, + _this.imKey, + _this.imKey + ); _this.messages.push(data); - console.log("收到数据====" + msg.data); + //console.log("收到数据====" + msg.data); // 构建消息内容 _this.createContent(_this.to_user_name, null, data.data); }; @@ -336,7 +345,6 @@ export default { }, // 生命周期钩子,在组件挂载完成后被调用 mounted() { - console.log("chatUser:", this.chatUser); this.to_user_id = localStorage.getItem("to_user_id"); this.to_user_name = localStorage.getItem("to_user_name"); this.chatUser = this.to_user_name; @@ -345,9 +353,10 @@ export default { //this.connectWebSocket(); }, // 生命周期钩子,在组件卸载之前被调用 - beforeDestroy() { + onUnmounted() { this.stopInterval(); this.socket.close(); + this.loading = false; }, };