|
|
@@ -1,5 +1,5 @@
|
|
|
/**
|
|
|
- * 登录用户 / 菜单 / 权限(对齐 EOM)
|
|
|
+ * 登录用户 / 菜单 / 权限(对齐 EOM,不写门户 store)
|
|
|
*/
|
|
|
import { formatMenus, toTreeData, formatTreeData } from 'ele-admin';
|
|
|
import { USER_MENUS, SYSTEM_NAME, HOME_PATH } from '@/config/setting';
|
|
|
@@ -37,16 +37,6 @@ function buildLocalMenus() {
|
|
|
return formatMenus(JSON.parse(JSON.stringify(DEFAULT_MENUS)));
|
|
|
}
|
|
|
|
|
|
-/** 乾坤下同步侧栏菜单到门户 store(侧栏由主应用渲染) */
|
|
|
-function syncMenusToPortal(menus) {
|
|
|
- if (!window.__POWERED_BY_QIANKUN__ || !menus?.length) return;
|
|
|
- try {
|
|
|
- Vue.prototype.$portalStore?.commit('user/setMenus', menus);
|
|
|
- } catch (e) {
|
|
|
- console.warn('[page-hr] syncMenusToPortal failed', e);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
export default {
|
|
|
namespaced: true,
|
|
|
state: {
|
|
|
@@ -64,7 +54,6 @@ export default {
|
|
|
state.menus = menus == null ? menus : rewriteLegacyHrMenus(menus);
|
|
|
},
|
|
|
setAuthorities(state, authorities) {
|
|
|
- // 乾坤下门户可能下发 permissionCode 字符串数组,与 EOM 本地对象数组兼容
|
|
|
state.authorities = (authorities || []).map((item) =>
|
|
|
typeof item === 'string' ? item : item.permissionCode,
|
|
|
);
|
|
|
@@ -78,20 +67,11 @@ export default {
|
|
|
setRoles(state, roles) {
|
|
|
state.roles = roles;
|
|
|
},
|
|
|
- sanitizeMenus(state) {
|
|
|
- if (state.menus?.length) {
|
|
|
- state.menus = rewriteLegacyHrMenus(state.menus);
|
|
|
- }
|
|
|
- if (state.authoritiesRouter?.length) {
|
|
|
- state.authoritiesRouter = rewriteLegacyHrMenus(
|
|
|
- state.authoritiesRouter,
|
|
|
- );
|
|
|
- }
|
|
|
- },
|
|
|
},
|
|
|
actions: {
|
|
|
/**
|
|
|
- * 请求用户菜单:与 EOM 一致,按 `/page-{SYSTEM_NAME}` 过滤资源树
|
|
|
+ * 与 EOM 一致:只按 `/page-hr` 过滤,只写入本子应用 store。
|
|
|
+ * 切勿 commit 到 $portalStore —— 会污染门户顶栏/侧栏并丢掉 /page-hr 前缀。
|
|
|
*/
|
|
|
async fetchUserInfo({ commit }) {
|
|
|
const currentUser = getCurrentUser() || {};
|
|
|
@@ -113,64 +93,49 @@ export default {
|
|
|
(item) => item.path === APP_MENU_PATH,
|
|
|
);
|
|
|
|
|
|
- // 与 EOM 一致:有 /page-hr 节点时走接口菜单
|
|
|
- if (list?.length) {
|
|
|
- const { menuList, authorities } = formatRouter(list[0].children || []);
|
|
|
- commit('setAuthorities', authorities);
|
|
|
- const { menus, homePath } = formatMenus(
|
|
|
- USER_MENUS ??
|
|
|
- toTreeData({
|
|
|
- data: menuList,
|
|
|
- idField: 'id',
|
|
|
- parentIdField: 'parentId',
|
|
|
- }),
|
|
|
- );
|
|
|
- const { menus: authoritiesRouter } = formatMenus(
|
|
|
- USER_MENUS ??
|
|
|
- toTreeData({
|
|
|
- data: authorities.filter((item) => item.path),
|
|
|
- idField: 'id',
|
|
|
- parentIdField: 'parentId',
|
|
|
- }),
|
|
|
- );
|
|
|
- const nextMenus = rewriteLegacyHrMenus(menus || []);
|
|
|
- const nextAuth = rewriteLegacyHrMenus(authoritiesRouter || []);
|
|
|
+ if (!list?.length) {
|
|
|
+ // 乾坤下侧栏由门户按 /page-hr 自行切换;无节点时与 EOM 一样返回空
|
|
|
+ if (window.__POWERED_BY_QIANKUN__) {
|
|
|
+ return {};
|
|
|
+ }
|
|
|
+ const local = buildLocalMenus();
|
|
|
+ const nextMenus = rewriteLegacyHrMenus(local.menus || []);
|
|
|
commit('setMenus', nextMenus);
|
|
|
- commit('setAuthoritiesRouter', nextAuth);
|
|
|
- // 关键写门户侧栏,避免闪一下又变回第一个系统
|
|
|
- syncMenusToPortal(nextMenus);
|
|
|
+ commit('setAuthorities', []);
|
|
|
+ commit('setAuthoritiesRouter', []);
|
|
|
return {
|
|
|
menus: nextMenus,
|
|
|
- homePath: HOME_PATH || homePath || '/home/index',
|
|
|
- authoritiesRouter: nextAuth,
|
|
|
+ homePath: HOME_PATH || local.homePath || '/home/index',
|
|
|
+ authoritiesRouter: [],
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- // 乾坤下:接口暂无节点时沿用门户当前侧栏做本地路由,不回写门户
|
|
|
- if (window.__POWERED_BY_QIANKUN__) {
|
|
|
- const portalMenus = Vue.prototype.$portalStore?.state?.user?.menus;
|
|
|
- if (portalMenus?.length) {
|
|
|
- const nextMenus = rewriteLegacyHrMenus(portalMenus);
|
|
|
- commit('setMenus', nextMenus);
|
|
|
- return {
|
|
|
- menus: nextMenus,
|
|
|
- homePath: HOME_PATH || '/home/index',
|
|
|
- authoritiesRouter: [],
|
|
|
- };
|
|
|
- }
|
|
|
- return {};
|
|
|
- }
|
|
|
-
|
|
|
- // 独立运行且接口无 /page-hr 时本地兜底
|
|
|
- const local = buildLocalMenus();
|
|
|
- const nextMenus = rewriteLegacyHrMenus(local.menus || []);
|
|
|
+ const { menuList, authorities } = formatRouter(list[0].children || []);
|
|
|
+ commit('setAuthorities', authorities);
|
|
|
+ const { menus, homePath } = formatMenus(
|
|
|
+ USER_MENUS ??
|
|
|
+ toTreeData({
|
|
|
+ data: menuList,
|
|
|
+ idField: 'id',
|
|
|
+ parentIdField: 'parentId',
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ const { menus: authoritiesRouter } = formatMenus(
|
|
|
+ USER_MENUS ??
|
|
|
+ toTreeData({
|
|
|
+ data: authorities.filter((item) => item.path),
|
|
|
+ idField: 'id',
|
|
|
+ parentIdField: 'parentId',
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ const nextMenus = rewriteLegacyHrMenus(menus || []);
|
|
|
+ const nextAuth = rewriteLegacyHrMenus(authoritiesRouter || []);
|
|
|
commit('setMenus', nextMenus);
|
|
|
- commit('setAuthorities', []);
|
|
|
- commit('setAuthoritiesRouter', []);
|
|
|
+ commit('setAuthoritiesRouter', nextAuth);
|
|
|
return {
|
|
|
menus: nextMenus,
|
|
|
- homePath: HOME_PATH || local.homePath || '/home/index',
|
|
|
- authoritiesRouter: [],
|
|
|
+ homePath: HOME_PATH || homePath || '/home/index',
|
|
|
+ authoritiesRouter: nextAuth,
|
|
|
};
|
|
|
},
|
|
|
setInfo({ commit }, value) {
|