-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30e4214
commit 77c962e
Showing
11 changed files
with
125 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,4 @@ export interface UserType { | |
password: string | ||
role: string | ||
roleId: string | ||
permissions: string | string[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { defineStore } from 'pinia' | ||
import { store } from '../index' | ||
import { UserType } from '@/api/login/types' | ||
import { ElMessageBox } from 'element-plus' | ||
import { useI18n } from '@/hooks/web/useI18n' | ||
import { loginOutApi } from '@/api/login' | ||
import { useTagsViewStore } from './tagsView' | ||
import router from '@/router' | ||
|
||
interface UserState { | ||
userInfo?: UserType | ||
tokenKey: string | ||
token: string | ||
roleRouters?: string[] | AppCustomRouteRecordRaw[] | ||
} | ||
|
||
export const useUserStore = defineStore('user', { | ||
state: (): UserState => { | ||
return { | ||
userInfo: undefined, | ||
tokenKey: 'Token', | ||
token: '', | ||
roleRouters: undefined | ||
} | ||
}, | ||
getters: { | ||
getTokenKey(): string { | ||
return this.tokenKey | ||
}, | ||
getToken(): string { | ||
return this.token | ||
}, | ||
getUserInfo(): UserType | undefined { | ||
return this.userInfo | ||
}, | ||
getRoleRouters(): string[] | AppCustomRouteRecordRaw[] | undefined { | ||
return this.roleRouters | ||
} | ||
}, | ||
actions: { | ||
setTokenKey(tokenKey: string) { | ||
this.tokenKey = tokenKey | ||
}, | ||
setToken(token: string) { | ||
this.token = token | ||
}, | ||
setUserInfo(userInfo?: UserType) { | ||
this.userInfo = userInfo | ||
}, | ||
setRoleRouters(roleRouters: string[] | AppCustomRouteRecordRaw[]) { | ||
this.roleRouters = roleRouters | ||
}, | ||
logoutConfirm() { | ||
const { t } = useI18n() | ||
ElMessageBox.confirm(t('common.loginOutMessage'), t('common.reminder'), { | ||
confirmButtonText: t('common.ok'), | ||
cancelButtonText: t('common.cancel'), | ||
type: 'warning' | ||
}) | ||
.then(async () => { | ||
const res = await loginOutApi().catch(() => {}) | ||
if (res) { | ||
this.reset() | ||
} | ||
}) | ||
.catch(() => {}) | ||
}, | ||
reset() { | ||
const tagsViewStore = useTagsViewStore() | ||
tagsViewStore.delAllViews() | ||
this.setToken('') | ||
this.setUserInfo(undefined) | ||
this.setRoleRouters([]) | ||
router.replace('/login') | ||
}, | ||
logout() { | ||
this.reset() | ||
} | ||
}, | ||
persist: true | ||
}) | ||
|
||
export const useUserStoreWithOut = () => { | ||
return useUserStore(store) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters