Blame view

mock/sys/menu.ts 5.89 KB
1
import { resultSuccess, resultError, getRequestToken, requestParams } from '../_util';
陈文彬 authored
2
import { MockMethod } from 'vite-plugin-mock';
3
import { createFakeUserList } from './user';
陈文彬 authored
4
vben authored
5
// single
陈文彬 authored
6
const dashboardRoute = {
7
  path: '/dashboard',
8
9
10
  name: 'Dashboard',
  component: 'LAYOUT',
  redirect: '/dashboard/analysis',
11
  meta: {
12
13
    title: 'routes.dashboard.dashboard',
    hideChildrenInMenu: true,
陈小婷 authored
14
    icon: 'bx:bx-home',
陈文彬 authored
15
  },
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  children: [
    {
      path: 'analysis',
      name: 'Analysis',
      component: '/dashboard/analysis/index',
      meta: {
        hideMenu: true,
        hideBreadcrumb: true,
        title: 'routes.dashboard.analysis',
        currentActiveMenu: '/dashboard',
        icon: 'bx:bx-home',
      },
    },
    {
      path: 'workbench',
      name: 'Workbench',
      component: '/dashboard/workbench/index',
      meta: {
        hideMenu: true,
        hideBreadcrumb: true,
        title: 'routes.dashboard.workbench',
        currentActiveMenu: '/dashboard',
        icon: 'bx:bx-home',
      },
    },
  ],
陈文彬 authored
42
43
44
};

const backRoute = {
vben authored
45
  path: 'back',
陈文彬 authored
46
47
  name: 'PermissionBackDemo',
  meta: {
vben authored
48
    title: 'routes.demo.permission.back',
陈文彬 authored
49
  },
vben authored
50
陈文彬 authored
51
52
53
  children: [
    {
      path: 'page',
vben authored
54
      name: 'BackAuthPage',
55
      component: '/demo/permission/back/index',
陈文彬 authored
56
      meta: {
vben authored
57
        title: 'routes.demo.permission.backPage',
陈文彬 authored
58
59
60
61
      },
    },
    {
      path: 'btn',
vben authored
62
      name: 'BackAuthBtn',
63
      component: '/demo/permission/back/Btn',
陈文彬 authored
64
      meta: {
vben authored
65
        title: 'routes.demo.permission.backBtn',
陈文彬 authored
66
67
68
69
70
      },
    },
  ],
};
71
const authRoute = {
72
73
  path: '/permission',
  name: 'Permission',
vben authored
74
  component: 'LAYOUT',
75
76
  redirect: '/permission/front/page',
  meta: {
vben authored
77
78
    icon: 'carbon:user-role',
    title: 'routes.demo.permission.permission',
陈文彬 authored
79
  },
80
  children: [backRoute],
陈文彬 authored
81
};
vben authored
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

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',
      },
    },
  ],
};
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

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',
    },
    {
159
160
161
162
163
164
165
166
167
168
169
170
      path: 'account_detail/:id',
      name: 'AccountDetail',
      meta: {
        hideMenu: true,
        title: 'routes.demo.system.account_detail',
        ignoreKeepAlive: true,
        showMenu: false,
        currentActiveMenu: '/system/account',
      },
      component: '/demo/system/account/AccountDetail',
    },
    {
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
      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',
    },
  ],
};
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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',
      },
    },
  ],
};
陈文彬 authored
238
239
export default [
  {
240
    url: '/basic-api/getMenuList',
陈文彬 authored
241
242
    timeout: 1000,
    method: 'get',
243
244
245
246
247
248
249
250
251
252
    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;
253
254
255
256
257
258
259
260
261
262
263
264
      let menu: Object[];
      switch (id) {
        case '1':
          dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[0].path;
          menu = [dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute];
          break;
        case '2':
          dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[1].path;
          menu = [dashboardRoute, authRoute, levelRoute, linkRoute];
          break;
        default:
          menu = [];
陈文彬 authored
265
      }
266
267

      return resultSuccess(menu);
陈文彬 authored
268
269
270
    },
  },
] as MockMethod[];