menu.js 7.06 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';

jim's avatar
jim committed
197 198 199 200
const menuData = [
  {
    name: 'dashboard',
    icon: 'dashboard',
xiaohu's avatar
xiaohu committed
201
    path: 'Dashboard',
jim's avatar
jim committed
202 203 204
    children: [
      {
        name: '分析页',
xiaohu's avatar
xiaohu committed
205
        path: 'Analysis',
jim's avatar
jim committed
206 207 208
      },
      {
        name: '监控页',
xiaohu's avatar
xiaohu committed
209
        path: 'Monitor',
jim's avatar
jim committed
210 211 212
      },
      {
        name: '工作台',
xiaohu's avatar
xiaohu committed
213
        path: 'Workplace',
jim's avatar
jim committed
214 215 216 217 218 219 220
        // hideInMenu: true,
      },
    ],
  },
  {
    name: '表单页',
    icon: 'form',
xiaohu's avatar
xiaohu committed
221
    path: 'Forms',
jim's avatar
jim committed
222 223 224
    children: [
      {
        name: '基础表单',
xiaohu's avatar
xiaohu committed
225
        path: 'BasicForm',
jim's avatar
jim committed
226 227 228
      },
      {
        name: '分步表单',
xiaohu's avatar
xiaohu committed
229
        path: 'StepForm/Step1',
jim's avatar
jim committed
230 231 232 233
      },
      {
        name: '高级表单',
        authority: 'admin',
xiaohu's avatar
xiaohu committed
234
        path: 'AdvancedForm',
jim's avatar
jim committed
235 236 237 238 239 240
      },
    ],
  },
  {
    name: '列表页',
    icon: 'table',
xiaohu's avatar
xiaohu committed
241
    path: 'List',
jim's avatar
jim committed
242 243 244
    children: [
      {
        name: '查询表格',
xiaohu's avatar
xiaohu committed
245
        path: 'TableList',
jim's avatar
jim committed
246 247 248
      },
      {
        name: '标准列表',
xiaohu's avatar
xiaohu committed
249
        path: 'BasicList',
jim's avatar
jim committed
250 251 252
      },
      {
        name: '卡片列表',
xiaohu's avatar
xiaohu committed
253
        path: 'CardList',
jim's avatar
jim committed
254 255 256
      },
      {
        name: '搜索列表',
xiaohu's avatar
xiaohu committed
257
        path: 'Search',
jim's avatar
jim committed
258 259 260
        children: [
          {
            name: '搜索列表(文章)',
xiaohu's avatar
xiaohu committed
261
            path: 'Articles',
jim's avatar
jim committed
262 263 264
          },
          {
            name: '搜索列表(项目)',
xiaohu's avatar
xiaohu committed
265
            path: 'Projects',
jim's avatar
jim committed
266 267 268
          },
          {
            name: '搜索列表(应用)',
xiaohu's avatar
xiaohu committed
269
            path: 'Applications',
jim's avatar
jim committed
270 271 272 273 274 275 276 277
          },
        ],
      },
    ],
  },
  {
    name: '详情页',
    icon: 'profile',
xiaohu's avatar
xiaohu committed
278
    path: 'Profile',
jim's avatar
jim committed
279 280 281
    children: [
      {
        name: '基础详情页',
xiaohu's avatar
xiaohu committed
282
        path: 'BasicProfile',
jim's avatar
jim committed
283 284 285
      },
      {
        name: '高级详情页',
xiaohu's avatar
xiaohu committed
286
        path: 'AdvancedProfile',
jim's avatar
jim committed
287 288 289 290 291 292 293
        authority: 'admin',
      },
    ],
  },
  {
    name: '结果页',
    icon: 'check-circle-o',
xiaohu's avatar
xiaohu committed
294
    path: 'Result',
jim's avatar
jim committed
295 296 297
    children: [
      {
        name: '成功',
xiaohu's avatar
xiaohu committed
298
        path: 'Success',
jim's avatar
jim committed
299 300 301
      },
      {
        name: '失败',
xiaohu's avatar
xiaohu committed
302
        path: 'Error',
jim's avatar
jim committed
303 304 305 306 307 308
      },
    ],
  },
  {
    name: '异常页',
    icon: 'warning',
xiaohu's avatar
xiaohu committed
309
    path: 'Exception',
jim's avatar
jim committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
    children: [
      {
        name: '403',
        path: '403',
      },
      {
        name: '404',
        path: '404',
      },
      {
        name: '500',
        path: '500',
      },
      {
        name: '触发异常',
xiaohu's avatar
xiaohu committed
325
        path: 'triggerException',
jim's avatar
jim committed
326 327 328 329 330 331 332
        hideInMenu: true,
      },
    ],
  },
  {
    name: '账户',
    icon: 'user',
xiaohu's avatar
xiaohu committed
333
    path: 'User',
jim's avatar
jim committed
334 335 336 337
    authority: 'guest',
    children: [
      {
        name: '登录',
xiaohu's avatar
xiaohu committed
338
        path: 'Login',
jim's avatar
jim committed
339 340 341
      },
      {
        name: '注册',
xiaohu's avatar
xiaohu committed
342
        path: 'Register',
jim's avatar
jim committed
343 344 345
      },
      {
        name: '注册结果',
xiaohu's avatar
xiaohu committed
346
        path: 'RegisterResult',
jim's avatar
jim committed
347 348 349 350
      },
    ],
  },
];
ddcat1115's avatar
ddcat1115 committed
351

352
function formatter(data, parentPath = '/', parentAuthority) {
jim's avatar
jim committed
353
  return data.map(item => {
354 355 356 357
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
afc163's avatar
afc163 committed
358 359
    const result = {
      ...item,
360
      path,
ddcat1115's avatar
ddcat1115 committed
361
      authority: item.authority || parentAuthority,
afc163's avatar
afc163 committed
362
    };
ddcat1115's avatar
ddcat1115 committed
363
    if (item.children) {
ddcat1115's avatar
ddcat1115 committed
364
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
ddcat1115's avatar
ddcat1115 committed
365
    }
afc163's avatar
afc163 committed
366
    return result;
ddcat1115's avatar
ddcat1115 committed
367 368 369 370
  });
}

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