完善审批台接收推送信息

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 http from '@/utils/http'
import type { EquipmentApprovalReq, EquipmentApprovalResp, EquipmentApprovalListReq } from './type' import type { EquipmentApprovalListReq, EquipmentApprovalResp } from './type'
/** /**
* API * API
*/ */
export const equipmentApprovalApi = { export const equipmentApprovalApi = {
/** /**
* *
*/ */
getPendingApprovals: (params: EquipmentApprovalListReq) => { getPendingApprovals(params: EquipmentApprovalListReq) {
return http.get<ApiRes<PageRes<EquipmentApprovalResp>>>('/equipment/approval/pending', { params }) return http.get<EquipmentApprovalResp[]>('/equipment/approval/pending', params)
}, },
/** /**
* *
*/ */
getApprovedApprovals: (params: EquipmentApprovalListReq) => { getApprovedApprovals(params: EquipmentApprovalListReq) {
return http.get<ApiRes<PageRes<EquipmentApprovalResp>>>('/equipment/approval/approved', { params }) return http.get<EquipmentApprovalResp[]>('/equipment/approval/approved', params)
}, },
/** /**
* *
*/ */
approve: (approvalId: string, data: EquipmentApprovalReq) => { approve(approvalId: string, data: any) {
return http.post<ApiRes<null>>(`/equipment/approval/${approvalId}/approve`, data) return http.post(`/equipment/approval/${approvalId}/approve`, data)
}, },
/** /**
* *
*/ */
reject: (approvalId: string, data: EquipmentApprovalReq) => { reject(approvalId: string, data: any) {
return http.post<ApiRes<null>>(`/equipment/approval/${approvalId}/reject`, data) return http.post(`/equipment/approval/${approvalId}/reject`, data)
}, },
/** /**
* *
*/ */
getApprovalDetail: (approvalId: string) => { getApprovalDetail(approvalId: string) {
return http.get<ApiRes<EquipmentApprovalResp>>(`/equipment/approval/${approvalId}`) return http.get<EquipmentApprovalResp>(`/equipment/approval/${approvalId}`)
}, },
/** /**
* *
*/ */
getApprovalStats: () => { getApprovalStats() {
return http.get<ApiRes<unknown>>('/equipment/approval/stats') 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> </template>
<script setup lang="ts"> <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 { useFullscreen } from '@vueuse/core'
import { onMounted, ref, nextTick } from 'vue' import { onMounted, ref, nextTick, onBeforeUnmount } from 'vue'
import Message from './Message.vue' import Message from './Message.vue'
import SettingDrawer from './SettingDrawer.vue' import SettingDrawer from './SettingDrawer.vue'
import Search from './Search.vue' import Search from './Search.vue'
@ -116,29 +116,61 @@ const initWebSocket = (token: string) => {
} }
try { 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 = () => { socket.onopen = () => {
// console.log('WebSocket connection opened') console.log('WebSocket连接成功')
} }
socket.onmessage = (event) => { socket.onmessage = (event) => {
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) const count = Number.parseInt(event.data)
if (!isNaN(count)) { if (!isNaN(count)) {
unreadMessageCount.value = count unreadMessageCount.value = count
} }
} }
socket.onerror = () => {
// console.error('WebSocket error:', error)
} }
socket.onclose = () => { socket.onerror = (error) => {
// console.log('WebSocket connection closed') console.error('WebSocket连接错误:', error)
}
socket.onclose = (event) => {
console.log('WebSocket连接关闭:', event.code, event.reason)
socket = null socket = null
} }
} catch (error) { } catch (error) {
console.error('Failed to create WebSocket connection:', error) console.error('创建WebSocket连接失败:', error)
} }
initTimer = null initTimer = null

View File

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

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

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