提交 | 用户 | 时间
|
820397
|
1 |
import { defineStore } from 'pinia' |
H |
2 |
import { store } from '@/store' |
|
3 |
|
|
4 |
interface lockInfo { |
|
5 |
isLock?: boolean |
|
6 |
password?: string |
|
7 |
} |
|
8 |
|
|
9 |
interface LockState { |
|
10 |
lockInfo: lockInfo |
|
11 |
} |
|
12 |
|
|
13 |
export const useLockStore = defineStore('lock', { |
|
14 |
state: (): LockState => { |
|
15 |
return { |
|
16 |
lockInfo: { |
|
17 |
// isLock: false, // 是否锁定屏幕 |
|
18 |
// password: '' // 锁屏密码 |
|
19 |
} |
|
20 |
} |
|
21 |
}, |
|
22 |
getters: { |
|
23 |
getLockInfo(): lockInfo { |
|
24 |
return this.lockInfo |
|
25 |
} |
|
26 |
}, |
|
27 |
actions: { |
|
28 |
setLockInfo(lockInfo: lockInfo) { |
|
29 |
this.lockInfo = lockInfo |
|
30 |
}, |
|
31 |
resetLockInfo() { |
|
32 |
this.lockInfo = {} |
|
33 |
}, |
|
34 |
unLock(password: string) { |
|
35 |
if (this.lockInfo?.password === password) { |
|
36 |
this.resetLockInfo() |
|
37 |
return true |
|
38 |
} else { |
|
39 |
return false |
|
40 |
} |
|
41 |
} |
|
42 |
}, |
|
43 |
persist: true |
|
44 |
}) |
|
45 |
|
|
46 |
export const useLockStoreWithOut = () => { |
|
47 |
return useLockStore(store) |
|
48 |
} |