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

View File

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