menu.js 7.34 KB
Newer Older
xiaohu's avatar
xiaohu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 42 43 44 45 46 47 48 49 50 51 52 53 54 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 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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
// TODO:remove
// import { isUrl } from '../utils/utils';

// const menuData = [
//   {
//     name: 'dashboard',
//     icon: 'dashboard',
//     path: 'dashboard',
//     children: [
//       {
//         name: '分析页',
//         path: 'analysis',
//       },
//       {
//         name: '监控页',
//         path: 'monitor',
//       },
//       {
//         name: '工作台',
//         path: 'workplace',
//         // hideInBreadcrumb: true,
//         // hideInMenu: true,
//       },
//     ],
//   },
//   {
//     name: '表单页',
//     icon: 'form',
//     path: 'form',
//     children: [
//       {
//         name: '基础表单',
//         path: 'basic-form',
//       },
//       {
//         name: '分步表单',
//         path: 'step-form',
//       },
//       {
//         name: '高级表单',
//         authority: 'admin',
//         path: 'advanced-form',
//       },
//     ],
//   },
//   {
//     name: '列表页',
//     icon: 'table',
//     path: 'list',
//     children: [
//       {
//         name: '查询表格',
//         path: 'table-list',
//       },
//       {
//         name: '标准列表',
//         path: 'basic-list',
//       },
//       {
//         name: '卡片列表',
//         path: 'card-list',
//       },
//       {
//         name: '搜索列表',
//         path: 'search',
//         children: [
//           {
//             name: '搜索列表(文章)',
//             path: 'articles',
//           },
//           {
//             name: '搜索列表(项目)',
//             path: 'projects',
//           },
//           {
//             name: '搜索列表(应用)',
//             path: 'applications',
//           },
//         ],
//       },
//     ],
//   },
//   {
//     name: '详情页',
//     icon: 'profile',
//     path: 'profile',
//     children: [
//       {
//         name: '基础详情页',
//         path: 'basic',
//       },
//       {
//         name: '高级详情页',
//         path: 'advanced',
//         authority: 'admin',
//       },
//     ],
//   },
//   {
//     name: '结果页',
//     icon: 'check-circle-o',
//     path: 'result',
//     children: [
//       {
//         name: '成功',
//         path: 'success',
//       },
//       {
//         name: '失败',
//         path: 'fail',
//       },
//     ],
//   },
//   {
//     name: '异常页',
//     icon: 'warning',
//     path: 'exception',
//     children: [
//       {
//         name: '403',
//         path: '403',
//       },
//       {
//         name: '404',
//         path: '404',
//       },
//       {
//         name: '500',
//         path: '500',
//       },
//       {
//         name: '触发异常',
//         path: 'trigger',
//         hideInMenu: true,
//       },
//     ],
//   },
//   {
//     name: '账户',
//     icon: 'user',
//     path: 'user',
//     authority: 'guest',
//     children: [
//       {
//         name: '登录',
//         path: 'login',
//       },
//       {
//         name: '注册',
//         path: 'register',
//       },
//       {
//         name: '注册结果',
//         path: 'register-result',
//       },
//     ],
//   },
//   {
//     name: '个人页',
//     icon: 'user',
//     path: 'account',
//     children: [
//       {
//         name: '个人中心',
//         path: 'center',
//       },
//       {
//         name: '个人设置',
//         path: 'settings',
//       },
//     ],
//   },
// ];

// function formatter(data, parentPath = '/', parentAuthority) {
//   return data.map(item => {
//     let { path } = item;
//     if (!isUrl(path)) {
//       path = parentPath + item.path;
//     }
//     const result = {
//       ...item,
//       path,
//       authority: item.authority || parentAuthority,
//     };
//     if (item.children) {
//       result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
//     }
//     return result;
//   });
// }

// export const getMenuData = () => formatter(menuData);

195 196
import { isUrl } from '../utils/utils';

xiaohu's avatar
xiaohu committed
197
// TODO: authority
jim's avatar
jim committed
198 199 200 201
const menuData = [
  {
    name: 'dashboard',
    icon: 'dashboard',
愚道's avatar
愚道 committed
202
    path: 'dashboard',
jim's avatar
jim committed
203 204
    children: [
      {
陈帅's avatar
陈帅 committed
205
        name: 'analysis',
愚道's avatar
愚道 committed
206
        path: 'analysis',
jim's avatar
jim committed
207 208
      },
      {
陈帅's avatar
陈帅 committed
209
        name: 'monitor',
愚道's avatar
愚道 committed
210
        path: 'monitor',
jim's avatar
jim committed
211 212
      },
      {
陈帅's avatar
陈帅 committed
213
        name: 'workplace',
愚道's avatar
愚道 committed
214
        path: 'workplace',
xiaohu's avatar
xiaohu committed
215
        // hideInBreadcrumb: true,
jim's avatar
jim committed
216 217 218 219 220
        // hideInMenu: true,
      },
    ],
  },
  {
陈帅's avatar
陈帅 committed
221
    name: 'form',
jim's avatar
jim committed
222
    icon: 'form',
愚道's avatar
愚道 committed
223
    path: 'form',
jim's avatar
jim committed
224 225
    children: [
      {
陈帅's avatar
陈帅 committed
226
        name: 'basicform',
愚道's avatar
愚道 committed
227
        path: 'basic-form',
jim's avatar
jim committed
228 229
      },
      {
陈帅's avatar
陈帅 committed
230
        name: 'stepform',
愚道's avatar
愚道 committed
231
        path: 'step-form',
jim's avatar
jim committed
232 233
      },
      {
陈帅's avatar
陈帅 committed
234
<<<<<<< HEAD
jim's avatar
jim committed
235
        name: '高级表单',
xiaohu's avatar
xiaohu committed
236
        // authority: 'admin',
陈帅's avatar
陈帅 committed
237 238 239 240
=======
        name: 'advancedform',
        authority: 'admin',
>>>>>>> add meun Intl
愚道's avatar
愚道 committed
241
        path: 'advanced-form',
jim's avatar
jim committed
242 243 244 245
      },
    ],
  },
  {
陈帅's avatar
陈帅 committed
246
    name: 'list',
jim's avatar
jim committed
247
    icon: 'table',
愚道's avatar
愚道 committed
248
    path: 'list',
jim's avatar
jim committed
249 250
    children: [
      {
陈帅's avatar
陈帅 committed
251
        name: 'searchlist',
愚道's avatar
愚道 committed
252
        path: 'table-list',
jim's avatar
jim committed
253 254
      },
      {
陈帅's avatar
陈帅 committed
255
        name: 'basiclist',
愚道's avatar
愚道 committed
256
        path: 'basic-list',
jim's avatar
jim committed
257 258
      },
      {
陈帅's avatar
陈帅 committed
259
        name: 'cardlist',
愚道's avatar
愚道 committed
260
        path: 'card-list',
jim's avatar
jim committed
261 262
      },
      {
陈帅's avatar
陈帅 committed
263
        name: 'searchlist',
愚道's avatar
愚道 committed
264
        path: 'search',
jim's avatar
jim committed
265 266
        children: [
          {
陈帅's avatar
陈帅 committed
267
            name: 'articles',
愚道's avatar
愚道 committed
268
            path: 'articles',
jim's avatar
jim committed
269 270
          },
          {
陈帅's avatar
陈帅 committed
271
            name: 'projects',
愚道's avatar
愚道 committed
272
            path: 'projects',
jim's avatar
jim committed
273 274
          },
          {
陈帅's avatar
陈帅 committed
275
            name: 'applications',
愚道's avatar
愚道 committed
276
            path: 'applications',
jim's avatar
jim committed
277 278 279 280 281 282
          },
        ],
      },
    ],
  },
  {
陈帅's avatar
陈帅 committed
283
    name: 'profile',
jim's avatar
jim committed
284
    icon: 'profile',
愚道's avatar
愚道 committed
285
    path: 'profile',
jim's avatar
jim committed
286 287
    children: [
      {
陈帅's avatar
陈帅 committed
288
        name: 'basic',
愚道's avatar
愚道 committed
289
        path: 'basic',
jim's avatar
jim committed
290 291
      },
      {
陈帅's avatar
陈帅 committed
292
        name: 'advanced',
愚道's avatar
愚道 committed
293
        path: 'advanced',
xiaohu's avatar
xiaohu committed
294
        // authority: 'admin',
jim's avatar
jim committed
295 296 297 298
      },
    ],
  },
  {
陈帅's avatar
陈帅 committed
299
    name: 'result',
jim's avatar
jim committed
300
    icon: 'check-circle-o',
愚道's avatar
愚道 committed
301
    path: 'result',
jim's avatar
jim committed
302 303
    children: [
      {
陈帅's avatar
陈帅 committed
304
        name: 'success',
愚道's avatar
愚道 committed
305
        path: 'success',
jim's avatar
jim committed
306 307
      },
      {
陈帅's avatar
陈帅 committed
308
        name: 'fail',
愚道's avatar
愚道 committed
309
        path: 'fail',
jim's avatar
jim committed
310 311 312 313
      },
    ],
  },
  {
陈帅's avatar
陈帅 committed
314
    name: 'exception',
jim's avatar
jim committed
315
    icon: 'warning',
愚道's avatar
愚道 committed
316
    path: 'exception',
jim's avatar
jim committed
317 318
    children: [
      {
陈帅's avatar
陈帅 committed
319
        name: 'not-permission',
jim's avatar
jim committed
320 321 322
        path: '403',
      },
      {
陈帅's avatar
陈帅 committed
323
        name: 'not-find',
jim's avatar
jim committed
324 325 326
        path: '404',
      },
      {
陈帅's avatar
陈帅 committed
327
        name: 'server-error',
jim's avatar
jim committed
328 329
        path: '500',
      },
陈帅's avatar
陈帅 committed
330 331 332 333 334
      {
        name: 'trigger',
        path: 'trigger',
        hideInMenu: true,
      },
jim's avatar
jim committed
335 336 337
    ],
  },
  {
陈帅's avatar
陈帅 committed
338
    name: 'user',
jim's avatar
jim committed
339
    icon: 'user',
xiaohu's avatar
xiaohu committed
340
    path: 'User',
jim's avatar
jim committed
341 342 343
    authority: 'guest',
    children: [
      {
陈帅's avatar
陈帅 committed
344
        name: 'login',
愚道's avatar
愚道 committed
345
        path: 'login',
jim's avatar
jim committed
346 347
      },
      {
陈帅's avatar
陈帅 committed
348
        name: 'register',
愚道's avatar
愚道 committed
349
        path: 'register',
jim's avatar
jim committed
350 351
      },
      {
陈帅's avatar
陈帅 committed
352
        name: 'register-result',
愚道's avatar
愚道 committed
353
        path: 'register-result',
jim's avatar
jim committed
354 355 356
      },
    ],
  },
xiaohu's avatar
xiaohu committed
357
  {
陈帅's avatar
陈帅 committed
358
    name: 'account',
xiaohu's avatar
xiaohu committed
359
    icon: 'user',
愚道's avatar
愚道 committed
360
    path: 'account',
xiaohu's avatar
xiaohu committed
361 362
    children: [
      {
陈帅's avatar
陈帅 committed
363
        name: 'center',
愚道's avatar
愚道 committed
364
        path: 'center',
xiaohu's avatar
xiaohu committed
365 366
      },
      {
陈帅's avatar
陈帅 committed
367
        name: 'settings',
愚道's avatar
愚道 committed
368
        path: 'settings',
xiaohu's avatar
xiaohu committed
369 370 371
      },
    ],
  },
jim's avatar
jim committed
372
];
ddcat1115's avatar
ddcat1115 committed
373

374
function formatter(data, parentPath = '/', parentAuthority) {
jim's avatar
jim committed
375
  return data.map(item => {
376 377 378 379
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
afc163's avatar
afc163 committed
380 381
    const result = {
      ...item,
382
      path,
ddcat1115's avatar
ddcat1115 committed
383
      authority: item.authority || parentAuthority,
afc163's avatar
afc163 committed
384
    };
ddcat1115's avatar
ddcat1115 committed
385
    if (item.children) {
ddcat1115's avatar
ddcat1115 committed
386
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
ddcat1115's avatar
ddcat1115 committed
387
    }
afc163's avatar
afc163 committed
388
    return result;
ddcat1115's avatar
ddcat1115 committed
389 390 391 392
  });
}

export const getMenuData = () => formatter(menuData);