| 1234567891011121314151617181920212223242526272829303132333435363738 |
- import { defineStore } from 'pinia'
- import { useVisitedRowState } from './visitedRow'
- interface UserState {
- username: string
- isFirstLogin: boolean
- }
- export const useUserStore = defineStore('user', {
- state: (): UserState => ({
- username: localStorage.getItem('username') || '',
- isFirstLogin: localStorage.getItem('isFirstLogin')
- ? JSON.parse(localStorage.getItem('isFirstLogin'))
- : false
- }),
- getters: {},
- actions: {
- setUsername(username: any, isFirstLogin?: boolean) {
- localStorage.setItem('username', username)
- this.username = username
- if (isFirstLogin !== undefined) {
- localStorage.setItem('isFirstLogin', JSON.stringify(isFirstLogin))
- this.isFirstLogin = isFirstLogin
- }
- },
- async logout(isNeedLogout: boolean = true) {
- if (isNeedLogout) {
- await $api.logout().then(() => {})
- }
- localStorage.removeItem('username')
- this.username = ''
- if (localStorage.getItem('isFirstLogin')) {
- localStorage.removeItem('isFirstLogin')
- }
- this.isFirstLogin = false
- useVisitedRowState().clearVisitedRow()
- }
- }
- })
|