article.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Mock from 'mockjs'
  2. import { param2Obj } from '@/utils'
  3. const List = []
  4. const count = 100
  5. const baseContent = '<p>我是测试数据我是测试数据</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(Mock.mock({
  9. id: '@increment',
  10. timestamp: +Mock.Random.date('T'),
  11. author: '@first',
  12. reviewer: '@first',
  13. title: '111111111',
  14. content_short: '我是测试数据',
  15. content: baseContent,
  16. forecast: '@float(0, 100, 2, 2)',
  17. importance: '@integer(1, 3)',
  18. 'type|1': ['CN', 'US', 'JP', 'EU'],
  19. 'status|1': ['published', 'draft', 'deleted'],
  20. display_time: '@datetime',
  21. comment_disabled: true,
  22. pageviews: '@integer(300, 5000)',
  23. image_uri,
  24. platforms: ['a-platform']
  25. }))
  26. }
  27. export default {
  28. getList: config => {
  29. const { importance, type, title, page = 1, limit = 20, sort } = param2Obj(config.url)
  30. let mockList = List.filter(item => {
  31. if (importance && item.importance !== +importance) return false
  32. if (type && item.type !== type) return false
  33. if (title && item.title.indexOf(title) < 0) return false
  34. return true
  35. })
  36. if (sort === '-id') {
  37. mockList = mockList.reverse()
  38. }
  39. const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  40. return {
  41. total: mockList.length,
  42. items: pageList
  43. }
  44. },
  45. getPv: () => ({
  46. pvData: [{ key: 'PC', pv: 1024 }, { key: 'mobile', pv: 1024 }, { key: 'ios', pv: 1024 }, { key: 'android', pv: 1024 }]
  47. }),
  48. getArticle: (config) => {
  49. const { id } = param2Obj(config.url)
  50. for (const article of List) {
  51. if (article.id === +id) {
  52. return article
  53. }
  54. }
  55. },
  56. createArticle: () => ({
  57. data: 'success'
  58. }),
  59. updateArticle: () => ({
  60. data: 'success'
  61. })
  62. }