From 7c33568883f359f4bbe1445d49cdd9cf76a3d88c Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 20 Mar 2019 11:00:54 +0800 Subject: [PATCH] tweak mock --- mock/article.js | 10 +++--- mock/remoteSearch.js | 4 +-- mock/role/index.js | 60 ++++++++++++++++++++++++++--------- mock/user.js | 6 ++-- src/api/role.js | 6 ++-- src/views/permission/role.vue | 2 +- 6 files changed, 59 insertions(+), 29 deletions(-) diff --git a/mock/article.js b/mock/article.js index d8e575c1..45b75296 100644 --- a/mock/article.js +++ b/mock/article.js @@ -48,7 +48,7 @@ export default [ const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1)) return { - code: '20000', + code: 20000, data: { total: mockList.length, items: pageList @@ -65,7 +65,7 @@ export default [ for (const article of List) { if (article.id === +id) { return { - code: '20000', + code: 20000, data: article } } @@ -78,7 +78,7 @@ export default [ type: 'get', response: _ => { return { - code: '20000', + code: 20000, data: { pvData: [ { key: 'PC', pv: 1024 }, @@ -96,7 +96,7 @@ export default [ type: 'post', response: _ => { return { - code: '20000', + code: 20000, data: 'success' } } @@ -107,7 +107,7 @@ export default [ type: 'post', response: _ => { return { - code: '20000', + code: 20000, data: 'success' } } diff --git a/mock/remoteSearch.js b/mock/remoteSearch.js index d07422c9..bb33c2f4 100644 --- a/mock/remoteSearch.js +++ b/mock/remoteSearch.js @@ -22,7 +22,7 @@ export default [ return !(name && lowerCaseName.indexOf(name.toLowerCase()) < 0) }) return { - code: '20000', + code: 20000, data: { items: mockNameList } } } @@ -34,7 +34,7 @@ export default [ type: 'get', response: _ => { return { - code: '20000', + code: 20000, data: { total: 20, 'items|20': [{ diff --git a/mock/role/index.js b/mock/role/index.js index 70d22b0f..39148076 100644 --- a/mock/role/index.js +++ b/mock/role/index.js @@ -36,33 +36,63 @@ const roles = [ ] export default [ + // mock get all routes form server { url: '/routes', type: 'get', - response: routes + response: _ => { + return { + code: 20000, + data: routes + } + } }, + + // mock get all roles form server { url: '/roles', type: 'get', - response: roles - }, - { - url: '/roles/add', - type: 'post', - response: Mock.mock('@integer(300, 5000)') - }, - { - url: '/roles/update/\/[A-Za-z0-9]', - type: 'put', - response: { - data: 'success' + response: _ => { + return { + code: 20000, + data: roles + } } }, + + // 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', response: { - data: 'success' + code: 20000, + data: { + status: 'success' + } } } ] diff --git a/mock/user.js b/mock/user.js index 2bf4ee55..21366c1e 100644 --- a/mock/user.js +++ b/mock/user.js @@ -31,7 +31,7 @@ export default [ response: config => { const { username } = config.body return { - code: '20000', + code: 20000, data: tokens[username] } } @@ -44,7 +44,7 @@ export default [ response: config => { const { token } = config.query return { - code: '20000', + code: 20000, data: users[token] } } @@ -56,7 +56,7 @@ export default [ type: 'post', response: _ => { return { - code: '20000', + code: 20000, data: 'success' } } diff --git a/src/api/role.js b/src/api/role.js index 1d6da8b3..f6a983f1 100644 --- a/src/api/role.js +++ b/src/api/role.js @@ -16,7 +16,7 @@ export function getRoles() { export function addRole(data) { return request({ - url: '/roles/add', + url: '/role', method: 'post', data }) @@ -24,7 +24,7 @@ export function addRole(data) { export function updateRole(id, data) { return request({ - url: `/roles/update/${id}`, + url: `/role/${id}`, method: 'put', data }) @@ -32,7 +32,7 @@ export function updateRole(id, data) { export function deleteRole(id) { return request({ - url: `/roles/delete/${id}`, + url: `/role/${id}`, method: 'delete' }) } diff --git a/src/views/permission/role.vue b/src/views/permission/role.vue index 4d7fa8be..3789e516 100644 --- a/src/views/permission/role.vue +++ b/src/views/permission/role.vue @@ -230,7 +230,7 @@ export default { } } else { const { data } = await addRole(this.role) - this.role.key = data + this.role.key = data.key this.rolesList.push(this.role) }