小说后台管理系统
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

117 строки
2.6 KiB

  1. const Mock = require('mockjs')
  2. const List = []
  3. const count = 100
  4. const baseContent = '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
  5. const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'
  6. for (let i = 0; i < count; i++) {
  7. List.push(Mock.mock({
  8. id: '@increment',
  9. timestamp: +Mock.Random.date('T'),
  10. author: '@first',
  11. reviewer: '@first',
  12. title: '@title(5, 10)',
  13. content_short: 'mock data',
  14. content: baseContent,
  15. forecast: '@float(0, 100, 2, 2)',
  16. importance: '@integer(1, 3)',
  17. 'type|1': ['CN', 'US', 'JP', 'EU'],
  18. 'status|1': ['published', 'draft'],
  19. display_time: '@datetime',
  20. comment_disabled: true,
  21. pageviews: '@integer(300, 5000)',
  22. image_uri,
  23. platforms: ['a-platform']
  24. }))
  25. }
  26. module.exports = [
  27. {
  28. url: '/vue-element-admin/article/list',
  29. type: 'get',
  30. response: config => {
  31. const { importance, type, title, page = 1, limit = 20, sort } = config.query
  32. let mockList = List.filter(item => {
  33. if (importance && item.importance !== +importance) return false
  34. if (type && item.type !== type) return false
  35. if (title && item.title.indexOf(title) < 0) return false
  36. return true
  37. })
  38. if (sort === '-id') {
  39. mockList = mockList.reverse()
  40. }
  41. const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  42. return {
  43. code: 20000,
  44. data: {
  45. total: mockList.length,
  46. items: pageList
  47. }
  48. }
  49. }
  50. },
  51. {
  52. url: '/vue-element-admin/article/detail',
  53. type: 'get',
  54. response: config => {
  55. const { id } = config.query
  56. for (const article of List) {
  57. if (article.id === +id) {
  58. return {
  59. code: 20000,
  60. data: article
  61. }
  62. }
  63. }
  64. }
  65. },
  66. {
  67. url: '/vue-element-admin/article/pv',
  68. type: 'get',
  69. response: _ => {
  70. return {
  71. code: 20000,
  72. data: {
  73. pvData: [
  74. { key: 'PC', pv: 1024 },
  75. { key: 'mobile', pv: 1024 },
  76. { key: 'ios', pv: 1024 },
  77. { key: 'android', pv: 1024 }
  78. ]
  79. }
  80. }
  81. }
  82. },
  83. {
  84. url: '/vue-element-admin/article/create',
  85. type: 'post',
  86. response: _ => {
  87. return {
  88. code: 20000,
  89. data: 'success'
  90. }
  91. }
  92. },
  93. {
  94. url: '/vue-element-admin/article/update',
  95. type: 'post',
  96. response: _ => {
  97. return {
  98. code: 20000,
  99. data: 'success'
  100. }
  101. }
  102. }
  103. ]