mock-server支持nodejs-es5

删除role/routes.js中import { deepClone } from '../../src/utils/index.js
简单深拷贝方法(这里使用深拷贝的目的不太理解,应该是非必须吧?)

升级依赖:"mockjs": "^1.1.0",
删除依赖:
"@babel/core": "7.0.0",
"@babel/register": "7.0.0",
"babel-core": "7.0.0-bridge.0",
可支持依赖:https://github.com/mengbaiai/vue-h5-template/blob/vue-h5-template/package.json
This commit is contained in:
于博文 2020-05-12 17:30:57 +08:00
parent 6f80263b42
commit d5b278a57b
8 changed files with 39 additions and 33 deletions

View File

@ -1,4 +1,4 @@
import Mock from 'mockjs' const Mock = require('mockjs')
const List = [] const List = []
const count = 100 const count = 100
@ -27,7 +27,7 @@ for (let i = 0; i < count; i++) {
})) }))
} }
export default [ exports.default = [
{ {
url: '/vue-element-admin/article/list', url: '/vue-element-admin/article/list',
type: 'get', type: 'get',
@ -113,4 +113,3 @@ export default [
} }
} }
] ]

View File

@ -1,22 +1,17 @@
import Mock from 'mockjs' const Mock = require('mockjs')
import { param2Obj } from '../src/utils'
import user from './user' const user = require('./user')
import role from './role' const role = require('./role')
import article from './article' const article = require('./article')
import search from './remote-search' const search = require('./remote-search')
const mocks = [ const mocks = [].concat(user.default, role.default, article.default, search.default)
...user,
...role,
...article,
...search
]
// for front mock // for front mock
// please use it cautiously, it will redefine XMLHttpRequest, // please use it cautiously, it will redefine XMLHttpRequest,
// which will cause many of your third-party libraries to be invalidated(like progress event). // which will cause many of your third-party libraries to be invalidated(like progress event).
export function mockXHR() {
exports.mockXHR = function mockXHR() {
// mock patch // mock patch
// https://github.com/nuysoft/Mock/issues/300 // https://github.com/nuysoft/Mock/issues/300
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
@ -54,4 +49,20 @@ export function mockXHR() {
} }
} }
export default mocks function param2Obj(url) {
const search = url.split('?')[1]
if (!search) {
return {}
}
return JSON.parse(
'{"' +
decodeURIComponent(search)
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')
.replace(/\+/g, ' ') +
'"}'
)
}
exports.default = mocks

View File

@ -44,9 +44,6 @@ const responseFake = (url, type, respond) => {
} }
module.exports = app => { module.exports = app => {
// es6 polyfill
require('@babel/register')
// parse app.body // parse app.body
// https://expressjs.com/en/4x/api.html#req.body // https://expressjs.com/en/4x/api.html#req.body
app.use(bodyParser.json()) app.use(bodyParser.json())

View File

@ -1,4 +1,4 @@
import Mock from 'mockjs' const Mock = require('mockjs')
const NameList = [] const NameList = []
const count = 100 const count = 100
@ -10,7 +10,7 @@ for (let i = 0; i < count; i++) {
} }
NameList.push({ name: 'mock-Pan' }) NameList.push({ name: 'mock-Pan' })
export default [ exports.default = [
// username search // username search
{ {
url: '/vue-element-admin/search/user', url: '/vue-element-admin/search/user',

View File

@ -1,8 +1,7 @@
import Mock from 'mockjs' const Mock = require('mockjs')
import { deepClone } from '../../src/utils/index.js' const { asyncRoutes, constantRoutes } = require('./routes.js')
import { asyncRoutes, constantRoutes } from './routes.js'
const routes = deepClone([...constantRoutes, ...asyncRoutes]) const routes = [].concat(constantRoutes, asyncRoutes)
const roles = [ const roles = [
{ {
@ -35,7 +34,7 @@ const roles = [
} }
] ]
export default [ exports.default = [
// mock get all routes form server // mock get all routes form server
{ {
url: '/vue-element-admin/routes', url: '/vue-element-admin/routes',

View File

@ -1,6 +1,6 @@
// Just a mock data // Just a mock data
export const constantRoutes = [ const constantRoutes = [
{ {
path: '/redirect', path: '/redirect',
component: 'layout/Layout', component: 'layout/Layout',
@ -72,7 +72,7 @@ export const constantRoutes = [
} }
] ]
export const asyncRoutes = [ const asyncRoutes = [
{ {
path: '/permission', path: '/permission',
component: 'layout/Layout', component: 'layout/Layout',
@ -523,3 +523,6 @@ export const asyncRoutes = [
{ path: '*', redirect: '/404', hidden: true } { path: '*', redirect: '/404', hidden: true }
] ]
exports.constantRoutes = constantRoutes;
exports.asyncRoutes = asyncRoutes;

View File

@ -23,7 +23,7 @@ const users = {
} }
} }
export default [ exports.default = [
// user login // user login
{ {
url: '/vue-element-admin/user/login', url: '/vue-element-admin/user/login',

View File

@ -72,15 +72,12 @@
"xlsx": "0.14.1" "xlsx": "0.14.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "7.0.0",
"@babel/register": "7.0.0",
"@vue/cli-plugin-babel": "3.5.3", "@vue/cli-plugin-babel": "3.5.3",
"@vue/cli-plugin-eslint": "^3.9.1", "@vue/cli-plugin-eslint": "^3.9.1",
"@vue/cli-plugin-unit-jest": "3.5.3", "@vue/cli-plugin-unit-jest": "3.5.3",
"@vue/cli-service": "3.5.3", "@vue/cli-service": "3.5.3",
"@vue/test-utils": "1.0.0-beta.29", "@vue/test-utils": "1.0.0-beta.29",
"autoprefixer": "^9.5.1", "autoprefixer": "^9.5.1",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1", "babel-eslint": "10.0.1",
"babel-jest": "23.6.0", "babel-jest": "23.6.0",
"chalk": "2.4.2", "chalk": "2.4.2",