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

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

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