feat: 系统首次使用引导标记

This commit is contained in:
TsMask
2024-04-19 19:51:01 +08:00
parent 399bddc635
commit 845084f77f
2 changed files with 36 additions and 26 deletions

View File

@@ -142,16 +142,26 @@ router.afterEach((to, from, failure) => {
});
/**无Token可访问页面地址白名单 */
const WHITE_LIST: string[] = ['/login', '/auth-redirect', '/help', '/register', '/quick-build'];
const WHITE_LIST: string[] = [
'/login',
'/auth-redirect',
'/help',
'/register',
'/quick-build',
];
/**全局路由-前置守卫 */
router.beforeEach((to, from, next) => {
router.beforeEach(async (to, from, next) => {
NProgress.start();
const token = getToken();
// 获取系统配置信息
const appStore = useAppStore();
if (!appStore.loginBackground) {
appStore.fnSysConf();
await appStore.fnSysConf();
console.log(to.path);
if (appStore.sysGuide && to.path !== '/quick-build') {
next({ name: 'QuickBuild' });
}
}
// 没有token
@@ -174,13 +184,11 @@ router.beforeEach((to, from, next) => {
// 判断当前用户是否有角色信息
const user = useUserStore();
if (user.roles && user.roles.length === 0) {
try {
// 获取用户信息
user
.fnGetInfo()
.then(() => {
return useRouterStore().generateRoutes();
})
.then(accessRoutes => {
await user.fnGetInfo();
// 获取路由信息
const accessRoutes = await useRouterStore().generateRoutes();
// 根据后台配置生成可访问的路由表
if (accessRoutes && accessRoutes.length !== 0) {
for (const route of accessRoutes) {
@@ -192,13 +200,11 @@ router.beforeEach((to, from, next) => {
}
// 刷新替换原先路由确保addRoutes已完成
next({ ...to, replace: true });
})
.catch(e => {
console.error(`[${to.path}]: ${e.message}`);
user.fnLogOut().finally(() => {
} catch (error: any) {
console.error(`[${to.path}]: ${error.message}`);
await user.fnLogOut();
next({ name: 'Login' });
});
});
}
} else {
next();
}

View File

@@ -17,6 +17,8 @@ type AppStore = {
/**服务版本 */
version: string;
buildTime: string;
/**系统首次使用 */
sysGuide: boolean;
// 序列号
serialNum: string;
/**应用版权声明 */
@@ -48,6 +50,7 @@ const useAppStore = defineStore('app', {
version: `-`,
buildTime: `-`,
sysGuide: false,
serialNum: `-`,
copyright: `Copyright ©2023 For ${import.meta.env.VITE_APP_NAME}`,
logoType: 'icon',
@@ -80,6 +83,7 @@ const useAppStore = defineStore('app', {
if (res.code === RESULT_CODE_SUCCESS && res.data) {
this.version = res.data.version;
this.buildTime = res.data.buildTime;
this.sysGuide = res.data.sysGuide === 'true';
this.serialNum = res.data.serialNum;
this.appName = res.data.title;
this.copyright = res.data.copyright;