Commit b7247fc48d0a64c93e9a4088677dfb8b71dca89b
Merge branch 'ft' into 'main_dev'
fix: 修复公共接口切换产品切换属性websocket又新建连接,造成上一个ws和这一个ws交替接受信息问题 See merge request yunteng/thingskit-front!720
Showing
1 changed file
with
7 additions
and
1 deletions
... | ... | @@ -68,7 +68,7 @@ |
68 | 68 | </div> |
69 | 69 | </template> |
70 | 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 | 72 | import { Button } from 'ant-design-vue'; |
73 | 73 | import { otherHttp } from '/@/utils/http/axios'; |
74 | 74 | import { useWebSocket } from '@vueuse/core'; |
... | ... | @@ -153,6 +153,9 @@ |
153 | 153 | |
154 | 154 | const postBodyType = ref(''); |
155 | 155 | |
156 | + //定义一个全局的关闭websocket变量 fix: 修复切换产品切换属性websocket又新建连接,造成上一个ws和这一个ws交替接受信息问题 | |
157 | + const closeSocket = ref<Nullable<Fn>>(null); | |
158 | + | |
156 | 159 | //执行测试接口 |
157 | 160 | const handleExcute = () => { |
158 | 161 | emits('emitExcute'); |
... | ... | @@ -188,6 +191,8 @@ |
188 | 191 | const list = Object.values(params); |
189 | 192 | const isEmpty = list.some((it) => it === '' || null || undefined); |
190 | 193 | if (!isEmpty) { |
194 | + //执行ws close方法 关闭上一个 | |
195 | + unref(closeSocket)?.(); | |
191 | 196 | websocketRequest(params); |
192 | 197 | } else { |
193 | 198 | resetValue(false); |
... | ... | @@ -245,6 +250,7 @@ |
245 | 250 | }, |
246 | 251 | onError() {}, |
247 | 252 | }); |
253 | + closeSocket.value = close; | |
248 | 254 | if (destroy) close(); |
249 | 255 | } finally { |
250 | 256 | } | ... | ... |