diff --git a/src/App.vue b/src/App.vue index a47d7d7..5ac7430 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,50 +2,24 @@ import { ref, onMounted } from "vue"; import MainPage from "./MainPage.vue"; import Slider from "./components/Slider.vue"; -import Client from "./utils/ws"; +import useWebsocket from "./utils/useWebsocket"; import { useWsStore } from "./store"; - const store = useWsStore(); -const url = "ws://192.168.1.101:8082/QbMonitoring/websocket"; +// use websocket let urlPath = document.location.pathname; if (urlPath === "/") { urlPath = "/1-1"; } -new Client( - { - url: url + urlPath, - name: urlPath, - }, - (message) => { - try { - const data = JSON.parse(message.data); - console.log("message", JSON.parse(message.data)); - - if ("specificationChanges" in data) { - console.log("[*] setting data1"); - // 分屏推送1数据 - store.updateData("1", data); - } else if ("deliveryNotification" in data) { - // 分屏推送3数据 - console.log("[*] setting data3"); - store.updateData("3", data); - } else { - // 分屏推送2数据 - console.log("[*] setting data2"); - store.updateData("2", data); - } - } catch (err) { - console.log("[x] 未解析的ws数据: ", err); - } - } -); +useWebsocket(store, urlPath); +// size setting const size = ref(80); onMounted(() => { setSize(size.value); }); +// style update const styles = ref({}); function setSize(value) { const v = (value / 100).toFixed(2); diff --git a/src/components/HourChart.vue b/src/components/HourChart.vue index df9f58c..77f1a59 100644 --- a/src/components/HourChart.vue +++ b/src/components/HourChart.vue @@ -1,10 +1,13 @@ diff --git a/src/components/HourChartOptions.js b/src/components/HourChartOptions.js new file mode 100644 index 0000000..59dc9af --- /dev/null +++ b/src/components/HourChartOptions.js @@ -0,0 +1,40 @@ +export const options = { + grid: { + top: "5%", + bottom: "5%", + left: "3%", + right: "3%", + containLabel: true, + }, + xAxis: { + type: "category", + data: [], + axisLabel: { + fontSize: 24, + }, + }, + yAxis: { + type: "value", + axisLabel: { + fontSize: 24, + }, + minInterval: 1, + }, + series: [ + { + data: [], + type: "bar", + showBackground: true, + backgroundStyle: { + color: "rgba(180, 180, 180, 0.2)", + }, + }, + ], +}; + +export default function setup(echartInstance, timeArr, dataArr) { + const options = { ...options }; + options.xAxis.data = timeArr; + options.series[0].data = dataArr; + echartInstance.setOption(options); +} diff --git a/src/utils/connects.js b/src/utils/connects_deprecated.js similarity index 100% rename from src/utils/connects.js rename to src/utils/connects_deprecated.js diff --git a/src/utils/useWebsocket.js b/src/utils/useWebsocket.js new file mode 100644 index 0000000..ea069f2 --- /dev/null +++ b/src/utils/useWebsocket.js @@ -0,0 +1,55 @@ +import Client from "./ws"; + +export default function useWebsocket(store, path) { + connect0(store); + connectPath(store, path); +} + +const url = "ws://192.168.1.101:8082/QbMonitoring/websocket"; +function connectPath(store, path) { + new Client( + { + url: url + path, + name: path, + }, + (message) => { + try { + const data = JSON.parse(message.data); + console.log("message", JSON.parse(message.data)); + + if ("specificationChanges" in data) { + console.log("[*] setting data1"); + // 分屏推送1数据 + store.updateData("1", data); + } else if ("deliveryNotification" in data) { + // 分屏推送3数据 + console.log("[*] setting data3"); + store.updateData("3", data); + } else { + // 分屏推送2数据 + console.log("[*] setting data2"); + store.updateData("2", data); + } + } catch (err) { + console.log("[x] 未解析的ws数据: ", err); + } + } + ); +} + +function connect0(store) { + new Client( + { + url: url + "/0", + name: "/0", + }, + (message) => { + try { + const data = JSON.parse(message.data); + console.log("message --- 0 ---> ", JSON.parse(message.data)); + } catch (err) { + console.log("[x] 未解析的ws数据: ", err); + } + } + ); +}