lock.ts 897 B

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