Commit fe8eca664072360cdc291f5c4f5ca31aa014fd2c

Authored by fengwotao
1 parent 71cb984f

fix: 公共接口修复切换产品切换属性websocket又新建连接,造成上一个ws和这一个ws交替接受信息问题

@@ -68,7 +68,7 @@ @@ -68,7 +68,7 @@
68 </div> 68 </div>
69 </template> 69 </template>
70 <script lang="ts" setup name="testRequest"> 70 <script lang="ts" setup name="testRequest">
71 - import { nextTick, ref, reactive, onUnmounted } from 'vue'; 71 + import { nextTick, ref, reactive, onUnmounted, unref } from 'vue';
72 import { Button } from 'ant-design-vue'; 72 import { Button } from 'ant-design-vue';
73 import { otherHttp } from '/@/utils/http/axios'; 73 import { otherHttp } from '/@/utils/http/axios';
74 import { useWebSocket } from '@vueuse/core'; 74 import { useWebSocket } from '@vueuse/core';
@@ -153,6 +153,9 @@ @@ -153,6 +153,9 @@
153 153
154 const postBodyType = ref(''); 154 const postBodyType = ref('');
155 155
  156 + //定义一个全局的关闭websocket变量 fix: 修复切换产品切换属性websocket又新建连接,造成上一个ws和这一个ws交替接受信息问题
  157 + const closeSocket = ref<Nullable<Fn>>(null);
  158 +
156 //执行测试接口 159 //执行测试接口
157 const handleExcute = () => { 160 const handleExcute = () => {
158 emits('emitExcute'); 161 emits('emitExcute');
@@ -188,6 +191,8 @@ @@ -188,6 +191,8 @@
188 const list = Object.values(params); 191 const list = Object.values(params);
189 const isEmpty = list.some((it) => it === '' || null || undefined); 192 const isEmpty = list.some((it) => it === '' || null || undefined);
190 if (!isEmpty) { 193 if (!isEmpty) {
  194 + //执行ws close方法 关闭上一个
  195 + unref(closeSocket)?.();
191 websocketRequest(params); 196 websocketRequest(params);
192 } else { 197 } else {
193 resetValue(false); 198 resetValue(false);
@@ -245,6 +250,7 @@ @@ -245,6 +250,7 @@
245 }, 250 },
246 onError() {}, 251 onError() {},
247 }); 252 });
  253 + closeSocket.value = close;
248 if (destroy) close(); 254 if (destroy) close();
249 } finally { 255 } finally {
250 } 256 }