mock.hbs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import Mock from 'mockjs'
  2. const AllList: any[] = []
  3. for (let i = 0; i < 50; i++) {
  4. AllList.push(Mock.mock({
  5. id: '@id',
  6. title: '@ctitle(10, 20)',
  7. }))
  8. }
  9. export default [
  10. {
  11. url: '/mock/{{#if relativePath}}{{ relativePath }}/{{/if}}{{ moduleName }}/list',
  12. method: 'get',
  13. response: (option: any) => {
  14. const { title, from, limit } = option.query
  15. const list = AllList.filter((item) => {
  16. return title ? item.title.includes(title) : true
  17. })
  18. const pageList = list.filter((item, index) => {
  19. return index >= ~~from && index < (~~from + ~~limit)
  20. })
  21. return {
  22. error: '',
  23. status: 1,
  24. data: {
  25. list: pageList,
  26. total: list.length,
  27. },
  28. }
  29. },
  30. },
  31. {
  32. url: '/mock/{{#if relativePath}}{{ relativePath }}/{{/if}}{{ moduleName }}/detail',
  33. method: 'get',
  34. response: (option: any) => {
  35. const info = AllList.filter(item => item.id === option.query.id)
  36. return {
  37. error: '',
  38. status: 1,
  39. data: info[0],
  40. }
  41. },
  42. },
  43. {
  44. url: '/mock/{{#if relativePath}}{{ relativePath }}/{{/if}}{{ moduleName }}/create',
  45. method: 'post',
  46. response: () => {
  47. return {
  48. error: '',
  49. status: 1,
  50. data: {
  51. isSuccess: true,
  52. },
  53. }
  54. },
  55. },
  56. {
  57. url: '/mock/{{#if relativePath}}{{ relativePath }}/{{/if}}{{ moduleName }}/edit',
  58. method: 'post',
  59. response: () => {
  60. return {
  61. error: '',
  62. status: 1,
  63. data: {
  64. isSuccess: true,
  65. },
  66. }
  67. },
  68. },
  69. {
  70. url: '/mock/{{#if relativePath}}{{ relativePath }}/{{/if}}{{ moduleName }}/delete',
  71. method: 'post',
  72. response: () => {
  73. return {
  74. error: '',
  75. status: 1,
  76. data: {
  77. isSuccess: true,
  78. },
  79. }
  80. },
  81. },
  82. ]