feat(detection): 添加检测锁机制防止多用户同时操作
- 新增 detectionLock store 管理检测锁状态 - 实现检测锁相关的弹窗提示功能 - 添加 DETECTION_BUSY 错误码处理多人竞争逻辑 - 在 websocket 中集成检测锁超时处理 - 修改程序源控制接口以同步锁状态 - 更新项目标题和图标配置 - 添加 docs 目录到忽略列表
This commit is contained in:
15
frontend/src/api/detection/lock.ts
Normal file
15
frontend/src/api/detection/lock.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import http from '@/api'
|
||||
import type { DetectionLockHolder } from '@/stores/modules/detectionLock'
|
||||
|
||||
/**
|
||||
* 查询当前检测锁持有状态
|
||||
* - data 为 null → 锁空闲
|
||||
* - data 非 null → 锁被某账号持有
|
||||
*
|
||||
* 本接口只读,不抢锁、不会返回 DETECTION_BUSY
|
||||
*/
|
||||
export const getCurrentLock = () => {
|
||||
return http.get<DetectionLockHolder | null>('/detection/lock/current', undefined, {
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
import type { controlSource } from '@/api/device/interface/controlSource'
|
||||
import http from '@/api'
|
||||
import { useDetectionLockStore } from '@/stores/modules/detectionLock'
|
||||
|
||||
/**
|
||||
* @name 程控源管理模块
|
||||
@@ -17,8 +18,11 @@ export const startSimulateTest = (params: controlSource.ResControl) => {
|
||||
}
|
||||
|
||||
//停止
|
||||
export const closeSimulateTest = (params: controlSource.ResControl) => {
|
||||
return http.post(`/prepare/closeSimulateTest`,params,{loading:false})
|
||||
export const closeSimulateTest = async (params: controlSource.ResControl) => {
|
||||
const result = await http.post(`/prepare/closeSimulateTest`,params,{loading:false})
|
||||
// 主动终止 → 释放本地持锁标记
|
||||
useDetectionLockStore().clearHolder()
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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('&')) {
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import http from '@/api'
|
||||
import { useDetectionLockStore } from '@/stores/modules/detectionLock'
|
||||
|
||||
|
||||
export const startPreTest = (params) => {
|
||||
return http.post(`/prepare/startPreTest`, params, {loading: false})
|
||||
export const startPreTest = async (params) => {
|
||||
const result = await http.post(`/prepare/startPreTest`, params, {loading: false})
|
||||
// 抢锁成功 → 标记本地为持锁者
|
||||
useDetectionLockStore().setAsHolder()
|
||||
return result
|
||||
}
|
||||
|
||||
export const closePreTest = (params) => {
|
||||
@@ -37,8 +41,11 @@ export const resumeTest = (params) => {
|
||||
* 比对式通道配对
|
||||
* @param params
|
||||
*/
|
||||
export const contrastTest = (params: any) => {
|
||||
return http.post(`/prepare/startContrastTest`,params)
|
||||
export const contrastTest = async (params: any) => {
|
||||
const result = await http.post(`/prepare/startContrastTest`, params)
|
||||
// 抢锁成功 → 标记本地为持锁者
|
||||
useDetectionLockStore().setAsHolder()
|
||||
return result
|
||||
}
|
||||
|
||||
export const exportAlignData= () => {
|
||||
|
||||
Reference in New Issue
Block a user