committed by
GitHub
15 changed files with 93 additions and 77 deletions
@ -1,4 +1,3 @@ |
|||||
export * from './access'; |
export * from './access'; |
||||
export * from './lock'; |
|
||||
export * from './tabbar'; |
export * from './tabbar'; |
||||
export * from './user'; |
export * from './user'; |
||||
|
|||||
@ -1,31 +0,0 @@ |
|||||
import { createPinia, setActivePinia } from 'pinia'; |
|
||||
import { beforeEach, describe, expect, it } from 'vitest'; |
|
||||
|
|
||||
import { useLockStore } from './lock'; |
|
||||
|
|
||||
describe('useLockStore', () => { |
|
||||
beforeEach(() => { |
|
||||
setActivePinia(createPinia()); |
|
||||
}); |
|
||||
|
|
||||
it('should initialize with correct default state', () => { |
|
||||
const store = useLockStore(); |
|
||||
expect(store.isLockScreen).toBe(false); |
|
||||
expect(store.lockScreenPassword).toBeUndefined(); |
|
||||
}); |
|
||||
|
|
||||
it('should lock screen with a password', () => { |
|
||||
const store = useLockStore(); |
|
||||
store.lockScreen('1234'); |
|
||||
expect(store.isLockScreen).toBe(true); |
|
||||
expect(store.lockScreenPassword).toBe('1234'); |
|
||||
}); |
|
||||
|
|
||||
it('should unlock screen and clear password', () => { |
|
||||
const store = useLockStore(); |
|
||||
store.lockScreen('1234'); |
|
||||
store.unlockScreen(); |
|
||||
expect(store.isLockScreen).toBe(false); |
|
||||
expect(store.lockScreenPassword).toBeUndefined(); |
|
||||
}); |
|
||||
}); |
|
||||
@ -1,33 +0,0 @@ |
|||||
import { defineStore } from 'pinia'; |
|
||||
|
|
||||
interface AppState { |
|
||||
/** |
|
||||
* 是否锁屏状态 |
|
||||
*/ |
|
||||
isLockScreen: boolean; |
|
||||
/** |
|
||||
* 锁屏密码 |
|
||||
*/ |
|
||||
lockScreenPassword?: string; |
|
||||
} |
|
||||
|
|
||||
export const useLockStore = defineStore('core-lock', { |
|
||||
actions: { |
|
||||
lockScreen(password: string) { |
|
||||
this.isLockScreen = true; |
|
||||
this.lockScreenPassword = password; |
|
||||
}, |
|
||||
|
|
||||
unlockScreen() { |
|
||||
this.isLockScreen = false; |
|
||||
this.lockScreenPassword = undefined; |
|
||||
}, |
|
||||
}, |
|
||||
persist: { |
|
||||
pick: ['isLockScreen', 'lockScreenPassword'], |
|
||||
}, |
|
||||
state: (): AppState => ({ |
|
||||
isLockScreen: false, |
|
||||
lockScreenPassword: undefined, |
|
||||
}), |
|
||||
}); |
|
||||
Loading…
Reference in new issue