From f6602d37cddddecf43cd671ee4af43aae9a71ea0 Mon Sep 17 00:00:00 2001
From: 23688nl <329261568@qq.com>
Date: Wed, 28 Sep 2022 11:20:11 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=EF=BC=9A=20=E8=AE=BE?=
=?UTF-8?q?=E5=A4=87=E7=AE=A1=E7=90=86=20=E7=BD=91=E5=85=B3=E7=B1=BB?=
=?UTF-8?q?=E5=9E=8B=20=E8=AE=BE=E5=A4=87=E8=AF=A6=E6=83=85=20=E6=B7=BB?=
=?UTF-8?q?=E5=8A=A0=20=E8=AE=BE=E5=A4=87=E7=8A=B6=E6=80=81ws?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/EWebSocket/index.js | 5 +
src/components/EWebSocket/src/basic/index.js | 8 +
.../EWebSocket/src/basic/webSocket.js | 94 ++++++++
src/components/EWebSocket/src/index | 0
src/components/ParamWrap/deviceParam.vue | 89 ++++----
.../ESceneTriggers/src/EConditionTemp.vue | 13 +-
.../ESceneManage/ESceneTriggers/src/index.js | 2 +-
.../ESceneTriggers/src/style.scss | 2 +-
.../profile/DeviceDetailsView/EWebSocket.vue | 16 ++
.../DeviceDetailsView/deviceSelectNav.vue | 215 ++++++++++++++----
10 files changed, 359 insertions(+), 85 deletions(-)
create mode 100644 src/components/EWebSocket/index.js
create mode 100644 src/components/EWebSocket/src/basic/index.js
create mode 100644 src/components/EWebSocket/src/basic/webSocket.js
create mode 100644 src/components/EWebSocket/src/index
create mode 100644 src/views/profile/DeviceDetailsView/EWebSocket.vue
diff --git a/src/components/EWebSocket/index.js b/src/components/EWebSocket/index.js
new file mode 100644
index 00000000..bf9b71cc
--- /dev/null
+++ b/src/components/EWebSocket/index.js
@@ -0,0 +1,5 @@
+import EWebSocket from './src/basic/index';
+
+export default {
+ EWebSocket
+}
diff --git a/src/components/EWebSocket/src/basic/index.js b/src/components/EWebSocket/src/basic/index.js
new file mode 100644
index 00000000..469d713d
--- /dev/null
+++ b/src/components/EWebSocket/src/basic/index.js
@@ -0,0 +1,8 @@
+
+import EWebSocket from "./webSocket"
+
+EWebSocket.install = function install(Vue) {
+ Vue.component(EWebSocket.name, EWebSocket);
+};
+
+export default EWebSocket
diff --git a/src/components/EWebSocket/src/basic/webSocket.js b/src/components/EWebSocket/src/basic/webSocket.js
new file mode 100644
index 00000000..672f85b7
--- /dev/null
+++ b/src/components/EWebSocket/src/basic/webSocket.js
@@ -0,0 +1,94 @@
+
+export default {
+ name: 'EWebSocket',
+ props: {
+ wsServiceUrl: {
+ type: String,
+ default: ''
+ },
+ closeSleepTime: {
+ type: Number,
+ default: 10000
+ }
+ },
+ data() {
+ return {
+ stompClient: null,
+ socket_flag: false,
+ timeout_flag: null
+ }
+ },
+ watch: {
+ wsServiceUrl() {
+ if (this.stompClient) {
+ this.closeSocket();
+ }
+ this.connection();
+ }
+ },
+ methods: {
+ /**
+ * 创建 ws 对象
+ * @returns
+ */
+ connection() {
+ if (this.stompClient) {
+ return;
+ }
+ if (!this.wsServiceUrl) {
+ return;
+ }
+ this.stompClient = new WebSocket(`${this.wsServiceUrl}`);
+ this.stompClient.onopen = this.socket_open;
+ this.stompClient.onmessage = this.socket_message;
+ this.stompClient.onclose = this.socket_close;
+ },
+ socket_open(evt) {
+ console.log("ws-open:", evt);
+ this.$emit('open', evt)
+ },
+ /**
+ * ws message
+ * @param {*} evt
+ */
+ socket_message(evt) {
+ console.log("wsljcg:=", evt);
+ const data = JSON.parse(evt.data);
+ this.$emit('message_http', evt);
+ this.$emit('message', data)
+ },
+ /**
+ * ws close
+ * @param {*} e
+ */
+ socket_close(e) {
+ this.stompClient = null;
+ if (this.socket_flag) {
+ this.socket_flag = false;
+ let _this = this;
+ _this.timeout_flag = setTimeout(function () {
+ _this.socket_flag = true;
+ _this.connection();
+ }, Number(this.closeSleepTime));
+ }
+ },
+ /**
+ * ws 前端 销毁
+ */
+ closeSocket() {
+ if (this.stompClient) {
+ console.log('ws-close!!!')
+ this.stompClient.close();
+ }
+ this.socket_flag = false;
+ this.stompClient = null;
+ clearTimeout(this.timeout_flag);
+ },
+ },
+ render() {
+ return ()
+ },
+ destroyed() {
+ this.closeSocket();
+ },
+}
diff --git a/src/components/EWebSocket/src/index b/src/components/EWebSocket/src/index
new file mode 100644
index 00000000..e69de29b
diff --git a/src/components/ParamWrap/deviceParam.vue b/src/components/ParamWrap/deviceParam.vue
index ab901afb..19e48260 100644
--- a/src/components/ParamWrap/deviceParam.vue
+++ b/src/components/ParamWrap/deviceParam.vue
@@ -10,11 +10,22 @@
-
+
+ >
-
暂无参数信息
@@ -41,34 +51,34 @@ export default {
data() {
return {
list: [],
- ruleForm: {}
+ ruleForm: {},
};
},
methods: {
getParams() {
- this.list = []
- const newArr = getTypeParam(this.typeKeys)
+ this.list = [];
+ const newArr = getTypeParam(this.typeKeys);
if (newArr) {
- newArr.forEach(v => {
- this.list.push(Object.assign({}, v))
+ newArr.forEach((v) => {
+ this.list.push(Object.assign({}, v));
});
}
this.$forceUpdate();
},
setList(data) {
- this.list = data
+ this.list = data;
},
getResult() {
return this.list;
- }
+ },
},
watch: {
typeKeys(val) {
if (val) {
this.getParams();
}
- }
- }
+ },
+ },
};