fix: fixed mock server (#2929)

* init

* refine

* update
This commit is contained in:
花裤衩 2020-01-09 17:21:36 +08:00 committed by GitHub
parent fbad7f481b
commit c9affcf2ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 43 deletions

View File

@ -29,7 +29,7 @@ for (let i = 0; i < count; i++) {
export default [ export default [
{ {
url: '/article/list', url: '/vue-element-admin/article/list',
type: 'get', type: 'get',
response: config => { response: config => {
const { importance, type, title, page = 1, limit = 20, sort } = config.query const { importance, type, title, page = 1, limit = 20, sort } = config.query
@ -58,7 +58,7 @@ export default [
}, },
{ {
url: '/article/detail', url: '/vue-element-admin/article/detail',
type: 'get', type: 'get',
response: config => { response: config => {
const { id } = config.query const { id } = config.query
@ -74,7 +74,7 @@ export default [
}, },
{ {
url: '/article/pv', url: '/vue-element-admin/article/pv',
type: 'get', type: 'get',
response: _ => { response: _ => {
return { return {
@ -92,7 +92,7 @@ export default [
}, },
{ {
url: '/article/create', url: '/vue-element-admin/article/create',
type: 'post', type: 'post',
response: _ => { response: _ => {
return { return {
@ -103,7 +103,7 @@ export default [
}, },
{ {
url: '/article/update', url: '/vue-element-admin/article/update',
type: 'post', type: 'post',
response: _ => { response: _ => {
return { return {

View File

@ -57,9 +57,10 @@ export function mockXHR() {
// for mock server // for mock server
const responseFake = (url, type, respond) => { const responseFake = (url, type, respond) => {
return { return {
url: new RegExp(`/mock${url}`), url: new RegExp(`${process.env.VUE_APP_BASE_API}${url}`),
type: type || 'get', type: type || 'get',
response(req, res) { response(req, res) {
console.log('request invoke:' + req.path)
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond)) res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
} }
} }

View File

@ -13,7 +13,7 @@ NameList.push({ name: 'mock-Pan' })
export default [ export default [
// username search // username search
{ {
url: '/search/user', url: '/vue-element-admin/search/user',
type: 'get', type: 'get',
response: config => { response: config => {
const { name } = config.query const { name } = config.query
@ -30,7 +30,7 @@ export default [
// transaction list // transaction list
{ {
url: '/transaction/list', url: '/vue-element-admin/transaction/list',
type: 'get', type: 'get',
response: _ => { response: _ => {
return { return {

View File

@ -38,7 +38,7 @@ const roles = [
export default [ export default [
// mock get all routes form server // mock get all routes form server
{ {
url: '/routes', url: '/vue-element-admin/routes',
type: 'get', type: 'get',
response: _ => { response: _ => {
return { return {
@ -50,7 +50,7 @@ export default [
// mock get all roles form server // mock get all roles form server
{ {
url: '/roles', url: '/vue-element-admin/roles',
type: 'get', type: 'get',
response: _ => { response: _ => {
return { return {
@ -62,7 +62,7 @@ export default [
// add role // add role
{ {
url: '/role', url: '/vue-element-admin/role',
type: 'post', type: 'post',
response: { response: {
code: 20000, code: 20000,
@ -74,7 +74,7 @@ export default [
// update role // update role
{ {
url: '/role/[A-Za-z0-9]', url: '/vue-element-admin/role/[A-Za-z0-9]',
type: 'put', type: 'put',
response: { response: {
code: 20000, code: 20000,
@ -86,7 +86,7 @@ export default [
// delete role // delete role
{ {
url: '/role/[A-Za-z0-9]', url: '/vue-element-admin/role/[A-Za-z0-9]',
type: 'delete', type: 'delete',
response: { response: {
code: 20000, code: 20000,

View File

@ -26,7 +26,7 @@ const users = {
export default [ export default [
// user login // user login
{ {
url: '/user/login', url: '/vue-element-admin/user/login',
type: 'post', type: 'post',
response: config => { response: config => {
const { username } = config.body const { username } = config.body
@ -49,7 +49,7 @@ export default [
// get user info // get user info
{ {
url: '/user/info\.*', url: '/vue-element-admin/user/info\.*',
type: 'get', type: 'get',
response: config => { response: config => {
const { token } = config.query const { token } = config.query
@ -72,7 +72,7 @@ export default [
// user logout // user logout
{ {
url: '/user/logout', url: '/vue-element-admin/user/logout',
type: 'post', type: 'post',
response: _ => { response: _ => {
return { return {

View File

@ -2,7 +2,7 @@ import request from '@/utils/request'
export function fetchList(query) { export function fetchList(query) {
return request({ return request({
url: '/article/list', url: '/vue-element-admin/article/list',
method: 'get', method: 'get',
params: query params: query
}) })
@ -10,7 +10,7 @@ export function fetchList(query) {
export function fetchArticle(id) { export function fetchArticle(id) {
return request({ return request({
url: '/article/detail', url: '/vue-element-admin/article/detail',
method: 'get', method: 'get',
params: { id } params: { id }
}) })
@ -18,7 +18,7 @@ export function fetchArticle(id) {
export function fetchPv(pv) { export function fetchPv(pv) {
return request({ return request({
url: '/article/pv', url: '/vue-element-admin/article/pv',
method: 'get', method: 'get',
params: { pv } params: { pv }
}) })
@ -26,7 +26,7 @@ export function fetchPv(pv) {
export function createArticle(data) { export function createArticle(data) {
return request({ return request({
url: '/article/create', url: '/vue-element-admin/article/create',
method: 'post', method: 'post',
data data
}) })
@ -34,7 +34,7 @@ export function createArticle(data) {
export function updateArticle(data) { export function updateArticle(data) {
return request({ return request({
url: '/article/update', url: '/vue-element-admin/article/update',
method: 'post', method: 'post',
data data
}) })

View File

@ -2,7 +2,7 @@ import request from '@/utils/request'
export function searchUser(name) { export function searchUser(name) {
return request({ return request({
url: '/search/user', url: '/vue-element-admin/search/user',
method: 'get', method: 'get',
params: { name } params: { name }
}) })
@ -10,7 +10,7 @@ export function searchUser(name) {
export function transactionList(query) { export function transactionList(query) {
return request({ return request({
url: '/transaction/list', url: '/vue-element-admin/transaction/list',
method: 'get', method: 'get',
params: query params: query
}) })

View File

@ -2,21 +2,21 @@ import request from '@/utils/request'
export function getRoutes() { export function getRoutes() {
return request({ return request({
url: '/routes', url: '/vue-element-admin/routes',
method: 'get' method: 'get'
}) })
} }
export function getRoles() { export function getRoles() {
return request({ return request({
url: '/roles', url: '/vue-element-admin/roles',
method: 'get' method: 'get'
}) })
} }
export function addRole(data) { export function addRole(data) {
return request({ return request({
url: '/role', url: '/vue-element-admin/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: `/role/${id}`, url: `/vue-element-admin/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: `/role/${id}`, url: `/vue-element-admin/role/${id}`,
method: 'delete' method: 'delete'
}) })
} }

View File

@ -2,7 +2,7 @@ import request from '@/utils/request'
export function login(data) { export function login(data) {
return request({ return request({
url: '/user/login', url: '/vue-element-admin/user/login',
method: 'post', method: 'post',
data data
}) })
@ -10,7 +10,7 @@ export function login(data) {
export function getInfo(token) { export function getInfo(token) {
return request({ return request({
url: '/user/info', url: '/vue-element-admin/user/info',
method: 'get', method: 'get',
params: { token } params: { token }
}) })
@ -18,7 +18,7 @@ export function getInfo(token) {
export function logout() { export function logout() {
return request({ return request({
url: '/user/logout', url: '/vue-element-admin/user/logout',
method: 'post' method: 'post'
}) })
} }

View File

@ -36,18 +36,7 @@ module.exports = {
warnings: false, warnings: false,
errors: true errors: true
}, },
proxy: { before: require('./mock/mock-server.js')
// change xxx-api/login => mock/login
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: `http://127.0.0.1:${port}/mock`,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
},
after: require('./mock/mock-server.js')
}, },
configureWebpack: { configureWebpack: {
// provide the app's title in webpack's name field, so that // provide the app's title in webpack's name field, so that