Blame view
mock/article.js
2.71 KB
d7d9c38c2 auto commit the c... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import Mock from 'mockjs' const List = [] const count = 100 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>' const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3' for (let i = 0; i < count; i++) { List.push(Mock.mock({ id: '@increment', timestamp: +Mock.Random.date('T'), author: '@first', reviewer: '@first', title: '@title(5, 10)', content_short: 'mock data', content: baseContent, forecast: '@float(0, 100, 2, 2)', importance: '@integer(1, 3)', 'type|1': ['CN', 'US', 'JP', 'EU'], 'status|1': ['published', 'draft'], display_time: '@datetime', comment_disabled: true, pageviews: '@integer(300, 5000)', image_uri, platforms: ['a-platform'] })) } |
50760eab9 auto commit the c... |
29 30 |
export default [{ url: '/yp/article/list', |
d7d9c38c2 auto commit the c... |
31 32 |
type: 'get', response: config => { |
50760eab9 auto commit the c... |
33 34 35 36 37 38 39 40 |
const { importance, type, title, page = 1, limit = 20, sort } = config.query |
d7d9c38c2 auto commit the c... |
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
let mockList = List.filter(item => { if (importance && item.importance !== +importance) return false if (type && item.type !== type) return false if (title && item.title.indexOf(title) < 0) return false return true }) if (sort === '-id') { mockList = mockList.reverse() } const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1)) return { code: 20000, data: { total: mockList.length, items: pageList } } } }, { |
50760eab9 auto commit the c... |
66 |
url: '/yp/article/detail', |
d7d9c38c2 auto commit the c... |
67 68 |
type: 'get', response: config => { |
50760eab9 auto commit the c... |
69 70 71 |
const { id } = config.query |
d7d9c38c2 auto commit the c... |
72 73 74 75 76 77 78 79 80 81 82 83 |
for (const article of List) { if (article.id === +id) { return { code: 20000, data: article } } } } }, { |
50760eab9 auto commit the c... |
84 |
url: '/yp/article/pv', |
d7d9c38c2 auto commit the c... |
85 86 87 88 89 |
type: 'get', response: _ => { return { code: 20000, data: { |
50760eab9 auto commit the c... |
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
pvData: [{ key: 'PC', pv: 1024 }, { key: 'mobile', pv: 1024 }, { key: 'ios', pv: 1024 }, { key: 'android', pv: 1024 } |
d7d9c38c2 auto commit the c... |
106 107 108 109 110 111 112 |
] } } } }, { |
50760eab9 auto commit the c... |
113 |
url: '/yp/article/create', |
d7d9c38c2 auto commit the c... |
114 115 116 117 118 119 120 121 122 123 |
type: 'post', response: _ => { return { code: 20000, data: 'success' } } }, { |
50760eab9 auto commit the c... |
124 |
url: '/yp/article/update', |
d7d9c38c2 auto commit the c... |
125 126 127 128 129 130 131 132 133 |
type: 'post', response: _ => { return { code: 20000, data: 'success' } } } ] |