Former-commit-id: 942f3f52baf6cfd823aaf446ed306540aa23a89f Former-commit-id: ebb4d4319db002f4a935c7e195bfa7f420c58d93 Former-commit-id: 41a9ad068170ff1673e5fe7a10ebdbf4db0849a1
50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
import Mock from 'mockjs'
|
|
|
|
const r = (add = 0) => {
|
|
return Math.round(Math.random() * 100) + add
|
|
}
|
|
|
|
const returnMaker = (data = []) => {
|
|
return {
|
|
code: 0,
|
|
msg: '请求成功',
|
|
data
|
|
}
|
|
}
|
|
|
|
Mock.mock('/api/chart/G2Line', 'post', ({body, type, url}) => {
|
|
const _body = JSON.parse(body)
|
|
switch (_body.type) {
|
|
case 'base': {
|
|
let last = 0
|
|
const year = ['1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999']
|
|
const data = year.map(e => ({
|
|
year: e,
|
|
value: 0
|
|
})).map(e => {
|
|
e.value = last + r()
|
|
last = e.value
|
|
return e
|
|
}).map(e => ({
|
|
x: e.year,
|
|
y: e.value
|
|
}))
|
|
last = 0
|
|
return returnMaker(data)
|
|
}
|
|
case 'step': {
|
|
const month = ['3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月']
|
|
const data = month.map(e => ({
|
|
month: e,
|
|
value: r()
|
|
})).map(e => ({
|
|
x: e.month,
|
|
y: e.value
|
|
}))
|
|
return returnMaker(data)
|
|
}
|
|
default:
|
|
return {}
|
|
}
|
|
})
|