完善审批台接收推送信息

This commit is contained in:
Mr.j 2025-08-08 16:37:36 +08:00
parent 5a13911694
commit f7641f6439
4 changed files with 81 additions and 26 deletions

View File

@ -1,49 +1,70 @@
import http from '@/utils/http'
import type { EquipmentApprovalReq, EquipmentApprovalResp, EquipmentApprovalListReq } from './type'
import type { EquipmentApprovalListReq, EquipmentApprovalResp } from './type'
/**
* API
* API
*/
export const equipmentApprovalApi = {
/**
*
*/
getPendingApprovals: (params: EquipmentApprovalListReq) => {
return http.get<ApiRes<PageRes<EquipmentApprovalResp>>>('/equipment/approval/pending', { params })
getPendingApprovals(params: EquipmentApprovalListReq) {
return http.get<EquipmentApprovalResp[]>('/equipment/approval/pending', params)
},
/**
*
*/
getApprovedApprovals: (params: EquipmentApprovalListReq) => {
return http.get<ApiRes<PageRes<EquipmentApprovalResp>>>('/equipment/approval/approved', { params })
getApprovedApprovals(params: EquipmentApprovalListReq) {
return http.get<EquipmentApprovalResp[]>('/equipment/approval/approved', params)
},
/**
*
*/
approve: (approvalId: string, data: EquipmentApprovalReq) => {
return http.post<ApiRes<null>>(`/equipment/approval/${approvalId}/approve`, data)
approve(approvalId: string, data: any) {
return http.post(`/equipment/approval/${approvalId}/approve`, data)
},
/**
*
*/
reject: (approvalId: string, data: EquipmentApprovalReq) => {
return http.post<ApiRes<null>>(`/equipment/approval/${approvalId}/reject`, data)
reject(approvalId: string, data: any) {
return http.post(`/equipment/approval/${approvalId}/reject`, data)
},
/**
*
*/
getApprovalDetail: (approvalId: string) => {
return http.get<ApiRes<EquipmentApprovalResp>>(`/equipment/approval/${approvalId}`)
getApprovalDetail(approvalId: string) {
return http.get<EquipmentApprovalResp>(`/equipment/approval/${approvalId}`)
},
/**
*
*/
getApprovalStats: () => {
return http.get<ApiRes<unknown>>('/equipment/approval/stats')
getApprovalStats() {
return http.get('/equipment/approval/stats')
},
/**
*
*/
submitProcurementApplication(data: any) {
return http.post('/equipment/approval/procurement/apply', data)
},
/**
*
*/
getMyProcurementApplications(params: EquipmentApprovalListReq) {
return http.get<EquipmentApprovalResp[]>('/equipment/approval/procurement/my-applications', params)
},
/**
*
*/
withdrawProcurementApplication(approvalId: string) {
return http.post(`/equipment/approval/procurement/${approvalId}/withdraw`)
}
}

View File

@ -74,9 +74,9 @@
</template>
<script setup lang="ts">
import { Modal } from '@arco-design/web-vue'
import { Modal, Notification } from '@arco-design/web-vue'
import { useFullscreen } from '@vueuse/core'
import { onMounted, ref, nextTick } from 'vue'
import { onMounted, ref, nextTick, onBeforeUnmount } from 'vue'
import Message from './Message.vue'
import SettingDrawer from './SettingDrawer.vue'
import Search from './Search.vue'
@ -116,29 +116,61 @@ const initWebSocket = (token: string) => {
}
try {
socket = new WebSocket(`${import.meta.env.VITE_API_WS_URL}/websocket?token=${token}`)
const wsUrl = import.meta.env.VITE_API_WS_URL || 'ws://localhost:8888'
console.log('正在连接WebSocket:', `${wsUrl}/websocket?token=${token}`)
socket = new WebSocket(`${wsUrl}/websocket?token=${token}`)
socket.onopen = () => {
// console.log('WebSocket connection opened')
console.log('WebSocket连接成功')
}
socket.onmessage = (event) => {
const count = Number.parseInt(event.data)
if (!isNaN(count)) {
unreadMessageCount.value = count
console.log('收到WebSocket消息:', event.data)
try {
const data = JSON.parse(event.data)
//
if (data.type && data.title && data.content) {
console.log('处理通知消息:', data)
//
Notification.info({
title: data.title,
content: data.content,
duration: 5000,
closable: true,
position: 'topRight'
})
//
unreadMessageCount.value++
} else {
//
const count = Number.parseInt(event.data)
if (!isNaN(count)) {
unreadMessageCount.value = count
}
}
} catch (error) {
console.error('解析WebSocket消息失败:', error)
//
const count = Number.parseInt(event.data)
if (!isNaN(count)) {
unreadMessageCount.value = count
}
}
}
socket.onerror = () => {
// console.error('WebSocket error:', error)
socket.onerror = (error) => {
console.error('WebSocket连接错误:', error)
}
socket.onclose = () => {
// console.log('WebSocket connection closed')
socket.onclose = (event) => {
console.log('WebSocket连接关闭:', event.code, event.reason)
socket = null
}
} catch (error) {
console.error('Failed to create WebSocket connection:', error)
console.error('创建WebSocket连接失败:', error)
}
initTimer = null

View File

@ -57,6 +57,7 @@ declare global {
const useCssVars: typeof import('vue')['useCssVars']
const useId: typeof import('vue')['useId']
const useLink: typeof import('vue-router')['useLink']
const useModel: typeof import('vue')['useModel']
const useRoute: typeof import('vue-router')['useRoute']
const useRouter: typeof import('vue-router')['useRouter']
const useSlots: typeof import('vue')['useSlots']

1
src/types/env.d.ts vendored
View File

@ -4,6 +4,7 @@
interface ImportMetaEnv {
readonly VITE_API_PREFIX: string
readonly VITE_API_BASE_URL: string
readonly VITE_API_WS_URL: string
readonly VITE_BASE: string
readonly VITE_APP_SETTING: string
readonly VITE_CLIENT_ID: string