/** 已知区域:标题 → 展示元数据(顺序即首页优先展示序) */ const REGION_DEFS = [ { match: '市场部', key: 'market', title: '市场部', hint: '存储现场', tone: 'market' }, { match: 'OA工作流', key: 'oa', title: 'OA工作流', hint: '审批协同', tone: 'oa' } ] const OTHER = { key: 'other', title: '其他', hint: '', tone: 'other' } export function resolveRegionMeta(groupTitle) { const name = String(groupTitle || '').trim() if (!name) return { ...OTHER } const found = REGION_DEFS.find((d) => d.match === name) if (found) { return { key: found.key, title: found.title, hint: found.hint, tone: found.tone } } return { key: `custom:${name}`, title: name, hint: '', tone: 'other' } } /** * 按 groupTitle 聚合成区域;已知区域按 REGION_DEFS 顺序,其余按首次出现顺序排在后面。 * @param {Array<{ groupTitle?: string }>} menus */ export function groupMenusByRegion(menus) { const list = Array.isArray(menus) ? menus : [] if (!list.length) return [] const buckets = new Map() for (const menu of list) { const meta = resolveRegionMeta(menu && menu.groupTitle) const key = meta.key if (!buckets.has(key)) { buckets.set(key, { ...meta, menus: [] }) } buckets.get(key).menus.push(menu) } const ordered = [] for (const def of REGION_DEFS) { if (buckets.has(def.key)) { ordered.push(buckets.get(def.key)) buckets.delete(def.key) } } for (const region of buckets.values()) { ordered.push(region) } return ordered }