menu.js 7.38 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
      },
      {
xiaohu's avatar
xiaohu committed
234
        // authority: 'admin',
陈帅's avatar
陈帅 committed
235 236
        name: 'advancedform',
        authority: 'admin',
愚道's avatar
愚道 committed
237
        path: 'advanced-form',
jim's avatar
jim committed
238 239 240 241
      },
    ],
  },
  {
陈帅's avatar
陈帅 committed
242
    name: 'list',
jim's avatar
jim committed
243
    icon: 'table',
愚道's avatar
愚道 committed
244
    path: 'list',
jim's avatar
jim committed
245 246
    children: [
      {
陈帅's avatar
陈帅 committed
247
        name: 'searchlist',
愚道's avatar
愚道 committed
248
        path: 'table-list',
jim's avatar
jim committed
249 250
      },
      {
陈帅's avatar
陈帅 committed
251
        name: 'basiclist',
愚道's avatar
愚道 committed
252
        path: 'basic-list',
jim's avatar
jim committed
253 254
      },
      {
陈帅's avatar
陈帅 committed
255
        name: 'cardlist',
愚道's avatar
愚道 committed
256
        path: 'card-list',
jim's avatar
jim committed
257 258
      },
      {
陈帅's avatar
陈帅 committed
259
        name: 'searchlist',
愚道's avatar
愚道 committed
260
        path: 'search',
jim's avatar
jim committed
261 262
        children: [
          {
陈帅's avatar
陈帅 committed
263
            name: 'articles',
愚道's avatar
愚道 committed
264
            path: 'articles',
jim's avatar
jim committed
265 266
          },
          {
陈帅's avatar
陈帅 committed
267
            name: 'projects',
愚道's avatar
愚道 committed
268
            path: 'projects',
jim's avatar
jim committed
269 270
          },
          {
陈帅's avatar
陈帅 committed
271
            name: 'applications',
愚道's avatar
愚道 committed
272
            path: 'applications',
jim's avatar
jim committed
273 274 275 276 277 278
          },
        ],
      },
    ],
  },
  {
陈帅's avatar
陈帅 committed
279
    name: 'profile',
jim's avatar
jim committed
280
    icon: 'profile',
愚道's avatar
愚道 committed
281
    path: 'profile',
jim's avatar
jim committed
282 283
    children: [
      {
陈帅's avatar
陈帅 committed
284
        name: 'basic',
愚道's avatar
愚道 committed
285
        path: 'basic',
jim's avatar
jim committed
286 287
      },
      {
陈帅's avatar
陈帅 committed
288
        name: 'advanced',
愚道's avatar
愚道 committed
289
        path: 'advanced',
xiaohu's avatar
xiaohu committed
290
        // authority: 'admin',
jim's avatar
jim committed
291 292 293 294
      },
    ],
  },
  {
陈帅's avatar
陈帅 committed
295
    name: 'result',
jim's avatar
jim committed
296
    icon: 'check-circle-o',
愚道's avatar
愚道 committed
297
    path: 'result',
jim's avatar
jim committed
298 299
    children: [
      {
陈帅's avatar
陈帅 committed
300
        name: 'success',
愚道's avatar
愚道 committed
301
        path: 'success',
jim's avatar
jim committed
302 303
      },
      {
陈帅's avatar
陈帅 committed
304
        name: 'fail',
愚道's avatar
愚道 committed
305
        path: 'fail',
jim's avatar
jim committed
306 307 308 309
      },
    ],
  },
  {
陈帅's avatar
陈帅 committed
310
    name: 'exception',
jim's avatar
jim committed
311
    icon: 'warning',
愚道's avatar
愚道 committed
312
    path: 'exception',
jim's avatar
jim committed
313 314
    children: [
      {
陈帅's avatar
陈帅 committed
315
        name: 'not-permission',
jim's avatar
jim committed
316 317 318
        path: '403',
      },
      {
陈帅's avatar
陈帅 committed
319
        name: 'not-find',
jim's avatar
jim committed
320 321 322
        path: '404',
      },
      {
陈帅's avatar
陈帅 committed
323
        name: 'server-error',
jim's avatar
jim committed
324 325
        path: '500',
      },
陈帅's avatar
陈帅 committed
326 327 328 329 330
      {
        name: 'trigger',
        path: 'trigger',
        hideInMenu: true,
      },
jim's avatar
jim committed
331 332 333
    ],
  },
  {
陈帅's avatar
陈帅 committed
334
    name: 'user',
jim's avatar
jim committed
335
    icon: 'user',
xiaohu's avatar
xiaohu committed
336
    path: 'User',
jim's avatar
jim committed
337 338 339
    authority: 'guest',
    children: [
      {
陈帅's avatar
陈帅 committed
340
        name: 'login',
愚道's avatar
愚道 committed
341
        path: 'login',
jim's avatar
jim committed
342 343
      },
      {
陈帅's avatar
陈帅 committed
344
        name: 'register',
愚道's avatar
愚道 committed
345
        path: 'register',
jim's avatar
jim committed
346 347
      },
      {
陈帅's avatar
陈帅 committed
348
        name: 'register-result',
愚道's avatar
愚道 committed
349
        path: 'register-result',
jim's avatar
jim committed
350 351 352
      },
    ],
  },
xiaohu's avatar
xiaohu committed
353
  {
陈帅's avatar
陈帅 committed
354
    name: 'account',
xiaohu's avatar
xiaohu committed
355
    icon: 'user',
愚道's avatar
愚道 committed
356
    path: 'account',
xiaohu's avatar
xiaohu committed
357 358
    children: [
      {
陈帅's avatar
陈帅 committed
359
        name: 'center',
愚道's avatar
愚道 committed
360
        path: 'center',
xiaohu's avatar
xiaohu committed
361 362
      },
      {
陈帅's avatar
陈帅 committed
363
        name: 'settings',
愚道's avatar
愚道 committed
364
        path: 'settings',
xiaohu's avatar
xiaohu committed
365 366 367
      },
    ],
  },
jim's avatar
jim committed
368
];
ddcat1115's avatar
ddcat1115 committed
369

陈帅's avatar
陈帅 committed
370
function formatter(data, parentPath = '/', parentAuthority, parentName) {
jim's avatar
jim committed
371
  return data.map(item => {
372
    let { path } = item;
陈帅's avatar
陈帅 committed
373 374
    const id = parentName ? `${parentName}.${item.name}` : `menu.${item.name}`;

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

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