article.js 2.7 KB

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