Bläddra i källkod

路由错乱的问题

ZGC4846 5 dagar sedan
förälder
incheckning
64e34c9444
5 ändrade filer med 59 tillägg och 147 borttagningar
  1. 3 4
      src/api/hr/offer.js
  2. 6 17
      src/main.js
  3. 12 53
      src/router/index.js
  4. 37 72
      src/store/modules/user.js
  5. 1 1
      src/views/hiring/hiringApproval/index.vue

+ 3 - 4
src/api/hr/offer.js

@@ -161,16 +161,15 @@ export function serializeOffer(form = {}) {
   const sendMode = String(
     form.sendMode || (online ? "ONLINE" : "OFFLINE"),
   ).toUpperCase();
-  const signingMethod = String(form.signingMethod || sendMode).toUpperCase();
+  // 暂时写死为线下签署,后续再按表单 signingMethod 回传
+  const signingMethod = "OFFLINE";
   const probationFlag = Number(form.probationFlag ?? 0) === 1 ? 1 : 0;
   const sealRequired =
     form.sealRequired != null
       ? Number(form.sealRequired) === 1
         ? 1
         : 0
-      : signingMethod === "ONLINE"
-        ? 1
-        : 0;
+      : 0;
   const probationMonths =
     probationFlag === 1 ? Number(form.probationMonths || 0) || undefined : undefined;
   const reminderIntervalHours =

+ 6 - 17
src/main.js

@@ -3,12 +3,12 @@ import Vue from 'vue';
 import EleAdmin from 'ele-admin';
 import VueClipboard from 'vue-clipboard2';
 import App from './App.vue';
-import router, { resetRouter, getAppRouterBase } from './router';
+import router, { resetRouter } from './router';
 import store from './store';
 import permission from './utils/permission';
 import initParentStore from '../qiankun_config/store';
 import i18n from './i18n';
-import { MAP_KEY, LICENSE_CODE } from '@/config/setting';
+import { MAP_KEY, LICENSE_CODE, SYSTEM_NAME } from '@/config/setting';
 import { installMessageGuard } from '@/utils/message';
 import HeaderTitle from '@/components/header-title';
 import DictSelection from '@/components/Dict/DictSelection';
@@ -106,7 +106,7 @@ export async function mount(props) {
   console.log('[page-hr] props from main framework', props);
   Vue.prototype.$portalStore = props.store;
 
-  // 与 EOM 一致:同步门户主题/用户;不立即 fire,避免用首个系统状态覆盖
+  // 与 EOM 一致:只同步主题/用户,绝不改门户 menus
   initParentStore(props.store?.state || props.store);
   if (typeof props.onGlobalStateChange === 'function') {
     props.onGlobalStateChange((state) => {
@@ -114,26 +114,15 @@ export async function mount(props) {
     });
   }
 
-  // 确保路由 base 为 /page-hr/(防止模块加载时乾坤标记未就绪)
+  // 乾坤下强制校正 router base 为 /page-hr/
   if (
-    getAppRouterBase().includes('page-hr') &&
-    !String(router.options?.base || '').includes('page-hr')
+    window.__POWERED_BY_QIANKUN__ &&
+    !String(router.options?.base || '').includes(`page-${SYSTEM_NAME}`)
   ) {
     resetRouter();
   }
 
   render(props);
-
-  // 接口菜单拉取成功后会 sync 到门户;这里再补几次,挡住主应用异步回写
-  const pushMenus = () => {
-    if (!String(window.location.pathname || '').includes('/page-hr')) return;
-    const menus = store.state.user.menus;
-    if (menus?.length) {
-      Vue.prototype.$portalStore?.commit('user/setMenus', menus);
-    }
-  };
-  setTimeout(pushMenus, 300);
-  setTimeout(pushMenus, 1000);
 }
 
 export async function unmount() {

+ 12 - 53
src/router/index.js

@@ -20,22 +20,14 @@ import { rewriteLegacyHrMenus } from '@/utils/menu-rewrite';
 
 Vue.use(VueRouter);
 
-/** 运行时计算 base,避免模块加载时 __POWERED_BY_QIANKUN__ 尚未注入 */
+/**
+ * 乾坤:/page-hr/(同 EOM 的 /page-eos/)
+ * 独立:/hr/(同 EOM 的 /eos/)
+ */
 export function getAppRouterBase() {
-  const pageBase = `/page-${SYSTEM_NAME}/`;
-  const shortBase = `/${SYSTEM_NAME}/`;
-  if (window.__POWERED_BY_QIANKUN__) {
-    return pageBase;
-  }
-  try {
-    const path = window.location?.pathname || '';
-    if (path === `/page-${SYSTEM_NAME}` || path.startsWith(pageBase)) {
-      return pageBase;
-    }
-  } catch (e) {
-    /* ignore */
-  }
-  return shortBase;
+  return window.__POWERED_BY_QIANKUN__
+    ? `/page-${SYSTEM_NAME}/`
+    : `/${SYSTEM_NAME}/`;
 }
 
 function createRouter() {
@@ -51,36 +43,20 @@ function createRouter() {
 
 const router = createRouter();
 
-/** 动态路由是否已挂到当前 matcher */
 let dynamicRoutesReady = false;
 
-/** 重新登录 / 切角色前清空动态路由 */
 export function resetRouter() {
   const newRouter = createRouter();
   router.matcher = newRouter.matcher;
-  // 同步 options.base,避免后续跳转仍用旧 base
   router.options.base = newRouter.options.base;
   dynamicRoutesReady = false;
 }
 
-/** 乾坤下把本系统菜单写回门户,防止被主应用默认/首个系统菜单覆盖 */
-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);
-  }
-}
-
 function registerMenuRoutes(menus, homePath, authoritiesRouter = []) {
   const nextMenus = rewriteLegacyHrMenus(menus || []);
   const nextAuth = rewriteLegacyHrMenus(authoritiesRouter || []);
   store.commit('user/setMenus', nextMenus);
   store.commit('user/setAuthoritiesRouter', nextAuth);
-  // 接口拉到的菜单注册时同步写回门户
-  syncMenusToPortal(nextMenus);
-  // 与 EOM 一致:有菜单才注册
   if (nextMenus.length || nextAuth.length) {
     router.addRoute(
       getMenuRoutes(
@@ -92,23 +68,19 @@ function registerMenuRoutes(menus, homePath, authoritiesRouter = []) {
   dynamicRoutesReady = true;
 }
 
-/** 供登录页等外部主动注册动态路由 */
 export function setupDynamicRoutes(menus, homePath, authoritiesRouter = []) {
   resetRouter();
   registerMenuRoutes(menus, homePath, authoritiesRouter);
 }
 
-/**
- * 路由守卫(对齐 EOM:fetch 后 next({ ...to }),不强制改写地址栏)
- */
 router.beforeEach((to, from, next) => {
   if (!from.path.includes(REDIRECT_PATH)) {
     NProgress.start();
   }
 
   if (getToken()) {
-    // 旧首页别名统一到 HOME_PATH
     const homePath = HOME_PATH || '/home/index';
+
     if (isHomeAliasPath(to.path) && to.path !== homePath) {
       next({
         path: homePath,
@@ -119,12 +91,11 @@ router.beforeEach((to, from, next) => {
       return;
     }
 
-    // 还未注册动态路由则先获取(与 EOM:menus == null)
+    // 与 EOM:menus 未加载时拉取;有菜单才 addRoute
     if (store.state.user.menus == null) {
       store
         .dispatch('user/fetchUserInfo')
         .then(({ menus, homePath: menuHome, authoritiesRouter }) => {
-          // 与 EOM:有菜单才 addRoute;无菜单也 next,避免卡死
           if (menus?.length || authoritiesRouter?.length) {
             registerMenuRoutes(
               menus || [],
@@ -132,20 +103,9 @@ router.beforeEach((to, from, next) => {
               authoritiesRouter || [],
             );
           } else {
-            // 乾坤下接口暂无 /page-hr:沿用门户侧栏做路由,但不回写,
-            // 避免把主应用已错误覆盖的「第一个系统菜单」再次固化
-            const portalMenus =
-              Vue.prototype.$portalStore?.state?.user?.menus;
-            if (window.__POWERED_BY_QIANKUN__ && portalMenus?.length) {
-              store.commit(
-                'user/setMenus',
-                rewriteLegacyHrMenus(portalMenus),
-              );
-              dynamicRoutesReady = true;
-            } else {
-              store.commit('user/setMenus', []);
-              dynamicRoutesReady = true;
-            }
+            // 标记已尝试,避免死循环;乾坤下侧栏仍由门户管
+            store.commit('user/setMenus', menus || []);
+            dynamicRoutesReady = true;
           }
           next({ ...to, replace: true });
         })
@@ -156,7 +116,6 @@ router.beforeEach((to, from, next) => {
       return;
     }
 
-    // 有菜单但动态路由未就绪时补注册
     if (!dynamicRoutesReady && store.state.user.menus?.length) {
       registerMenuRoutes(
         store.state.user.menus,

+ 37 - 72
src/store/modules/user.js

@@ -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) {

+ 1 - 1
src/views/hiring/hiringApproval/index.vue

@@ -68,7 +68,7 @@
             <el-button v-if="canLaunch(row)" type="text" @click.stop="launchApproval(row)">提交审批</el-button>
             <el-button v-if="canApprove(row)" type="text" @click.stop="openApprove(row)">通过</el-button>
             <el-button v-if="canEdit(row)" type="text" @click.stop="openEdit(row)">编辑</el-button>
-            <el-button v-if="canLaunchOffer(row)" type="text" @click.stop="openOffer(row)">发起 Offer</el-button>
+            <el-button v-if="canLaunchOffer(row)" type="text" @click.stop="openOffer(row)">发起Offer</el-button>
           </template>
 
           <template slot="empty">