refactor
This commit is contained in:
@@ -1,21 +1,50 @@
|
||||
import Mock from 'mockjs'
|
||||
import { param2Obj } from '@/utils'
|
||||
|
||||
const List = []
|
||||
const count = 20
|
||||
const count = 100
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
List.push(Mock.mock({
|
||||
id: '@id',
|
||||
title: '@ctitle(10, 20)',
|
||||
'status|1': ['published', 'draft'],
|
||||
id: '@increment',
|
||||
timestamp: +Mock.Random.date('T'),
|
||||
author: '@cname',
|
||||
auditor: '@cname',
|
||||
title: '@ctitle(10, 20)',
|
||||
forecast: '@float(0, 100, 2, 2)',
|
||||
importance: '@integer(1, 3)',
|
||||
'type|1': ['CN', 'US', 'JP', 'EU'],
|
||||
'status|1': ['published', 'draft', 'deleted'],
|
||||
display_time: '@datetime',
|
||||
pageviews: '@integer(300, 5000)'
|
||||
}))
|
||||
}
|
||||
|
||||
export default {
|
||||
getList: () => List,
|
||||
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: () => ({
|
||||
pvData: [{ key: 'PC网站', pv: 1024 }, { key: 'mobile网站', pv: 1024 }, { key: 'ios', pv: 1024 }, { key: 'android', pv: 1024 }]
|
||||
}),
|
||||
getArticle: () => ({
|
||||
id: 120000000001,
|
||||
author: { key: 'mockPan' },
|
||||
|
@@ -1,44 +0,0 @@
|
||||
import Mock from 'mockjs'
|
||||
import { param2Obj } from 'utils'
|
||||
|
||||
const List = []
|
||||
const count = 100
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
List.push(Mock.mock({
|
||||
id: '@increment',
|
||||
timestamp: +Mock.Random.date('T'),
|
||||
author: '@cname',
|
||||
auditor: '@cname',
|
||||
title: '@ctitle(10, 20)',
|
||||
forecast: '@float(0, 100, 2, 2)',
|
||||
importance: '@integer(1, 3)',
|
||||
'type|1': ['CN', 'US', 'JP', 'EU'],
|
||||
'status|1': ['published', 'draft', 'deleted'],
|
||||
pageviews: '@integer(300, 5000)'
|
||||
}))
|
||||
}
|
||||
|
||||
export default {
|
||||
getList: config => {
|
||||
const { importance, type, title, page, limit, 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: () => ({
|
||||
pvData: [{ key: 'PC网站', pv: 1024 }, { key: 'mobile网站', pv: 1024 }, { key: 'ios', pv: 1024 }, { key: 'android', pv: 1024 }]
|
||||
})
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
import Mock from 'mockjs'
|
||||
import loginAPI from './login'
|
||||
import articleAPI from './article'
|
||||
import article_tableAPI from './article_table'
|
||||
import remoteSearchAPI from './remoteSearch'
|
||||
|
||||
Mock.setup({
|
||||
@@ -16,10 +15,7 @@ Mock.mock(/\/user\/info\.*/, 'get', loginAPI.getUserInfo)
|
||||
// 文章相关
|
||||
Mock.mock(/\/article\/list/, 'get', articleAPI.getList)
|
||||
Mock.mock(/\/article\/detail/, 'get', articleAPI.getArticle)
|
||||
|
||||
// table example相关
|
||||
Mock.mock(/\/article_table\/list/, 'get', article_tableAPI.getList)
|
||||
Mock.mock(/\/article_table\/p/, 'get', article_tableAPI.getPv)
|
||||
Mock.mock(/\/article\/pv/, 'get', articleAPI.getPv)
|
||||
|
||||
// 搜索相关
|
||||
Mock.mock(/\/search\/user/, 'get', remoteSearchAPI.searchUser)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { param2Obj } from 'utils'
|
||||
import { param2Obj } from '@/utils'
|
||||
|
||||
const userMap = {
|
||||
admin: {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import Mock from 'mockjs'
|
||||
import { param2Obj } from 'utils'
|
||||
import { param2Obj } from '@/utils'
|
||||
|
||||
const NameList = []
|
||||
const count = 100
|
||||
|
Reference in New Issue
Block a user