table.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const { mock } = require('mockjs')
  2. const { handleRandomImage } = require('../utils')
  3. const List = []
  4. const count = 999
  5. for (let i = 0; i < count; i++) {
  6. List.push(
  7. mock({
  8. uuid: '@uuid',
  9. id: '@id',
  10. title: '@csentence(1, 2)',
  11. 'status|1': ['published', 'draft', 'deleted'],
  12. author: '@cname',
  13. datetime: '@datetime',
  14. pageViews: '@integer(300, 5000)',
  15. img: handleRandomImage(200, 200),
  16. smallImg: handleRandomImage(40, 40),
  17. switch: '@boolean',
  18. percent: '@integer(80,99)',
  19. })
  20. )
  21. }
  22. module.exports = [
  23. {
  24. url: '/table/getList',
  25. type: 'post',
  26. response(config) {
  27. if (!config.body) {
  28. return {
  29. code: 200,
  30. msg: 'success',
  31. totalCount: count,
  32. data: mock({
  33. 'data|50': [
  34. {
  35. id: '@id',
  36. title: '@csentence(1, 2)',
  37. 'status|1': ['published', 'draft', 'deleted'],
  38. author: '@cname',
  39. datetime: '@datetime',
  40. pageViews: '@integer(300, 5000)',
  41. img: handleRandomImage(200, 200),
  42. smallImg: handleRandomImage(40, 40),
  43. switch: '@boolean',
  44. percent: '@integer(80,99)',
  45. },
  46. ],
  47. }).data,
  48. }
  49. }
  50. const { title = '', pageNo = 1, pageSize = 20 } = config.body
  51. let mockList = List.filter((item) => {
  52. return !(title && item.title.indexOf(title) < 0)
  53. })
  54. const pageList = mockList.filter(
  55. (item, index) =>
  56. index < pageSize * pageNo && index >= pageSize * (pageNo - 1)
  57. )
  58. return {
  59. code: 200,
  60. msg: 'success',
  61. totalCount: count,
  62. data: pageList,
  63. }
  64. },
  65. },
  66. {
  67. url: '/table/doEdit',
  68. type: 'post',
  69. response() {
  70. return {
  71. code: 200,
  72. msg: '模拟保存成功',
  73. }
  74. },
  75. },
  76. {
  77. url: '/table/doDelete',
  78. type: 'post',
  79. response() {
  80. return {
  81. code: 200,
  82. msg: '模拟删除成功',
  83. }
  84. },
  85. },
  86. ]