You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.2 KiB

5 years ago
  1. import Mock from 'mockjs'
  2. import { param2Obj } from '@/utils'
  3. const List = []
  4. const count = 100
  5. for (let i = 0; i < count; i++) {
  6. List.push(Mock.mock({
  7. id: '@increment',
  8. timestamp: +Mock.Random.date('T'),
  9. author: '@first',
  10. reviewer: '@first',
  11. title: '@title(5, 10)',
  12. forecast: '@float(0, 100, 2, 2)',
  13. importance: '@integer(1, 3)',
  14. 'type|1': ['CN', 'US', 'JP', 'EU'],
  15. 'status|1': ['published', 'draft', 'deleted'],
  16. display_time: '@datetime',
  17. pageviews: '@integer(300, 5000)'
  18. }))
  19. }
  20. export default {
  21. getList: config => {
  22. const { importance, type, title, page = 1, limit = 20, sort } = param2Obj(config.url)
  23. let mockList = List.filter(item => {
  24. if (importance && item.importance !== +importance) return false
  25. if (type && item.type !== type) return false
  26. if (title && item.title.indexOf(title) < 0) return false
  27. return true
  28. })
  29. if (sort === '-id') {
  30. mockList = mockList.reverse()
  31. }
  32. const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  33. return {
  34. total: mockList.length,
  35. items: pageList
  36. }
  37. },
  38. getPv: () => ({
  39. pvData: [{ key: 'PC', pv: 1024 }, { key: 'mobile', pv: 1024 }, { key: 'ios', pv: 1024 }, { key: 'android', pv: 1024 }]
  40. }),
  41. getArticle: () => ({
  42. id: 120000000001,
  43. author: { key: 'mockPan' },
  44. source_name: '原创作者',
  45. category_item: [{ key: 'global', name: '全球' }],
  46. comment_disabled: true,
  47. content: '<p>我是测试数据我是测试数据</p><p><img class="wscnph" src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943" data-wscntype="image" data-wscnh="300" data-wscnw="400" data-mce-src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>"',
  48. content_short: '我是测试数据',
  49. display_time: +new Date(),
  50. image_uri: 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3',
  51. platforms: ['a-platform'],
  52. source_uri: 'https://github.com/PanJiaChen/vue-element-admin',
  53. status: 'published',
  54. tags: [],
  55. title: 'vue-element-admin'
  56. }),
  57. createArticle: () => ({
  58. data: 'success'
  59. }),
  60. updateArticle: () => ({
  61. data: 'success'
  62. })
  63. }