feat(detection): 添加检测锁机制防止多用户同时操作
- 新增 detectionLock store 管理检测锁状态 - 实现检测锁相关的弹窗提示功能 - 添加 DETECTION_BUSY 错误码处理多人竞争逻辑 - 在 websocket 中集成检测锁超时处理 - 修改程序源控制接口以同步锁状态 - 更新项目标题和图标配置 - 添加 docs 目录到忽略列表
This commit is contained in:
@@ -12,6 +12,12 @@ import { type ResultData } from '@/api/interface'
|
||||
import { ResultEnum } from '@/enums/httpEnum'
|
||||
import { checkStatus } from './helper/checkStatus'
|
||||
import { useUserStore } from '@/stores/modules/user'
|
||||
import { useDetectionLockStore, type DetectionLockHolder } from '@/stores/modules/detectionLock'
|
||||
import {
|
||||
showForceReleasedDialog,
|
||||
showLockBusyDialog,
|
||||
showLockNotStartedToast
|
||||
} from '@/utils/detectionLockDialog'
|
||||
import router from '@/routers'
|
||||
import { refreshToken } from '@/api/user/login'
|
||||
import { EventSourcePolyfill } from 'event-source-polyfill'
|
||||
@@ -107,6 +113,32 @@ class RequestHttp {
|
||||
}
|
||||
return Promise.reject(data)
|
||||
}
|
||||
// 单用户检测互斥:命中 DETECTION_BUSY 时根据 data 和本地持锁状态分发到 4 种文案
|
||||
if (data.code === ResultEnum.DETECTION_BUSY) {
|
||||
const lockStore = useDetectionLockStore()
|
||||
const holder = (data.data ?? null) as DetectionLockHolder | null
|
||||
const currentUserId = userStore.userInfo?.id
|
||||
const localDetecting = lockStore.iAmHolder
|
||||
|
||||
if (!localDetecting && holder) {
|
||||
// S1:他人持锁
|
||||
showLockBusyDialog(holder)
|
||||
} else if (!localDetecting && !holder) {
|
||||
// S2:未开始检测就调中间接口
|
||||
showLockNotStartedToast()
|
||||
} else if (localDetecting && holder && holder.holderUserId !== currentUserId) {
|
||||
// S4-a:被强释 + 别人接手
|
||||
showForceReleasedDialog(holder)
|
||||
lockStore.clearHolder()
|
||||
} else if (localDetecting && !holder) {
|
||||
// S4-b:被强释,无人接手
|
||||
showForceReleasedDialog(null)
|
||||
lockStore.clearHolder()
|
||||
}
|
||||
// 阻断默认错误提示,不再走下面的 ElMessage.error
|
||||
return Promise.reject(data)
|
||||
}
|
||||
|
||||
// 全局错误信息拦截(防止下载文件的时候返回数据流,没有 code 直接报错)
|
||||
if (data.code && data.code !== ResultEnum.SUCCESS) {
|
||||
if (data.message.includes('&')) {
|
||||
|
||||
Reference in New Issue
Block a user