| src/App.vue | ●●●●● patch | view | raw | blame | history | |
| src/page/index/GlobalWS.vue | ●●●●● patch | view | raw | blame | history | |
| src/page/index/index.vue | ●●●●● patch | view | raw | blame | history | |
| src/page/index/useGlobalWS.js | ●●●●● patch | view | raw | blame | history | |
| src/store/modules/common.js | ●●●●● patch | view | raw | blame | history | |
| src/views/dataCenter/components/searchData.vue | ●●●●● patch | view | raw | blame | history | |
| src/views/job/components/TaskIntermediateContent/TaskIntermediateContent.vue | ●●●●● patch | view | raw | blame | history |
src/App.vue
@@ -4,8 +4,6 @@ <script setup> import { useDownloadWs } from '@/page/index/useDownloadWs'; useDownloadWs() </script> <style> src/page/index/GlobalWS.vue
New file @@ -0,0 +1,11 @@ <template> </template> <script setup> import { useGlobalWS } from '@/page/index/useGlobalWS'; useGlobalWS() </script> <style scoped lang="scss"> </style> src/page/index/index.vue
@@ -24,6 +24,8 @@ </div> </div> </div> <GlobalWS/> <!-- <wechat></wechat> --> </div> </template> @@ -37,10 +39,12 @@ import logo from './logo.vue' import top from './top/index.vue' import sidebar from './sidebar/index.vue' import GlobalWS from '@/page/index/GlobalWS.vue'; export default { mixins: [index], components: { GlobalWS, top, logo, tags, src/page/index/useGlobalWS.js
File was renamed from src/page/index/useDownloadWs.js @@ -1,20 +1,21 @@ import { computed, onBeforeUnmount, onMounted } from 'vue'; import { getWebsocketUrl } from '@/utils/websocket/config' import { useConnectWebSocket } from '@/utils/websocket/connect-websocket' import { useStore } from 'vuex' import dayjs from 'dayjs' import { aLinkDownloadUtil } from '@/utils/util' import EventBus from '@/utils/eventBus' import { computed, onBeforeUnmount, onMounted } from 'vue'; import { setStore,getStore } from '@/utils/store'; import { getDownloadStatusApi } from '@/api/dataCenter/dataCenter'; import { getStore, setStore } from '@/utils/store' export const useDownloadWs = () => { export const useGlobalWS = () => { const store = useStore() const loginUserInfo = computed(() => store.state.user.userInfo) const downloadProgress = computed(() => store.state.common.downloadProgress) let currentWebSocket = null function messageHandler(payload) { const {type,status,progress,download_url} = payload // 下载进度处理 function downloadProcessing(payload) { const {type,status,progress,download_url} = payload?.data || {} let setProgress = 0 if (status === 'PENDING'){ setProgress = 1 @@ -29,7 +30,7 @@ ...downloadProgress.value, [type]: setProgress, }) if (status === 'COMPLETED' && ['htsjzx','htlsrwxq'].includes(type)) { if (status === 'COMPLETED' && ['dpsjzx','dplsrwxq'].includes(type)) { const name = `数据中心-${dayjs().format('YYYYMMDDHHmmss')}.zip` const currentUrl = getStore({name: 'downloadUrl'}) if (currentUrl === download_url && download_url!== undefined) return @@ -38,18 +39,42 @@ } } const logOut = () => { store.commit('SET_THEME_NAME', '') store.dispatch('LogOut').then(() => { router.push({ path: '/login' }) setTimeout(() => location.reload()) }) } function messageHandler(payload) { switch (payload.biz_code) { case 'JOB_ISREFRESH': store.commit('jobUpdateKeyAdd') break case 'DEVICE_ISREFRESH': store.commit('deviceUpdateKeyAdd') break case 'DOWNLOAD_PROGRESS': downloadProcessing(payload) break case 'LOGOUT_USER': logOut() break } } onMounted(() => { let webSocketUrl = getWebsocketUrl() + `&model_type=3&workspace-id=${loginUserInfo.value.user_id}` currentWebSocket = useConnectWebSocket((result)=>{ const payload = JSON.parse(result) messageHandler(payload.data) messageHandler(payload) }, webSocketUrl) EventBus.on('useDownloadWs-messageHandler',messageHandler) EventBus.on('useGlobalWS-messageHandler',messageHandler) }) onBeforeUnmount(() => { currentWebSocket?.close() EventBus.off('useDownloadWs-messageHandler',messageHandler) EventBus.off('useGlobalWS-messageHandler',messageHandler) }) return {} } src/store/modules/common.js
@@ -18,9 +18,17 @@ downloadProgress:{ htsjzx: 100, //数据中心 htlsrwxq: 100, //历史任务详情 } }, deviceUpdateKey: 0, //设备刷新key jobUpdateKey: 0, //任务刷新key }, mutations: { deviceUpdateKeyAdd(state, data) { state.deviceUpdateKey = state.deviceUpdateKey + 1 }, jobUpdateKeyAdd(state, data) { state.jobUpdateKey = state.jobUpdateKey + 1 }, setDownloadProgress(state, data) { state.downloadProgress = data }, src/views/dataCenter/components/searchData.vue
@@ -3,7 +3,7 @@ <el-form :model="searchForm" inline> <div class="search-first"> <el-form-item label="行政区划:" > <el-tree-select <el-tree-select :disabled="viewDetailsDisabled" popper-class="custom-tree-select" v-model="searchForm.areaCode" @@ -80,7 +80,7 @@ </el-form-item> <el-form-item label="文件类别:"> <el-select :disabled="disabled || foldersDisabled || viewDetailsDisabled" :teleported="false" v-model="searchForm.photoType" @@ -283,7 +283,7 @@ machineData.value = ''; const droneList = await getDeviceRegion({ areaCode: data.id }); machineData.value = droneList?.data?.data; // 默认选中值 if (signDevice_sn.value) { searchForm.deviceSn = signDevice_sn.value; @@ -292,7 +292,7 @@ deptData.value = []; getDeptsByAreaCode(); handleSearch(); }; // 所属部门信息 const getDeptsByAreaCode = () => { @@ -351,17 +351,17 @@ } // 切换文件夹 const handleswitchFolders =()=>{ emit('handleswitchFolders'); emit('handleswitchFolders'); } // 返回按钮 const handleBack = ()=>{ emit('handleBack'); emit('handleBack'); } onMounted(() => { requestDockInfo(); getDownloadStatusApi({type: 'htsjzx'}).then(res =>{ if (!['CANCELLED','COMPLETED'].includes(res.data.data?.status || 'COMPLETED')){ EventBus.emit('useDownloadWs-messageHandler',res.data.data) EventBus.emit('useGlobalWS-messageHandler',res.data.data) } }) }); src/views/job/components/TaskIntermediateContent/TaskIntermediateContent.vue
@@ -119,7 +119,7 @@ import CancelTaskDialog from '../CancelTaskDialog.vue' import { useStore } from 'vuex' import { cloneDeep } from 'lodash' import { inject, onBeforeUnmount } from 'vue'; import { inject, onBeforeUnmount, watch } from 'vue'; import ElTooltipCopy from '@/components/ElTooltipCopy.vue'; const store = useStore() const singleUavHome = computed(() => store.state.home.singleUavHome) @@ -264,14 +264,14 @@ const changeKey = inject('changeKey') // 轮询查询是否刷新 const polling = setInterval(async () => { const res = await statusChangedApi() if (res.data.data.DEVICE_REFRESH || res.data.data.JOB_REFRESH) { getJobList() changeKey.value++ } }, 4000) const jobUpdateKey = computed(() => store.state.common.jobUpdateKey) const deviceUpdateKey = computed(() => store.state.common.deviceUpdateKey) watch([jobUpdateKey,deviceUpdateKey],()=>{ getJobList() changeKey.value++ }) onBeforeUnmount(() => { clearInterval(polling)