Blame view

mock/sys/menu.ts 4.65 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
  name: 'Welcome',
9
  component: '/dashboard/analysis/index',
10
  meta: {
11
    title: 'routes.dashboard.analysis',
vben authored
12
    affix: true,
陈小婷 authored
13
    icon: 'bx:bx-home',
陈文彬 authored
14
15
16
17
  },
};

const backRoute = {
vben authored
18
  path: 'back',
陈文彬 authored
19
20
  name: 'PermissionBackDemo',
  meta: {
vben authored
21
    title: 'routes.demo.permission.back',
陈文彬 authored
22
  },
vben authored
23
陈文彬 authored
24
25
26
  children: [
    {
      path: 'page',
vben authored
27
      name: 'BackAuthPage',
28
      component: '/demo/permission/back/index',
陈文彬 authored
29
      meta: {
vben authored
30
        title: 'routes.demo.permission.backPage',
陈文彬 authored
31
32
33
34
      },
    },
    {
      path: 'btn',
vben authored
35
      name: 'BackAuthBtn',
36
      component: '/demo/permission/back/Btn',
陈文彬 authored
37
      meta: {
vben authored
38
        title: 'routes.demo.permission.backBtn',
陈文彬 authored
39
40
41
42
43
      },
    },
  ],
};
44
const authRoute = {
45
46
  path: '/permission',
  name: 'Permission',
vben authored
47
  component: 'LAYOUT',
48
49
  redirect: '/permission/front/page',
  meta: {
vben authored
50
51
    icon: 'carbon:user-role',
    title: 'routes.demo.permission.permission',
陈文彬 authored
52
  },
53
  children: [backRoute],
陈文彬 authored
54
};
vben authored
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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

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',
      },
    },
  ],
};
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

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',
    },
  ],
};
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
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
199
200
export default [
  {
201
    url: '/basic-api/getMenuList',
陈文彬 authored
202
203
    timeout: 1000,
    method: 'get',
204
205
206
207
208
209
210
211
212
213
    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;
陈文彬 authored
214
      if (!id || id === '1') {
215
        return resultSuccess([dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute]);
陈文彬 authored
216
217
      }
      if (id === '2') {
218
        return resultSuccess([dashboardRoute, authRoute, levelRoute, linkRoute]);
陈文彬 authored
219
220
221
222
      }
    },
  },
] as MockMethod[];