2017-08-22 07:43:34 +00:00
|
|
|
import Mock from 'mockjs'
|
2017-08-28 05:12:44 +00:00
|
|
|
import { param2Obj } from '@/utils'
|
2017-04-23 11:50:32 +00:00
|
|
|
|
2017-08-22 07:43:34 +00:00
|
|
|
const List = []
|
2017-08-28 05:12:44 +00:00
|
|
|
const count = 100
|
2017-04-23 11:50:32 +00:00
|
|
|
|
2018-05-30 07:25:08 +00:00
|
|
|
const baseContent = '<p>我是测试数据我是测试数据</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'
|
|
|
|
|
2017-04-23 11:50:32 +00:00
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
List.push(Mock.mock({
|
2017-08-28 05:12:44 +00:00
|
|
|
id: '@increment',
|
|
|
|
timestamp: +Mock.Random.date('T'),
|
2017-12-29 08:07:42 +00:00
|
|
|
author: '@first',
|
|
|
|
reviewer: '@first',
|
|
|
|
title: '@title(5, 10)',
|
2018-05-30 07:25:08 +00:00
|
|
|
content_short: '我是测试数据',
|
|
|
|
content: baseContent,
|
2017-08-28 05:12:44 +00:00
|
|
|
forecast: '@float(0, 100, 2, 2)',
|
|
|
|
importance: '@integer(1, 3)',
|
|
|
|
'type|1': ['CN', 'US', 'JP', 'EU'],
|
|
|
|
'status|1': ['published', 'draft', 'deleted'],
|
2017-04-23 11:50:32 +00:00
|
|
|
display_time: '@datetime',
|
2018-05-30 07:25:08 +00:00
|
|
|
comment_disabled: true,
|
|
|
|
pageviews: '@integer(300, 5000)',
|
|
|
|
image_uri,
|
|
|
|
platforms: ['a-platform']
|
2017-08-22 07:43:34 +00:00
|
|
|
}))
|
2017-04-23 11:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2017-08-28 05:12:44 +00:00
|
|
|
getList: config => {
|
|
|
|
const { importance, type, title, page = 1, limit = 20, sort } = param2Obj(config.url)
|
|
|
|
|
|
|
|
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 {
|
|
|
|
total: mockList.length,
|
|
|
|
items: pageList
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getPv: () => ({
|
2017-12-29 08:07:42 +00:00
|
|
|
pvData: [{ key: 'PC', pv: 1024 }, { key: 'mobile', pv: 1024 }, { key: 'ios', pv: 1024 }, { key: 'android', pv: 1024 }]
|
2017-08-28 05:12:44 +00:00
|
|
|
}),
|
2018-05-30 07:25:08 +00:00
|
|
|
getArticle: (config) => {
|
|
|
|
const { id } = param2Obj(config.url)
|
|
|
|
for (const article of List) {
|
|
|
|
if (article.id === +id) {
|
|
|
|
return article
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-11-30 10:02:31 +00:00
|
|
|
createArticle: () => ({
|
|
|
|
data: 'success'
|
|
|
|
}),
|
|
|
|
updateArticle: () => ({
|
|
|
|
data: 'success'
|
2017-04-23 11:50:32 +00:00
|
|
|
})
|
2017-08-22 07:43:34 +00:00
|
|
|
}
|