index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const Mock = require('mockjs')
  2. const { deepClone } = require('../utils')
  3. const { asyncRoutes, constantRoutes } = require('./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. module.exports = [
  36. // mock get all routes form server
  37. {
  38. url: '/vue-element-admin/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: '/vue-element-admin/roles',
  50. type: 'get',
  51. response: _ => {
  52. return {
  53. code: 20000,
  54. data: roles
  55. }
  56. }
  57. },
  58. // add role
  59. {
  60. url: '/vue-element-admin/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: '/vue-element-admin/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: '/vue-element-admin/role/[A-Za-z0-9]',
  83. type: 'delete',
  84. response: {
  85. code: 20000,
  86. data: {
  87. status: 'success'
  88. }
  89. }
  90. }
  91. ]