Merge remote-tracking branch 'origin/feature/0905_登录注册流程重构' into test
# Conflicts: # src/App.vue # src/layouts/components/siderBar/menu-list.ts # src/views/components/login/index.vue
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
import { fetchEnterpriseInfo } from '@/api/all/login';
|
||||
import { useSidebarStore } from '@/stores/modules/side-bar';
|
||||
import { useUserStore } from '@/stores/modules/user';
|
||||
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
|
||||
import { glsWithCatch, slsWithCatch } from '@/utils/stroage';
|
||||
|
||||
interface EnterpriseInfo {
|
||||
id: number | string;
|
||||
@ -11,6 +9,8 @@ interface EnterpriseInfo {
|
||||
sub_account_quota: number;
|
||||
used_sub_account_count: number;
|
||||
permissions: string[];
|
||||
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface EnterpriseState {
|
||||
@ -21,6 +21,12 @@ export const useEnterpriseStore = defineStore('enterprise', {
|
||||
state: (): EnterpriseState => ({
|
||||
enterpriseInfo: (glsWithCatch('enterpriseInfo') && JSON.parse(glsWithCatch('enterpriseInfo') as string)) || null,
|
||||
}),
|
||||
getters: {
|
||||
// 企业已开通/试用中
|
||||
isOpenEnterprise(): boolean {
|
||||
return [1, 2].includes(this.enterpriseInfo?.subscribe_status);
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
|
||||
this.enterpriseInfo = enterpriseInfo;
|
||||
|
||||
@ -1,111 +1,122 @@
|
||||
import router from '@/router';
|
||||
import { defineStore } from 'pinia';
|
||||
import { fetchProfileInfo } from '@/api/all/login';
|
||||
import { useSidebarStore } from '@/stores/modules/side-bar';
|
||||
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
|
||||
|
||||
interface UserInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
head_image: String;
|
||||
current_enterprise_id: number;
|
||||
mobile: string;
|
||||
// 添加其他用户属性...
|
||||
}
|
||||
|
||||
interface UserState {
|
||||
token: string;
|
||||
userInfo: UserInfo | null;
|
||||
// allowAccessRoutes: string[];
|
||||
// isLogin: boolean;
|
||||
}
|
||||
|
||||
interface UserInfo {
|
||||
id: number;
|
||||
mobile: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: (): UserState => ({
|
||||
token: glsWithCatch('accessToken') || '',
|
||||
userInfo: (glsWithCatch('userInfo') && JSON.parse(glsWithCatch('userInfo') as string)) || null,
|
||||
// allowAccessRoutes:
|
||||
// (glsWithCatch('allowAccessRoutes') && JSON.parse(glsWithCatch('allowAccessRoutes') as string)) || [], // 允许访问的路由列表
|
||||
}),
|
||||
getters: {
|
||||
isLogin(): boolean {
|
||||
return !!this.token;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
// 设置 Token
|
||||
setToken(token: string) {
|
||||
this.token = `Bearer ${token}`;
|
||||
slsWithCatch('accessToken', this.token);
|
||||
},
|
||||
|
||||
clearToken() {
|
||||
this.token = '';
|
||||
rlsWithCatch('accessToken');
|
||||
},
|
||||
|
||||
// 获取 Token
|
||||
getToken() {
|
||||
return this.token;
|
||||
},
|
||||
|
||||
// 设置用户信息
|
||||
setUserInfo(userInfo: UserInfo | null) {
|
||||
this.userInfo = userInfo;
|
||||
slsWithCatch('userInfo', JSON.stringify(userInfo));
|
||||
},
|
||||
clearUserInfo() {
|
||||
this.userInfo = null;
|
||||
rlsWithCatch('userInfo');
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
async getUserInfo() {
|
||||
const { code, data } = await fetchProfileInfo();
|
||||
if (code === 200) {
|
||||
this.setUserInfo(data);
|
||||
}
|
||||
},
|
||||
// clearUserAllowAccessRoutes() {
|
||||
// this.allowAccessRoutes = [];
|
||||
// rlsWithCatch('allowAccessRoutes');
|
||||
// },
|
||||
// getUserAllowAccessRoutes() {
|
||||
// const sidebarStore = useSidebarStore();
|
||||
// const menuList = sidebarStore.menuList;
|
||||
// const appRoutes = router.getRoutes();
|
||||
|
||||
// appRoutes.forEach((route: any) => {
|
||||
// if (!route.meta?.requiresAuth) {
|
||||
// this.allowAccessRoutes.push(route.name);
|
||||
// }
|
||||
// });
|
||||
|
||||
// const pushAllowAccessRoutes = (includeRouteNames: string[]) => {
|
||||
// const matchedRoute = appRoutes
|
||||
// .filter((route: any) => includeRouteNames.includes(route.name))
|
||||
// .map((route: any) => route.name);
|
||||
// this.allowAccessRoutes.push(...matchedRoute);
|
||||
// };
|
||||
|
||||
// menuList.forEach((item) => {
|
||||
// if (item.children && item.children.length > 0) {
|
||||
// item.children.forEach((child: any) => {
|
||||
// pushAllowAccessRoutes(child.includeRouteNames);
|
||||
// });
|
||||
// } else {
|
||||
// pushAllowAccessRoutes(item.includeRouteNames);
|
||||
// }
|
||||
// });
|
||||
|
||||
// this.allowAccessRoutes = uniq(this.allowAccessRoutes);
|
||||
// slsWithCatch('allowAccessRoutes', JSON.stringify(this.allowAccessRoutes));
|
||||
// },
|
||||
},
|
||||
});
|
||||
import { defineStore } from 'pinia';
|
||||
import { fetchProfileInfo } from '@/api/all/login';
|
||||
// import { useSidebarStore } from '@/stores/modules/side-bar';
|
||||
import { glsWithCatch, rlsWithCatch, slsWithCatch } from '@/utils/stroage';
|
||||
import { useEnterpriseStore } from '@/stores/modules/enterprise';
|
||||
|
||||
interface UserInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
head_image: String;
|
||||
current_enterprise_id: number;
|
||||
mobile: string;
|
||||
primary_enterprise: any; // 主企业信息
|
||||
[key: string]: any;
|
||||
|
||||
// 添加其他用户属性...
|
||||
}
|
||||
|
||||
interface UserState {
|
||||
token: string;
|
||||
userInfo: UserInfo | null;
|
||||
// allowAccessRoutes: string[];
|
||||
// isLogin: boolean;
|
||||
}
|
||||
|
||||
interface UserInfo {
|
||||
id: number;
|
||||
mobile: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: (): UserState => ({
|
||||
token: glsWithCatch('accessToken') || '',
|
||||
userInfo: (glsWithCatch('userInfo') && JSON.parse(glsWithCatch('userInfo') as string)) || null,
|
||||
// allowAccessRoutes:
|
||||
// (glsWithCatch('allowAccessRoutes') && JSON.parse(glsWithCatch('allowAccessRoutes') as string)) || [], // 允许访问的路由列表
|
||||
}),
|
||||
getters: {
|
||||
isLogin(): boolean {
|
||||
return !!this.token;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
// 设置 Token
|
||||
setToken(token: string) {
|
||||
this.token = `Bearer ${token}`;
|
||||
slsWithCatch('accessToken', this.token);
|
||||
},
|
||||
|
||||
clearToken() {
|
||||
this.token = '';
|
||||
rlsWithCatch('accessToken');
|
||||
},
|
||||
|
||||
// 获取 Token
|
||||
getToken() {
|
||||
return this.token;
|
||||
},
|
||||
|
||||
// 设置用户信息
|
||||
setUserInfo(userInfo: UserInfo | null) {
|
||||
this.userInfo = userInfo;
|
||||
slsWithCatch('userInfo', JSON.stringify(userInfo));
|
||||
},
|
||||
clearUserInfo() {
|
||||
this.userInfo = null;
|
||||
rlsWithCatch('userInfo');
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
async getUserInfo() {
|
||||
const enterpriseStore = useEnterpriseStore();
|
||||
|
||||
const { code, data } = await fetchProfileInfo();
|
||||
if (code === 200) {
|
||||
this.setUserInfo(data);
|
||||
|
||||
const { primary_enterprise } = data;
|
||||
|
||||
if (!enterpriseStore.enterpriseInfo && !isEmpty(primary_enterprise)) {
|
||||
enterpriseStore.setEnterpriseInfo(primary_enterprise);
|
||||
}
|
||||
}
|
||||
},
|
||||
// clearUserAllowAccessRoutes() {
|
||||
// this.allowAccessRoutes = [];
|
||||
// rlsWithCatch('allowAccessRoutes');
|
||||
// },
|
||||
// getUserAllowAccessRoutes() {
|
||||
// const sidebarStore = useSidebarStore();
|
||||
// const menuList = sidebarStore.menuList;
|
||||
// const appRoutes = router.getRoutes();
|
||||
|
||||
// appRoutes.forEach((route: any) => {
|
||||
// if (!route.meta?.requiresAuth) {
|
||||
// this.allowAccessRoutes.push(route.name);
|
||||
// }
|
||||
// });
|
||||
|
||||
// const pushAllowAccessRoutes = (includeRouteNames: string[]) => {
|
||||
// const matchedRoute = appRoutes
|
||||
// .filter((route: any) => includeRouteNames.includes(route.name))
|
||||
// .map((route: any) => route.name);
|
||||
// this.allowAccessRoutes.push(...matchedRoute);
|
||||
// };
|
||||
|
||||
// menuList.forEach((item) => {
|
||||
// if (item.children && item.children.length > 0) {
|
||||
// item.children.forEach((child: any) => {
|
||||
// pushAllowAccessRoutes(child.includeRouteNames);
|
||||
// });
|
||||
// } else {
|
||||
// pushAllowAccessRoutes(item.includeRouteNames);
|
||||
// }
|
||||
// });
|
||||
|
||||
// this.allowAccessRoutes = uniq(this.allowAccessRoutes);
|
||||
// slsWithCatch('allowAccessRoutes', JSON.stringify(this.allowAccessRoutes));
|
||||
// },
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user