article.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import Mock from 'mockjs'
  11. const List = []
  12. const count = 100
  13. 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>'
  14. const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'
  15. for (let i = 0; i < count; i++) {
  16. List.push(Mock.mock({
  17. id: '@increment',
  18. timestamp: +Mock.Random.date('T'),
  19. author: '@first',
  20. reviewer: '@first',
  21. title: '@title(5, 10)',
  22. content_short: 'mock data',
  23. content: baseContent,
  24. forecast: '@float(0, 100, 2, 2)',
  25. importance: '@integer(1, 3)',
  26. 'type|1': ['CN', 'US', 'JP', 'EU'],
  27. 'status|1': ['published', 'draft'],
  28. display_time: '@datetime',
  29. comment_disabled: true,
  30. pageviews: '@integer(300, 5000)',
  31. image_uri,
  32. platforms: ['a-platform']
  33. }))
  34. }
  35. export default [
  36. {
  37. url: '/vue-element-admin/article/list',
  38. type: 'get',
  39. response: config => {
  40. const { importance, type, title, page = 1, limit = 20, sort } = config.query
  41. let mockList = List.filter(item => {
  42. if (importance && item.importance !== +importance) return false
  43. if (type && item.type !== type) return false
  44. if (title && item.title.indexOf(title) < 0) return false
  45. return true
  46. })
  47. if (sort === '-id') {
  48. mockList = mockList.reverse()
  49. }
  50. const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  51. return {
  52. code: 20000,
  53. data: {
  54. total: mockList.length,
  55. items: pageList
  56. }
  57. }
  58. }
  59. },
  60. {
  61. url: '/vue-element-admin/article/detail',
  62. type: 'get',
  63. response: config => {
  64. const { id } = config.query
  65. for (const article of List) {
  66. if (article.id === +id) {
  67. return {
  68. code: 20000,
  69. data: article
  70. }
  71. }
  72. }
  73. }
  74. },
  75. {
  76. url: '/vue-element-admin/article/pv',
  77. type: 'get',
  78. response: _ => {
  79. return {
  80. code: 20000,
  81. data: {
  82. pvData: [
  83. { key: 'PC', pv: 1024 },
  84. { key: 'mobile', pv: 1024 },
  85. { key: 'ios', pv: 1024 },
  86. { key: 'android', pv: 1024 }
  87. ]
  88. }
  89. }
  90. }
  91. },
  92. {
  93. url: '/vue-element-admin/article/create',
  94. type: 'post',
  95. response: _ => {
  96. return {
  97. code: 20000,
  98. data: 'success'
  99. }
  100. }
  101. },
  102. {
  103. url: '/vue-element-admin/article/update',
  104. type: 'post',
  105. response: _ => {
  106. return {
  107. code: 20000,
  108. data: 'success'
  109. }
  110. }
  111. }
  112. ]