| | |
| | | import store from "../store/index"; |
| | | import http from "@/../src/api/http.js"; |
| | | import { ElNotification } from "element-plus"; |
| | | import { useStore } from "vuex"; |
| | | |
| | | export default defineComponent({ |
| | | components: { |
| | | VolMenu, |
| | |
| | | rightTabs: true, |
| | | otherTabs: true, |
| | | menuLeft: 0, |
| | | menuTop: 0, |
| | | client: null |
| | | menuTop: 0 |
| | | |
| | | // contextMenuVisible: false, // å³é®å
³éæ¾/é |
| | | }; |
| | | }, |
| | |
| | | toggleLeft(); |
| | | } |
| | | }; |
| | | const Store = useStore(); |
| | | const s = ref(null); |
| | | |
| | | const handleMessage = e => { |
| | | if (e) { |
| | | s.value = e.data; |
| | | console.log("WebSocket æ¶å°æ¶æ¯: ", e.data); |
| | | store.dispatch("sethomedata", s.value); |
| | | let data = JSON.parse(e.data); |
| | | messageList.push(data); |
| | | ElNotification({ |
| | |
| | | message: h("i", { style: "color: teal" }, data.message), |
| | | position: "bottom-right" |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | const createSocket = url => { |
| | | //console.log(url); |
| | | |
| | | // å建WebSocketè¿æ¥ |
| | | //"ws://127.0.0.1:9295/admin" |
| | | client = new WebSocket(url); |
| | | |
| | | //client = new WebSocket("ws://192.168.0.250:9260/"); |
| | | client = new WebSocket("ws:localhost:9260/"); |
| | | client.onopen = function() { |
| | | client.onmessage = handleMessage; |
| | | store.commit("setWebsocket", client); |
| | | //client.onmessage = handleMessage; |
| | | // store.commit("setWebsocket", client); |
| | | console.log("WebSocket è¿æ¥æå"); |
| | | }; |
| | | |
| | | client.onmessage = function(event) { |
| | | // console.log("WebSocket æ¶å°æ¶æ¯: ", event); |
| | | |
| | | if (event != undefined) { |
| | | store.dispatch("sethomedata", JSON.parse(event.data)); |
| | | } |
| | | // handleMessage(event); |
| | | }; |
| | | |
| | | client.onclose = function() { |
| | |
| | | setTimeout(createSocket, 10000); |
| | | }; |
| | | |
| | | client.onerror = function() {}; |
| | | client.onerror = function(err) { |
| | | console.log("WebSocket è¿æ¥é误: ", err); |
| | | }; |
| | | client.onmessage(); |
| | | }; |
| | | |
| | | const changeTheme = name => { |