2
0

article.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import Mock from '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', 'deleted'],
  19. display_time: '@datetime',
  20. comment_disabled: true,
  21. pageviews: '@integer(300, 5000)',
  22. image_uri,
  23. platforms: ['a-platform']
  24. }))
  25. }
  26. export default [
  27. {
  28. url: '/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: '/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: '/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: '/article/create',
  85. type: 'post',
  86. response: _ => {
  87. return {
  88. code: 20000,
  89. data: 'success'
  90. }
  91. }
  92. },
  93. {
  94. url: '/article/update',
  95. type: 'post',
  96. response: _ => {
  97. return {
  98. code: 20000,
  99. data: 'success'
  100. }
  101. }
  102. }
  103. ]