From d5b278a57be4e84b2d657ed5cc89ba37f4e992fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E5=8D=9A=E6=96=87?= Date: Tue, 12 May 2020 17:30:57 +0800 Subject: [PATCH] =?UTF-8?q?mock-server=E6=94=AF=E6=8C=81nodejs-es5=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4role/routes.js=E4=B8=ADimport=20{=20deepClone?= =?UTF-8?q?=20}=20from=20'../../src/utils/index.js=20=E7=AE=80=E5=8D=95?= =?UTF-8?q?=E6=B7=B1=E6=8B=B7=E8=B4=9D=E6=96=B9=E6=B3=95=EF=BC=88=E8=BF=99?= =?UTF-8?q?=E9=87=8C=E4=BD=BF=E7=94=A8=E6=B7=B1=E6=8B=B7=E8=B4=9D=E7=9A=84?= =?UTF-8?q?=E7=9B=AE=E7=9A=84=E4=B8=8D=E5=A4=AA=E7=90=86=E8=A7=A3=EF=BC=8C?= =?UTF-8?q?=E5=BA=94=E8=AF=A5=E6=98=AF=E9=9D=9E=E5=BF=85=E9=A1=BB=E5=90=A7?= =?UTF-8?q?=EF=BC=9F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 升级依赖:"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 --- mock/article.js | 5 ++--- mock/index.js | 39 +++++++++++++++++++++++++-------------- mock/mock-server.js | 3 --- mock/remote-search.js | 4 ++-- mock/role/index.js | 9 ++++----- mock/role/routes.js | 7 +++++-- mock/user.js | 2 +- package.json | 3 --- 8 files changed, 39 insertions(+), 33 deletions(-) diff --git a/mock/article.js b/mock/article.js index 50218ae4..5585760d 100644 --- a/mock/article.js +++ b/mock/article.js @@ -1,4 +1,4 @@ -import Mock from 'mockjs' +const Mock = require('mockjs') const List = [] const count = 100 @@ -27,7 +27,7 @@ for (let i = 0; i < count; i++) { })) } -export default [ +exports.default = [ { url: '/vue-element-admin/article/list', type: 'get', @@ -113,4 +113,3 @@ export default [ } } ] - diff --git a/mock/index.js b/mock/index.js index 196e2927..ec9d6bb1 100644 --- a/mock/index.js +++ b/mock/index.js @@ -1,22 +1,17 @@ -import Mock from 'mockjs' -import { param2Obj } from '../src/utils' +const Mock = require('mockjs') -import user from './user' -import role from './role' -import article from './article' -import search from './remote-search' +const user = require('./user') +const role = require('./role') +const article = require('./article') +const search = require('./remote-search') -const mocks = [ - ...user, - ...role, - ...article, - ...search -] +const mocks = [].concat(user.default, role.default, article.default, search.default) // for front mock // please use it cautiously, it will redefine XMLHttpRequest, // which will cause many of your third-party libraries to be invalidated(like progress event). -export function mockXHR() { + +exports.mockXHR = function mockXHR() { // mock patch // https://github.com/nuysoft/Mock/issues/300 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 diff --git a/mock/mock-server.js b/mock/mock-server.js index 806fdacc..207ea0d7 100644 --- a/mock/mock-server.js +++ b/mock/mock-server.js @@ -44,9 +44,6 @@ const responseFake = (url, type, respond) => { } module.exports = app => { - // es6 polyfill - require('@babel/register') - // parse app.body // https://expressjs.com/en/4x/api.html#req.body app.use(bodyParser.json()) diff --git a/mock/remote-search.js b/mock/remote-search.js index 60809cb8..e1a5529d 100644 --- a/mock/remote-search.js +++ b/mock/remote-search.js @@ -1,4 +1,4 @@ -import Mock from 'mockjs' +const Mock = require('mockjs') const NameList = [] const count = 100 @@ -10,7 +10,7 @@ for (let i = 0; i < count; i++) { } NameList.push({ name: 'mock-Pan' }) -export default [ +exports.default = [ // username search { url: '/vue-element-admin/search/user', diff --git a/mock/role/index.js b/mock/role/index.js index d957493b..86164b5b 100644 --- a/mock/role/index.js +++ b/mock/role/index.js @@ -1,8 +1,7 @@ -import Mock from 'mockjs' -import { deepClone } from '../../src/utils/index.js' -import { asyncRoutes, constantRoutes } from './routes.js' +const Mock = require('mockjs') +const { asyncRoutes, constantRoutes } = require('./routes.js') -const routes = deepClone([...constantRoutes, ...asyncRoutes]) +const routes = [].concat(constantRoutes, asyncRoutes) const roles = [ { @@ -35,7 +34,7 @@ const roles = [ } ] -export default [ +exports.default = [ // mock get all routes form server { url: '/vue-element-admin/routes', diff --git a/mock/role/routes.js b/mock/role/routes.js index d718919c..77cd0a87 100644 --- a/mock/role/routes.js +++ b/mock/role/routes.js @@ -1,6 +1,6 @@ // Just a mock data -export const constantRoutes = [ +const constantRoutes = [ { path: '/redirect', component: 'layout/Layout', @@ -72,7 +72,7 @@ export const constantRoutes = [ } ] -export const asyncRoutes = [ +const asyncRoutes = [ { path: '/permission', component: 'layout/Layout', @@ -523,3 +523,6 @@ export const asyncRoutes = [ { path: '*', redirect: '/404', hidden: true } ] + +exports.constantRoutes = constantRoutes; +exports.asyncRoutes = asyncRoutes; diff --git a/mock/user.js b/mock/user.js index 859bd6f3..8e62bb09 100644 --- a/mock/user.js +++ b/mock/user.js @@ -23,7 +23,7 @@ const users = { } } -export default [ +exports.default = [ // user login { url: '/vue-element-admin/user/login', diff --git a/package.json b/package.json index 448d1ec3..7150467d 100644 --- a/package.json +++ b/package.json @@ -72,15 +72,12 @@ "xlsx": "0.14.1" }, "devDependencies": { - "@babel/core": "7.0.0", - "@babel/register": "7.0.0", "@vue/cli-plugin-babel": "3.5.3", "@vue/cli-plugin-eslint": "^3.9.1", "@vue/cli-plugin-unit-jest": "3.5.3", "@vue/cli-service": "3.5.3", "@vue/test-utils": "1.0.0-beta.29", "autoprefixer": "^9.5.1", - "babel-core": "7.0.0-bridge.0", "babel-eslint": "10.0.1", "babel-jest": "23.6.0", "chalk": "2.4.2",