feat: 新增锁屏功能

This commit is contained in:
WuYihui
2023-05-10 10:12:31 +08:00
parent 46ac7f88c9
commit e2fd349070
11 changed files with 570 additions and 0 deletions

View File

@@ -1,8 +1,11 @@
import type { App } from 'vue'
import { createPinia } from 'pinia'
import piniaPersist from 'pinia-plugin-persist'
const store = createPinia()
store.use(piniaPersist)
export const setupStore = (app: App<Element>) => {
app.use(store)
}

51
src/store/modules/lock.ts Normal file
View File

@@ -0,0 +1,51 @@
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)
}