34 lines
983 B
TypeScript
34 lines
983 B
TypeScript
|
|
import { defineStore } from 'pinia'
|
||
|
|
import { DETECTION_LOCK_STORE_KEY } from '@/stores/constant'
|
||
|
|
|
||
|
|
export interface DetectionLockHolder {
|
||
|
|
holderUserId: string
|
||
|
|
holderUserName: string
|
||
|
|
acquireTime: string
|
||
|
|
expireAt: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export const useDetectionLockStore = defineStore(DETECTION_LOCK_STORE_KEY, {
|
||
|
|
state: () => ({
|
||
|
|
iAmHolder: false,
|
||
|
|
holder: null as DetectionLockHolder | null
|
||
|
|
}),
|
||
|
|
actions: {
|
||
|
|
setAsHolder(holder?: Partial<DetectionLockHolder> | null) {
|
||
|
|
this.iAmHolder = true
|
||
|
|
if (holder) {
|
||
|
|
this.holder = {
|
||
|
|
holderUserId: holder.holderUserId ?? '',
|
||
|
|
holderUserName: holder.holderUserName ?? '',
|
||
|
|
acquireTime: holder.acquireTime ?? '',
|
||
|
|
expireAt: holder.expireAt ?? ''
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
clearHolder() {
|
||
|
|
this.iAmHolder = false
|
||
|
|
this.holder = null
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|