|
@@ -17,9 +17,9 @@ import { rewriteLegacyHrMenus } from '@/utils/menu-rewrite';
|
|
|
|
|
|
|
|
Vue.use(VueRouter);
|
|
Vue.use(VueRouter);
|
|
|
|
|
|
|
|
-// 与 EOM/WT 一致:
|
|
|
|
|
-// - 乾坤嵌入:base = /page-{SYSTEM_NAME}/(对应主应用 activeRule)
|
|
|
|
|
-// - 独立运行:base = /{SYSTEM_NAME}/(对应 publicPath /hr)
|
|
|
|
|
|
|
+// 与 EOM 一致:
|
|
|
|
|
+// - WT 内浏览器路径:/page-hr/xxxx(同 page-eos/home/index)
|
|
|
|
|
+// - 独立运行:/hr/xxxx(同 /eos/,对应 publicPath)
|
|
|
const routerOptions = {
|
|
const routerOptions = {
|
|
|
base: window.__POWERED_BY_QIANKUN__
|
|
base: window.__POWERED_BY_QIANKUN__
|
|
|
? `/page-${SYSTEM_NAME}/`
|
|
? `/page-${SYSTEM_NAME}/`
|
|
@@ -56,7 +56,7 @@ function registerMenuRoutes(menus, homePath, authoritiesRouter = []) {
|
|
|
router.addRoute(
|
|
router.addRoute(
|
|
|
getMenuRoutes(
|
|
getMenuRoutes(
|
|
|
[...nextMenus, ...nextAuth],
|
|
[...nextMenus, ...nextAuth],
|
|
|
- homePath || HOME_PATH || '/home',
|
|
|
|
|
|
|
+ homePath || HOME_PATH || '/home/index',
|
|
|
),
|
|
),
|
|
|
);
|
|
);
|
|
|
dynamicRoutesReady = true;
|
|
dynamicRoutesReady = true;
|
|
@@ -72,17 +72,19 @@ router.beforeEach((to, from, next) => {
|
|
|
NProgress.start();
|
|
NProgress.start();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const homePath = HOME_PATH || '/home/index';
|
|
|
|
|
+
|
|
|
if (getToken()) {
|
|
if (getToken()) {
|
|
|
// 已登录访问登录页:直接进首页,避免停在空白态
|
|
// 已登录访问登录页:直接进首页,避免停在空白态
|
|
|
if (to.path === '/login') {
|
|
if (to.path === '/login') {
|
|
|
- next({ path: HOME_PATH || '/home', replace: true });
|
|
|
|
|
|
|
+ next({ path: homePath, replace: true });
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 旧首页别名统一跳到 /home,避免再开「首页」可关闭页签
|
|
|
|
|
- if (isHomeAliasPath(to.path) && to.path !== (HOME_PATH || '/home')) {
|
|
|
|
|
|
|
+ // 旧首页别名统一跳到 /home/index,避免再开「首页」可关闭页签
|
|
|
|
|
+ if (isHomeAliasPath(to.path) && to.path !== homePath) {
|
|
|
next({
|
|
next({
|
|
|
- path: HOME_PATH || '/home',
|
|
|
|
|
|
|
+ path: homePath,
|
|
|
query: to.query,
|
|
query: to.query,
|
|
|
hash: to.hash,
|
|
hash: to.hash,
|
|
|
replace: true,
|
|
replace: true,
|
|
@@ -93,14 +95,18 @@ router.beforeEach((to, from, next) => {
|
|
|
if (store.state.user.menus == null) {
|
|
if (store.state.user.menus == null) {
|
|
|
store
|
|
store
|
|
|
.dispatch('user/fetchUserInfo')
|
|
.dispatch('user/fetchUserInfo')
|
|
|
- .then(({ menus, homePath, authoritiesRouter }) => {
|
|
|
|
|
- // 与 EOM 一致:有菜单则注册;无菜单也要挂布局+首页,并标记已加载避免死循环
|
|
|
|
|
|
|
+ .then(({ menus, homePath: menuHome, authoritiesRouter }) => {
|
|
|
registerMenuRoutes(
|
|
registerMenuRoutes(
|
|
|
menus || [],
|
|
menus || [],
|
|
|
- homePath || HOME_PATH || '/home',
|
|
|
|
|
|
|
+ menuHome || homePath,
|
|
|
authoritiesRouter || [],
|
|
authoritiesRouter || [],
|
|
|
);
|
|
);
|
|
|
- next({ ...to, replace: true });
|
|
|
|
|
|
|
+ // 根路径必须落到首页,否则只有布局、子路由空白
|
|
|
|
|
+ const targetPath =
|
|
|
|
|
+ to.path === LAYOUT_PATH || to.path === '/'
|
|
|
|
|
+ ? homePath
|
|
|
|
|
+ : to.fullPath;
|
|
|
|
|
+ next({ path: targetPath, replace: true });
|
|
|
})
|
|
})
|
|
|
.catch((e) => {
|
|
.catch((e) => {
|
|
|
console.error(e);
|
|
console.error(e);
|
|
@@ -117,10 +123,18 @@ router.beforeEach((to, from, next) => {
|
|
|
if (!dynamicRoutesReady) {
|
|
if (!dynamicRoutesReady) {
|
|
|
registerMenuRoutes(
|
|
registerMenuRoutes(
|
|
|
store.state.user.menus,
|
|
store.state.user.menus,
|
|
|
- HOME_PATH || '/home',
|
|
|
|
|
|
|
+ homePath,
|
|
|
store.state.user.authoritiesRouter || [],
|
|
store.state.user.authoritiesRouter || [],
|
|
|
);
|
|
);
|
|
|
- next({ ...to, replace: true });
|
|
|
|
|
|
|
+ const targetPath =
|
|
|
|
|
+ to.path === LAYOUT_PATH || to.path === '/' ? homePath : to.fullPath;
|
|
|
|
|
+ next({ path: targetPath, replace: true });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 动态路由已就绪时,访问 / 仍强制进首页
|
|
|
|
|
+ if (to.path === LAYOUT_PATH || to.path === '/') {
|
|
|
|
|
+ next({ path: homePath, replace: true });
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|