You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
975 B
TypeScript
52 lines
975 B
TypeScript
|
3 years ago
|
import { defineStore } from 'pinia'
|
||
|
|
import { store } from '../index'
|
||
|
|
|
||
|
|
interface lockInfo {
|
||
|
|
isLock?: boolean
|
||
|
|
password?: string
|
||
|
|
}
|
||
|
|
|
||
|
|
interface LockState {
|
||
|
|
lockInfo: lockInfo
|
||
|
|
}
|
||
|
|
|
||
|
|
export const useLockStore = defineStore('lock', {
|
||
|
|
state: (): LockState => {
|
||
|
|
return {
|
||
|
|
lockInfo: {
|
||
|
|
// isLock: false, // 是否锁定屏幕
|
||
|
|
// password: '' // 锁屏密码
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
getters: {
|
||
|
|
getLockInfo(): lockInfo {
|
||
|
|
return this.lockInfo
|
||
|
|
}
|
||
|
|
},
|
||
|
|
actions: {
|
||
|
|
setLockInfo(lockInfo: lockInfo) {
|
||
|
|
this.lockInfo = lockInfo
|
||
|
|
},
|
||
|
|
resetLockInfo() {
|
||
|
|
this.lockInfo = {}
|
||
|
|
},
|
||
|
|
unLock(password: string) {
|
||
|
|
if (this.lockInfo?.password === password) {
|
||
|
|
this.resetLockInfo()
|
||
|
|
return true
|
||
|
|
} else {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
persist: {
|
||
|
|
enabled: true,
|
||
|
|
strategies: [{ key: 'lock', storage: localStorage }]
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
export const useLockStoreWithOut = () => {
|
||
|
|
return useLockStore(store)
|
||
|
|
}
|