import { h } from 'vue' import { HomeOutlined, ShoppingCartOutlined, GatewayOutlined } from '@ant-design/icons-vue' const pages = [ { icon: () => h(HomeOutlined), path: '', name: '首页', isMenu: true }, { icon: () => h(ShoppingCartOutlined), path: '/Produce', name: '生产管理', children: [{ path: '/CompProduce', name: '组件生产', isMenu: true }, { path: '/BikeQRCode', name: '车辆二维码', isMenu: true }, { path: '/BatteryQRCode', name: '电池二维码', isMenu: true }, { path: '/HelmetQRCode', name: '头盔二维码', isMenu: true } ] }, { icon: () => h(GatewayOutlined), path: '/Urban', name: '城市管理', children: [{ path: '/OperateRegion', name: '运营区域', isMenu: true }, { path: '/OperateRegionAdd', name: '运营区新增', isMenu: false } ] } ] const modules = import.meta.glob('./views/**/*.vue'); const getRouters = () => { const routes = []; pages.forEach((item) => { let ipath = item.path; if (ipath === '') { ipath = '/Home'; } const component = modules['./views' + ipath + '/index.vue']; const route = { path: item.path, name: item.name, component: component, // 动态导入组件 }; if (item.children) { item.children.forEach((child) => { let cpath = ipath + child.path; route.children = route.children || []; const component = modules['./views' + cpath + '/index.vue']; route.children.push({ path: cpath, name: child.name, component: component, // 动态导入组件 }) }) }; routes.push(route); }); return routes; } const getMenus = () => { const menus = []; pages.forEach((item) => { let ipath = item.path; if (ipath === '') { ipath = '/'; } let ikey = item.key; if (ikey === undefined) { ikey = ipath.replace('/', '-').substring(1); if (ikey === '') { ikey = 'Home' } } const menu = { key: ikey, icon: item.icon, label: item.name, title: item.name, path: ipath } menus.push(menu) if (item.children) { item.children.forEach((child) => { let cpath = ipath + child.path; let ckey = child.key; if (ckey === undefined) { ckey = cpath.replace('/', '-').substring(1); if (ckey === '') { ckey = 'Home' } } menu.children = menu.children || []; if (child['isMenu']) { menu.children.push({ key: ckey, label: child.name, title: child.name, path: cpath }) } }) } }); return menus; } export { getRouters, getMenus };