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