1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- const { Router } = require('express');
- const gaf = require('./gaf');
- const user = require('./user');
- const app = require('./app');
- const authorize = require('./authorize');
- const link = require('./link');
- const router = Router();
- const navDatas = [
- {
- title: '用户管理',
- path: '/xms',
- module: '@user',
- },
- {
- title: '授权管理',
- path: '/xms',
- module: '@authorize',
- },
- {
- title: '应用管理',
- path: '/xms',
- module: '@app',
- },
- {
- title: '系统管理',
- path: '/gaf',
- module: '@gaf',
- },
- // ...link,
- ];
- const transItems = (items, pid) =>
- items.map((p, i) => {
- p.pid = pid || '0';
- p.id = p.id || (pid ? `${pid}-${i + 1}` : `${i + 1}`);
- if (p.children && p.children.length > 0) p.children = transItems(p.children, p.id);
- return p;
- });
- const datas = transItems([...user, ...authorize, ...app, ...gaf]);
- const MapMenu = (catalog = [], module = undefined) => item => ({
- title: item.title,
- options: {
- icon: item.icon,
- path: `/${item.module || module}${item.path}`,
- url: item.url,
- target: item.target,
- tooltip: item.tooltip,
- module: item.module,
- platform: item.platform,
- roles: item.roels,
- tags: item.tags,
- meta: { catalog: catalog.concat(item.title) },
- },
- children: (item.children || []).map(MapMenu(catalog.concat(item.title), item.module || module)),
- });
- const menus = datas.map(MapMenu());
- const modules = navDatas.map(MapMenu());
- /* GET menus define. */
- router.get('/menu/load', function(req, res, next) {
- console.log("!!!I'm menu/load!!!");
- res.json({ errcode: 0, errmsg: 'ok', data: { items: menus, modules } });
- });
- // router.get('/menu/:module', function(req, res, next) {
- // const module = req.params.module;
- // const items = menus.filter(p => p.options.module == module);
- // res.json({ errcode: 0, errmsg: 'ok', data: { items, modules } });
- // });
- router.get('/menu/items', function(req, res, next) {
- res.json({ errcode: 0, errmsg: 'ok', data: datas });
- });
- router.get('/menu/menus', function(req, res, next) {
- res.json({ errcode: 0, errmsg: 'ok', data: navDatas });
- });
- router.get('/menu/:module/items', function(req, res, next) {
- const module = req.params.module;
- const items = datas.filter(p => p.options.module == module);
- res.json({ errcode: 0, errmsg: 'ok', data: items });
- });
- module.exports = router;
|