From d109086a5a55418fb50dcab514f316c76d2093b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E5=8D=9A=E6=96=87?= Date: Wed, 13 May 2020 10:31:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4role/routes.js=E4=B8=ADimport?= =?UTF-8?q?=20{=20deepClone=20}=20from=20'../../src/utils/index.js=20?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BE=9D=E8=B5=96=EF=BC=9A"mockjs":=20"^1.1.?= =?UTF-8?q?0",=20=E5=88=A0=E9=99=A4=E4=BE=9D=E8=B5=96=EF=BC=9A=20"@babel/c?= =?UTF-8?q?ore":=20"7.0.0",=20"@babel/register":=20"7.0.0",=20"babel-core"?= =?UTF-8?q?:=20"7.0.0-bridge.0",?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 | 5 +---- 8 files changed, 40 insertions(+), 34 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..a9ab6ae1 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", @@ -91,7 +88,7 @@ "html-webpack-plugin": "3.2.0", "husky": "1.3.1", "lint-staged": "8.1.5", - "mockjs": "1.0.1-beta3", + "mockjs": "^1.1.0", "node-sass": "^4.9.0", "plop": "2.3.0", "runjs": "^4.3.2",