tweak mock

This commit is contained in:
Pan 2019-03-20 11:00:54 +08:00
parent d927d4172f
commit 7c33568883
6 changed files with 59 additions and 29 deletions

View File

@ -48,7 +48,7 @@ export default [
const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1)) const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
return { return {
code: '20000', code: 20000,
data: { data: {
total: mockList.length, total: mockList.length,
items: pageList items: pageList
@ -65,7 +65,7 @@ export default [
for (const article of List) { for (const article of List) {
if (article.id === +id) { if (article.id === +id) {
return { return {
code: '20000', code: 20000,
data: article data: article
} }
} }
@ -78,7 +78,7 @@ export default [
type: 'get', type: 'get',
response: _ => { response: _ => {
return { return {
code: '20000', code: 20000,
data: { data: {
pvData: [ pvData: [
{ key: 'PC', pv: 1024 }, { key: 'PC', pv: 1024 },
@ -96,7 +96,7 @@ export default [
type: 'post', type: 'post',
response: _ => { response: _ => {
return { return {
code: '20000', code: 20000,
data: 'success' data: 'success'
} }
} }
@ -107,7 +107,7 @@ export default [
type: 'post', type: 'post',
response: _ => { response: _ => {
return { return {
code: '20000', code: 20000,
data: 'success' data: 'success'
} }
} }

View File

@ -22,7 +22,7 @@ export default [
return !(name && lowerCaseName.indexOf(name.toLowerCase()) < 0) return !(name && lowerCaseName.indexOf(name.toLowerCase()) < 0)
}) })
return { return {
code: '20000', code: 20000,
data: { items: mockNameList } data: { items: mockNameList }
} }
} }
@ -34,7 +34,7 @@ export default [
type: 'get', type: 'get',
response: _ => { response: _ => {
return { return {
code: '20000', code: 20000,
data: { data: {
total: 20, total: 20,
'items|20': [{ 'items|20': [{

View File

@ -36,33 +36,63 @@ const roles = [
] ]
export default [ export default [
// mock get all routes form server
{ {
url: '/routes', url: '/routes',
type: 'get', type: 'get',
response: routes response: _ => {
return {
code: 20000,
data: routes
}
}
}, },
// mock get all roles form server
{ {
url: '/roles', url: '/roles',
type: 'get', type: 'get',
response: roles response: _ => {
}, return {
{ code: 20000,
url: '/roles/add', data: roles
type: 'post', }
response: Mock.mock('@integer(300, 5000)')
},
{
url: '/roles/update/\/[A-Za-z0-9]',
type: 'put',
response: {
data: 'success'
} }
}, },
// add role
{ {
url: '/roles/delete/\/[A-Za-z0-9]', url: '/role',
type: 'post',
response: {
code: 20000,
data: {
key: Mock.mock('@integer(300, 5000)')
}
}
},
// update role
{
url: '/role/[A-Za-z0-9]',
type: 'put',
response: {
code: 20000,
data: {
status: 'success'
}
}
},
// delete role
{
url: '/role/[A-Za-z0-9]',
type: 'delete', type: 'delete',
response: { response: {
data: 'success' code: 20000,
data: {
status: 'success'
}
} }
} }
] ]

View File

@ -31,7 +31,7 @@ export default [
response: config => { response: config => {
const { username } = config.body const { username } = config.body
return { return {
code: '20000', code: 20000,
data: tokens[username] data: tokens[username]
} }
} }
@ -44,7 +44,7 @@ export default [
response: config => { response: config => {
const { token } = config.query const { token } = config.query
return { return {
code: '20000', code: 20000,
data: users[token] data: users[token]
} }
} }
@ -56,7 +56,7 @@ export default [
type: 'post', type: 'post',
response: _ => { response: _ => {
return { return {
code: '20000', code: 20000,
data: 'success' data: 'success'
} }
} }

View File

@ -16,7 +16,7 @@ export function getRoles() {
export function addRole(data) { export function addRole(data) {
return request({ return request({
url: '/roles/add', url: '/role',
method: 'post', method: 'post',
data data
}) })
@ -24,7 +24,7 @@ export function addRole(data) {
export function updateRole(id, data) { export function updateRole(id, data) {
return request({ return request({
url: `/roles/update/${id}`, url: `/role/${id}`,
method: 'put', method: 'put',
data data
}) })
@ -32,7 +32,7 @@ export function updateRole(id, data) {
export function deleteRole(id) { export function deleteRole(id) {
return request({ return request({
url: `/roles/delete/${id}`, url: `/role/${id}`,
method: 'delete' method: 'delete'
}) })
} }

View File

@ -230,7 +230,7 @@ export default {
} }
} else { } else {
const { data } = await addRole(this.role) const { data } = await addRole(this.role)
this.role.key = data this.role.key = data.key
this.rolesList.push(this.role) this.rolesList.push(this.role)
} }