diff --git a/src/api/media/device.ts b/src/api/media/device.ts index 6854d9e4..58b21f57 100644 --- a/src/api/media/device.ts +++ b/src/api/media/device.ts @@ -25,4 +25,6 @@ export default { queryProvider: (data?: any) => server.post(`/gateway/device/detail/_query`, data), // 查询网关配置 getConfiguration: (id: string, transport: string) => server.get(`/protocol/${id}/${transport}/configuration`), + //校验ID合法 + validateId: (id:string) => server.get('/media/device/id/_validate',{id:id}) } \ No newline at end of file diff --git a/src/utils/websocket.ts b/src/utils/websocket.ts index 920825f9..e971f641 100644 --- a/src/utils/websocket.ts +++ b/src/utils/websocket.ts @@ -13,10 +13,11 @@ const timeout = 5000 const tempQueue: any[] = [] // websocket未连接上时,缓存消息列 export const initWebSocket = () => { + const token = getToken() + if (!token) return if (ws) { return ws } - const token = getToken() const url = `${document.location.protocol.replace('http', 'ws')}//${document.location.host}${BASE_API_PATH}/messaging/${token}?:X_Access_Token=${token}`; if (count < total) { count += 1 @@ -102,6 +103,13 @@ export const getWebSocket = (id: string, topic: string, parameter: Record { + if (ws) { + ws.close() + timer && clearInterval(timer) + } +} + /** * 重连 */ diff --git a/src/views/device/Instance/Import/modal.vue b/src/views/device/Instance/Import/modal.vue index f55c983d..64e1a8bc 100644 --- a/src/views/device/Instance/Import/modal.vue +++ b/src/views/device/Instance/Import/modal.vue @@ -162,6 +162,7 @@ const save = () => { const importCancel = () => { importVisible.value = false emit('save') + cancel() } diff --git a/src/views/media/Device/Save/index.vue b/src/views/media/Device/Save/index.vue index 7e1d0a51..21d6a7f3 100644 --- a/src/views/media/Device/Save/index.vue +++ b/src/views/media/Device/Save/index.vue @@ -310,6 +310,7 @@ import DeviceApi from '@/api/media/device'; import { PROVIDER_OPTIONS } from '@/views/media/Device/const'; import type { ProductType } from '@/views/media/Device/typings'; import SaveProduct from './SaveProduct.vue'; +import { notification } from 'jetlinks-ui-components'; const router = useRouter(); const route = useRoute(); @@ -425,13 +426,18 @@ const handleSubmit = () => { formRef.value ?.validate() .then(async () => { - btnLoading.value = true; - const res = !route.query.id - ? await DeviceApi.save(params) - : await DeviceApi.update(params); - if (res?.success) { - onlyMessage('保存成功'); - history.back(); + const resq:any = await DeviceApi.validateId(id) + if(resq.status === 200 && resq?.result?.passed){ + btnLoading.value = true; + const res = !route.query.id + ? await DeviceApi.save(params) + : await DeviceApi.update(params); + if (res?.success) { + onlyMessage('保存成功'); + history.back(); + } + }else{ + notification.error({ key: 'error', message: '设备ID已重复'}) } }) .catch((err: any) => { diff --git a/src/views/user/Login/index.vue b/src/views/user/Login/index.vue index 0ef0f3d7..1b8ed397 100644 --- a/src/views/user/Login/index.vue +++ b/src/views/user/Login/index.vue @@ -178,6 +178,7 @@ import { LocalStore } from '@/utils/comm'; import { BASE_API_PATH, TOKEN_KEY, Version_Code } from '@/utils/variable'; import { SystemConst } from '@/utils/consts'; import {encrypt} from '@/utils/encrypt' +import { closeWs } from '@/utils/websocket' const store = useUserInfo(); const systemStore = useSystem(); @@ -382,6 +383,7 @@ getOpen(); getCode(); screenRotation(screenWidth.value, screenHeight.value); +closeWs() onMounted(()=>{ getRsa() })