| | |
| | | 'menu.whMat': '库区物料关系' |
| | | } |
| | | |
| | | export function resolveBackendMenuTitle(title) { |
| | | if (typeof title !== 'string') { |
| | | const DASHBOARD_MENU_KEYS = new Set(['menus.dashboard.title', 'menus.dashboard.console']) |
| | | const BACKEND_MENU_TITLE_KEY_MAP = Object.entries(LEGACY_BACKEND_MENU_TITLES).reduce( |
| | | (accumulator, [key, value]) => { |
| | | accumulator[key] = key |
| | | accumulator[value] = key |
| | | return accumulator |
| | | }, |
| | | { |
| | | '仪表盘': 'menus.dashboard.title', |
| | | '工作台': 'menus.dashboard.console', |
| | | 'menus.dashboard.title': 'menus.dashboard.title', |
| | | 'menus.dashboard.console': 'menus.dashboard.console' |
| | | } |
| | | ) |
| | | |
| | | function normalizeComponentMenuKey(componentKey) { |
| | | if (typeof componentKey !== 'string') { |
| | | return '' |
| | | } |
| | | |
| | | const trimmedTitle = title.trim() |
| | | if (!trimmedTitle) { |
| | | const normalizedComponentKey = componentKey.trim() |
| | | if (!normalizedComponentKey) { |
| | | return '' |
| | | } |
| | | |
| | | if (LEGACY_BACKEND_MENU_TITLES[trimmedTitle]) { |
| | | return LEGACY_BACKEND_MENU_TITLES[trimmedTitle] |
| | | if (normalizedComponentKey === 'console') { |
| | | return 'menus.dashboard.console' |
| | | } |
| | | |
| | | if (trimmedTitle.startsWith('menus.')) { |
| | | const legacyMenuKey = `menu.${trimmedTitle.slice('menus.'.length)}` |
| | | if (LEGACY_BACKEND_MENU_TITLES[legacyMenuKey]) { |
| | | return LEGACY_BACKEND_MENU_TITLES[legacyMenuKey] |
| | | } |
| | | return trimmedTitle.split('.').pop() || trimmedTitle |
| | | } |
| | | |
| | | if (trimmedTitle.startsWith('menu.')) { |
| | | return trimmedTitle.split('.').pop() || trimmedTitle |
| | | } |
| | | |
| | | return trimmedTitle |
| | | return `menu.${normalizedComponentKey}` |
| | | } |
| | | |
| | | function normalizeMenuKey(menuKey) { |
| | | if (!menuKey) { |
| | | return '' |
| | | } |
| | | |
| | | if (DASHBOARD_MENU_KEYS.has(menuKey)) { |
| | | return menuKey |
| | | } |
| | | |
| | | if (menuKey.startsWith('menus.')) { |
| | | const leaf = menuKey.slice('menus.'.length) |
| | | const aliasKey = `menu.${leaf}` |
| | | if (Object.prototype.hasOwnProperty.call(LEGACY_BACKEND_MENU_TITLES, aliasKey)) { |
| | | return aliasKey |
| | | } |
| | | } |
| | | |
| | | return menuKey |
| | | } |
| | | |
| | | function containsHan(value) { |
| | | return /[\u3400-\u9fff]/.test(value) |
| | | } |
| | | |
| | | export function resolveBackendMenuTitle(title, componentKey = '') { |
| | | const trimmedTitle = typeof title === 'string' ? title.trim() : '' |
| | | |
| | | if (trimmedTitle) { |
| | | if (trimmedTitle.startsWith('menu.') || trimmedTitle.startsWith('menus.')) { |
| | | const normalizedExistingKey = normalizeMenuKey(trimmedTitle) |
| | | if (normalizedExistingKey) { |
| | | return normalizedExistingKey |
| | | } |
| | | } |
| | | |
| | | const mappedKey = BACKEND_MENU_TITLE_KEY_MAP[trimmedTitle] |
| | | if (mappedKey) { |
| | | return normalizeMenuKey(mappedKey) |
| | | } |
| | | } |
| | | |
| | | const componentMenuKey = normalizeMenuKey(normalizeComponentMenuKey(componentKey)) |
| | | if (componentMenuKey) { |
| | | return componentMenuKey |
| | | } |
| | | |
| | | if (trimmedTitle && !containsHan(trimmedTitle)) { |
| | | return trimmedTitle |
| | | } |
| | | |
| | | return '' |
| | | } |
| | | |
| | | export { LEGACY_BACKEND_MENU_TITLES } |