feat:报表/管理菜单动态渲染
parent
d16f397336
commit
a97d9223b6
@ -0,0 +1,48 @@
|
||||
const DEFAULT_NAV_BACKGROUND = '#22486e'
|
||||
const DEFAULT_NAV_FRONT = '#ffffff'
|
||||
const LOGIN_NAV_BACKGROUND = '#ffffff'
|
||||
const LOGIN_NAV_FRONT = '#000000'
|
||||
|
||||
function getCurrentRoute() {
|
||||
try {
|
||||
const pages = getCurrentPages()
|
||||
if (!pages || pages.length === 0) return ''
|
||||
return pages[pages.length - 1]?.route || ''
|
||||
} catch (error) {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
function getNavigationTheme(route = '') {
|
||||
const currentRoute = route || getCurrentRoute()
|
||||
if (currentRoute === 'pages/login') {
|
||||
return {
|
||||
frontColor: LOGIN_NAV_FRONT,
|
||||
backgroundColor: LOGIN_NAV_BACKGROUND
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
frontColor: DEFAULT_NAV_FRONT,
|
||||
backgroundColor: DEFAULT_NAV_BACKGROUND
|
||||
}
|
||||
}
|
||||
|
||||
export function applyNavigationBarTheme(route = '') {
|
||||
const theme = getNavigationTheme(route)
|
||||
try {
|
||||
uni.setNavigationBarColor({
|
||||
frontColor: theme.frontColor,
|
||||
backgroundColor: theme.backgroundColor,
|
||||
animation: {
|
||||
duration: 0,
|
||||
timingFunc: 'linear'
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getDefaultNavigationBackground() {
|
||||
return DEFAULT_NAV_BACKGROUND
|
||||
}
|
||||
@ -0,0 +1,183 @@
|
||||
const DIRECT_ROUTE_PREFIXES = ['pages/', 'page_', 'pages_']
|
||||
|
||||
const MENU_ROUTE_MAP = {
|
||||
'生产任务': '/pages_function/pages/taskList/index',
|
||||
tasklist: '/pages_function/pages/taskList/index',
|
||||
'生产计划': '/pages_function/pages/planList/index',
|
||||
planlist: '/pages_function/pages/planList/index',
|
||||
'生产投料': '/page_record/feedingRecordForm',
|
||||
feedingrecordform: '/page_record/feedingRecordForm',
|
||||
'生产报工': '/page_report/reportForm',
|
||||
reportform: '/page_report/reportForm',
|
||||
'代报工': '/page_report/replaceForm',
|
||||
replaceform: '/page_report/replaceForm',
|
||||
'计划进度': '/page_report/planProgress',
|
||||
planprogress: '/page_report/planProgress',
|
||||
'仓库信息': '/pages_function/pages/warehouse/index',
|
||||
warehouse: '/pages_function/pages/warehouse/index',
|
||||
'检验类型': '/pages_function/pages/inspection/index',
|
||||
inspection: '/pages_function/pages/inspection/index',
|
||||
'检验项库': '/pages_function/pages/inspectionItem/index',
|
||||
inspectionitem: '/pages_function/pages/inspectionItem/index',
|
||||
moldinspectionitems: '/pages_function/pages/moldInspectionItems/index',
|
||||
'检验模板': '/pages_function/pages/inspectionTemplate/index',
|
||||
inspectiontemplate: '/pages_function/pages/inspectionTemplate/index',
|
||||
moldinspectionplan: '/pages_function/pages/moldInspectionPlan/index',
|
||||
'点检模板': '/pages_function/pages/moldInspectionPlan/index',
|
||||
'点检任务': '/pages_function/pages/moldTaskConfiguration/index',
|
||||
moldtaskconfiguration: '/pages_function/pages/moldTaskConfiguration/index',
|
||||
moldtaskconfig: '/pages_function/pages/moldTaskConfiguration/index',
|
||||
'点检记录': '/pages_function/pages/moldWorkOrderInquiry/index',
|
||||
moldworkorderinquiry: '/pages_function/pages/moldWorkOrderInquiry/index',
|
||||
'产品物料分类': '/pages_function/pages/materialCategory/index',
|
||||
materialcategory: '/pages_function/pages/materialCategory/index',
|
||||
'产品物料信息': '/pages_function/pages/materialInfo/index',
|
||||
materialinfo: '/pages_function/pages/materialInfo/index',
|
||||
'产品BOM': '/pages_function/pages/productBom/index',
|
||||
productbom: '/pages_function/pages/productBom/index',
|
||||
'设备分类': '/pages_function/pages/equipmentCategory/index',
|
||||
equipmentcategory: '/pages_function/pages/equipmentCategory/index',
|
||||
'设备台账': '/pages_function/pages/equipmentLedger/index',
|
||||
equipmentledger: '/pages_function/pages/equipmentLedger/index',
|
||||
'设备关键件': '/pages_function/pages/criticalComponent/index',
|
||||
criticalcomponent: '/pages_function/pages/criticalComponent/index',
|
||||
equipmentkeypart: '/pages_function/pages/equipmentKeypart/index',
|
||||
'模具类型': '/pages_function/pages/moldType/index',
|
||||
moldtype: '/pages_function/pages/moldType/index',
|
||||
'模具台账': '/pages_function/pages/moldLedger/index',
|
||||
moldledger: '/pages_function/pages/moldLedger/index',
|
||||
moldget: '/pages_function/pages/moldget/index',
|
||||
moldreturn: '/pages_function/pages/moldreturn/index',
|
||||
moldoperate: '/pages_function/pages/moldoperate/index',
|
||||
mold: '/pages_function/pages/mold/index',
|
||||
equipment: '/pages_function/pages/equipment/index',
|
||||
spare: '/pages_function/pages/spare/index',
|
||||
keypart: '/pages_function/pages/keypart/index',
|
||||
product: '/pages_function/pages/product/index'
|
||||
}
|
||||
|
||||
const HOME_KEYWORDS = ['首页', 'home', 'index', 'dashboard']
|
||||
const MODULE_COLORS = ['#1a3a5c', '#2d5a87', '#3d7ab5', '#ff8c00', '#18bc37', '#5aa0d2']
|
||||
const MENU_SYMBOLS = ['●', '■', '▲', '◆', '★', '▣']
|
||||
|
||||
function toArray(value) {
|
||||
return Array.isArray(value) ? value : []
|
||||
}
|
||||
|
||||
function normalizeMenuKey(value) {
|
||||
return String(value || '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/\/index$/i, '')
|
||||
.replace(/[^a-z0-9\u4e00-\u9fa5]/g, '')
|
||||
}
|
||||
|
||||
function getDirectRoute(value) {
|
||||
const route = String(value || '').trim().replace(/^\/+/, '')
|
||||
if (!route) return ''
|
||||
return DIRECT_ROUTE_PREFIXES.some((prefix) => route.startsWith(prefix)) ? `/${route}` : ''
|
||||
}
|
||||
|
||||
function looksLikeHomeMenu(menu) {
|
||||
const fields = [menu.name, menu.enName, menu.path, menu.component]
|
||||
.map((item) => String(item || '').toLowerCase())
|
||||
.join('|')
|
||||
return HOME_KEYWORDS.some((keyword) => fields.includes(keyword))
|
||||
}
|
||||
|
||||
function wrapGroupEntries(group) {
|
||||
const directChildren = toArray(group.children)
|
||||
const hasNestedEntries = directChildren.some((child) => toArray(child.children).length > 0)
|
||||
if (hasNestedEntries) {
|
||||
return directChildren
|
||||
.map((child) => ({
|
||||
...child,
|
||||
children: toArray(child.children)
|
||||
}))
|
||||
.filter((child) => child.children.length > 0)
|
||||
}
|
||||
if (directChildren.length === 0) {
|
||||
return []
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: `${group.id || group.name || 'group'}-entries`,
|
||||
name: group.name,
|
||||
children: directChildren
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
export function getTopLevelMenus(menus) {
|
||||
return toArray(menus).filter((menu) => menu && typeof menu === 'object')
|
||||
}
|
||||
|
||||
export function getDynamicTabMenus(menus) {
|
||||
return getTopLevelMenus(menus).filter((menu) => !looksLikeHomeMenu(menu))
|
||||
}
|
||||
|
||||
export function findTabMenuByPage(menus, pagePath) {
|
||||
const dynamicMenus = getDynamicTabMenus(menus)
|
||||
if (pagePath === 'pages/report') {
|
||||
return dynamicMenus[0] || null
|
||||
}
|
||||
if (pagePath === 'pages/work') {
|
||||
return dynamicMenus[1] || dynamicMenus[0] || null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function buildPageModules(tabMenu) {
|
||||
return toArray(tabMenu?.children)
|
||||
.map((module) => ({
|
||||
...module,
|
||||
groups: wrapGroupEntries(module)
|
||||
}))
|
||||
.filter((module) => module.groups.length > 0)
|
||||
}
|
||||
|
||||
export function resolveMenuUrl(menu) {
|
||||
const directRoute = getDirectRoute(menu?.path) || getDirectRoute(menu?.component)
|
||||
if (directRoute) {
|
||||
return directRoute
|
||||
}
|
||||
|
||||
const keys = [menu?.component, menu?.path, menu?.enName, menu?.name]
|
||||
for (const key of keys) {
|
||||
const normalizedKey = normalizeMenuKey(key)
|
||||
if (normalizedKey && MENU_ROUTE_MAP[normalizedKey]) {
|
||||
return MENU_ROUTE_MAP[normalizedKey]
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
export function getModuleColor(index) {
|
||||
return MODULE_COLORS[index % MODULE_COLORS.length]
|
||||
}
|
||||
|
||||
export function getMenuSymbol(name, index) {
|
||||
const trimmed = String(name || '').trim()
|
||||
if (trimmed) {
|
||||
return trimmed.slice(0, 1)
|
||||
}
|
||||
return MENU_SYMBOLS[index % MENU_SYMBOLS.length]
|
||||
}
|
||||
|
||||
export function syncTabBarMenus(menus, options = {}) {
|
||||
const dynamicMenus = getDynamicTabMenus(menus)
|
||||
const labels = [
|
||||
options.homeText || '首页',
|
||||
dynamicMenus[0]?.name || options.reportFallback || '报表',
|
||||
dynamicMenus[1]?.name || dynamicMenus[0]?.name || options.workFallback || '管理',
|
||||
options.mineText || '我的'
|
||||
]
|
||||
|
||||
labels.forEach((text, index) => {
|
||||
uni.setTabBarItem({
|
||||
index,
|
||||
text
|
||||
})
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue