vue-vben-admin/mock/sys/menu.ts

223 lines
4.6 KiB
TypeScript
Raw Normal View History

import { resultSuccess, resultError, getRequestToken, requestParams } from '../_util';
2020-09-28 20:19:10 +08:00
import { MockMethod } from 'vite-plugin-mock';
import { createFakeUserList } from './user';
2020-09-28 20:19:10 +08:00
2020-12-03 21:49:32 +08:00
// single
2020-09-28 20:19:10 +08:00
const dashboardRoute = {
path: '/dashboard',
name: 'Welcome',
component: '/dashboard/analysis/index',
meta: {
title: 'routes.dashboard.analysis',
2020-12-03 21:49:32 +08:00
affix: true,
2020-12-08 00:22:55 +08:00
icon: 'bx:bx-home',
2020-09-28 20:19:10 +08:00
},
};
const backRoute = {
2020-12-03 21:49:32 +08:00
path: 'back',
2020-09-28 20:19:10 +08:00
name: 'PermissionBackDemo',
meta: {
2020-12-03 21:49:32 +08:00
title: 'routes.demo.permission.back',
2020-09-28 20:19:10 +08:00
},
2020-12-03 21:49:32 +08:00
2020-09-28 20:19:10 +08:00
children: [
{
path: 'page',
2020-12-01 21:33:32 +08:00
name: 'BackAuthPage',
2020-11-08 23:13:47 +08:00
component: '/demo/permission/back/index',
2020-09-28 20:19:10 +08:00
meta: {
2020-12-03 21:49:32 +08:00
title: 'routes.demo.permission.backPage',
2020-09-28 20:19:10 +08:00
},
},
{
path: 'btn',
2020-12-01 21:33:32 +08:00
name: 'BackAuthBtn',
2020-11-08 23:13:47 +08:00
component: '/demo/permission/back/Btn',
2020-09-28 20:19:10 +08:00
meta: {
2020-12-03 21:49:32 +08:00
title: 'routes.demo.permission.backBtn',
2020-09-28 20:19:10 +08:00
},
},
],
};
const authRoute = {
path: '/permission',
name: 'Permission',
2020-12-03 21:49:32 +08:00
component: 'LAYOUT',
redirect: '/permission/front/page',
meta: {
2020-12-03 21:49:32 +08:00
icon: 'carbon:user-role',
title: 'routes.demo.permission.permission',
2020-09-28 20:19:10 +08:00
},
children: [backRoute],
2020-09-28 20:19:10 +08:00
};
2020-12-03 21:49:32 +08:00
const levelRoute = {
path: '/level',
name: 'Level',
component: 'LAYOUT',
redirect: '/level/menu1/menu1-1',
meta: {
icon: 'carbon:user-role',
title: 'routes.demo.level.level',
},
children: [
{
path: 'menu1',
name: 'Menu1Demo',
meta: {
title: 'Menu1',
},
children: [
{
path: 'menu1-1',
name: 'Menu11Demo',
meta: {
title: 'Menu1-1',
},
children: [
{
path: 'menu1-1-1',
name: 'Menu111Demo',
component: '/demo/level/Menu111',
meta: {
title: 'Menu111',
},
},
],
},
{
path: 'menu1-2',
name: 'Menu12Demo',
component: '/demo/level/Menu12',
meta: {
title: 'Menu1-2',
},
},
],
},
{
path: 'menu2',
name: 'Menu2Demo',
component: '/demo/level/Menu2',
meta: {
title: 'Menu2',
},
},
],
};
const sysRoute = {
path: '/system',
name: 'System',
component: 'LAYOUT',
redirect: '/system/account',
meta: {
icon: 'ion:settings-outline',
title: 'routes.demo.system.moduleName',
},
children: [
{
path: 'account',
name: 'AccountManagement',
meta: {
title: 'routes.demo.system.account',
ignoreKeepAlive: true,
},
component: '/demo/system/account/index',
},
{
path: 'role',
name: 'RoleManagement',
meta: {
title: 'routes.demo.system.role',
ignoreKeepAlive: true,
},
component: '/demo/system/role/index',
},
{
path: 'menu',
name: 'MenuManagement',
meta: {
title: 'routes.demo.system.menu',
ignoreKeepAlive: true,
},
component: '/demo/system/menu/index',
},
{
path: 'dept',
name: 'DeptManagement',
meta: {
title: 'routes.demo.system.dept',
ignoreKeepAlive: true,
},
component: '/demo/system/dept/index',
},
{
path: 'changePassword',
name: 'ChangePassword',
meta: {
title: 'routes.demo.system.password',
ignoreKeepAlive: true,
},
component: '/demo/system/password/index',
},
],
};
const linkRoute = {
path: '/link',
name: 'Link',
component: 'LAYOUT',
meta: {
icon: 'ion:tv-outline',
title: 'routes.demo.iframe.frame',
},
children: [
{
path: 'doc',
name: 'Doc',
meta: {
title: 'routes.demo.iframe.doc',
frameSrc: 'https://vvbin.cn/doc-next/',
},
},
{
path: 'https://vvbin.cn/doc-next/',
name: 'DocExternal',
component: 'LAYOUT',
meta: {
title: 'routes.demo.iframe.docExternal',
},
},
],
};
2020-09-28 20:19:10 +08:00
export default [
{
url: '/basic-api/getMenuList',
2020-09-28 20:19:10 +08:00
timeout: 1000,
method: 'get',
response: (request: requestParams) => {
const token = getRequestToken(request);
if (!token) {
return resultError('Invalid token!');
}
const checkUser = createFakeUserList().find((item) => item.token === token);
if (!checkUser) {
return resultError('Invalid user token!');
}
const id = checkUser.userId;
2020-09-28 20:19:10 +08:00
if (!id || id === '1') {
return resultSuccess([dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute]);
2020-09-28 20:19:10 +08:00
}
if (id === '2') {
return resultSuccess([dashboardRoute, authRoute, levelRoute, linkRoute]);
2020-09-28 20:19:10 +08:00
}
},
},
] as MockMethod[];