This commit is contained in:
zk
2024-06-27 11:26:55 +08:00
parent 778e350959
commit 752405b9a4
4 changed files with 72 additions and 10 deletions
+22 -1
View File
@@ -5,6 +5,7 @@ import { getBaseLogin, PageEnum } from '/@/enum/pageEnum.ts';
import { getAuthCache, setAuthCache } from '/@/utils/auth.ts';
import { useRouter } from 'vue-router';
import { LoginInfo, LoginParams, UserInfo } from '/@/store/modules/storeType.ts';
import { store } from '/@/store';
const router = useRouter();
export const useUserStore = defineStore({
@@ -15,6 +16,8 @@ export const useUserStore = defineStore({
//登录返回信息
loginInfo: null,
themeType: '', // dark 1, light 2
flag1: null, //银川权限标识
flag2: null, //西安权限标识
}),
getters: {
getUserInfo(): UserInfo {
@@ -29,6 +32,12 @@ export const useUserStore = defineStore({
getThemeType(): string {
return this.themeType || getAuthCache('themeType');
},
getFlag1(): string {
return this.flag1 || getAuthCache('flag1');
},
getFlag2(): string {
return this.flag2 || getAuthCache('flag2');
},
},
actions: {
setToken(info: string | undefined) {
@@ -46,6 +55,14 @@ export const useUserStore = defineStore({
this.themeType = info ? info : '';
setAuthCache('themeType', info);
},
setFlag1(info: string | undefined) {
this.flag1 = info ? info : '';
setAuthCache('flag1', info);
},
setFlag2(info: string | undefined) {
this.flag2 = info ? info : '';
setAuthCache('flag2', info);
},
/**
* 登录事件
*/
@@ -57,7 +74,7 @@ export const useUserStore = defineStore({
// save token
this.setToken(token, false);
this.setUserInfo(userInfo);
return { userInfo };
return { userInfo, token };
} catch (error) {
return Promise.reject(error);
}
@@ -108,3 +125,7 @@ export const useUserStore = defineStore({
},
},
});
export function useUserStoreWithOut() {
return useUserStore(store);
}