index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import Mock from 'mockjs'
  2. import { deepClone } from '../../src/utils/index.js'
  3. import { asyncRoutes, constantRoutes } from './routes.js'
  4. const routes = deepClone([...constantRoutes, ...asyncRoutes])
  5. const roles = [
  6. {
  7. key: 'admin',
  8. name: 'admin',
  9. description: 'Super Administrator. Have access to view all pages.',
  10. routes: routes
  11. },
  12. {
  13. key: 'editor',
  14. name: 'editor',
  15. description: 'Normal Editor. Can see all pages except permission page',
  16. routes: routes.filter(i => i.path !== '/permission')// just a mock
  17. },
  18. {
  19. key: 'visitor',
  20. name: 'visitor',
  21. description: 'Just a visitor. Can only see the home page and the document page',
  22. routes: [{
  23. path: '',
  24. redirect: 'dashboard',
  25. children: [
  26. {
  27. path: 'dashboard',
  28. name: 'Dashboard',
  29. meta: { title: 'dashboard', icon: 'dashboard' }
  30. }
  31. ]
  32. }]
  33. }
  34. ]
  35. export default [
  36. // mock get all routes form server
  37. {
  38. url: '/routes',
  39. type: 'get',
  40. response: _ => {
  41. return {
  42. code: 20000,
  43. data: routes
  44. }
  45. }
  46. },
  47. // mock get all roles form server
  48. {
  49. url: '/roles',
  50. type: 'get',
  51. response: _ => {
  52. return {
  53. code: 20000,
  54. data: roles
  55. }
  56. }
  57. },
  58. // add role
  59. {
  60. url: '/role',
  61. type: 'post',
  62. response: {
  63. code: 20000,
  64. data: {
  65. key: Mock.mock('@integer(300, 5000)')
  66. }
  67. }
  68. },
  69. // update role
  70. {
  71. url: '/role/[A-Za-z0-9]',
  72. type: 'put',
  73. response: {
  74. code: 20000,
  75. data: {
  76. status: 'success'
  77. }
  78. }
  79. },
  80. // delete role
  81. {
  82. url: '/role/[A-Za-z0-9]',
  83. type: 'delete',
  84. response: {
  85. code: 20000,
  86. data: {
  87. status: 'success'
  88. }
  89. }
  90. }
  91. ]