| File was renamed from src/page/index/useDownloadWs.js |
| | |
| | | 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 |
| | |
| | | ...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 |
| | |
| | | } |
| | | } |
| | | |
| | | 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 {} |
| | | } |