吴羡
11 小时以前 1193ed5cf72c8d1093d0c061b9eefe61a28b0cb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const LOCK_KEY = 'screen-lock'
const LOCK_PATH_KEY = 'screen-lock-path'
 
export const useLockStore = defineStore('lock', {
  state: () => ({
    isLock: JSON.parse(localStorage.getItem(LOCK_KEY) || 'false'),
    lockPath: localStorage.getItem(LOCK_PATH_KEY) || '/index'
  }),
  actions: {
    // 锁定屏幕,同时记录当前路径
    lockScreen(currentPath) {
      this.lockPath = currentPath || '/index'
      localStorage.setItem(LOCK_PATH_KEY, this.lockPath)
      this.isLock = true
      localStorage.setItem(LOCK_KEY, 'true')
    },
    // 解锁屏幕,清除路径
    unlockScreen() {
      this.isLock = false
      localStorage.setItem(LOCK_KEY, 'false')
      this.lockPath = '/index'
      localStorage.setItem(LOCK_PATH_KEY, '/index')
    }
  }
})
 
export default useLockStore