From efc976ae5ac572beaa45079258882a8648b944b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Mon, 15 Jun 2020 17:03:06 +0800 Subject: [PATCH 1/6] chore: turn on the preload --- vue.config.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vue.config.js b/vue.config.js index 1d4713f..efc2053 100644 --- a/vue.config.js +++ b/vue.config.js @@ -49,8 +49,11 @@ module.exports = { } }, chainWebpack(config) { - config.plugins.delete('preload') // TODO: need test - config.plugins.delete('prefetch') // TODO: need test + // it can improve the speed of the first screen, it is recommended to turn on preload + // config.plugins.delete('preload') + + // when there are many pages, it will cause too many meaningless requests + config.plugins.delete('prefetch') // set svg-sprite-loader config.module From 5c87772025d626762e8b5115efe29c691424bdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Mon, 15 Jun 2020 17:07:49 +0800 Subject: [PATCH 2/6] refactor: change mock files to commonjs --- mock/index.js | 16 ++++++++++------ mock/mock-server.js | 5 +---- mock/table.js | 4 ++-- mock/user.js | 2 +- mock/utils.js | 23 +++++++++++++++++++++++ package.json | 2 -- 6 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 mock/utils.js diff --git a/mock/index.js b/mock/index.js index aca99f4..c514c13 100644 --- a/mock/index.js +++ b/mock/index.js @@ -1,8 +1,8 @@ -import Mock from 'mockjs' -import { param2Obj } from '../src/utils' +const Mock = require('mockjs') +const { param2Obj } = require('./utils') -import user from './user' -import table from './table' +const user = require('./user') +const table = require('./table') const mocks = [ ...user, @@ -12,7 +12,7 @@ const mocks = [ // 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() { +function mockXHR() { // mock patch // https://github.com/nuysoft/Mock/issues/300 Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send @@ -50,4 +50,8 @@ export function mockXHR() { } } -export default mocks +module.exports = { + mocks, + mockXHR +} + diff --git a/mock/mock-server.js b/mock/mock-server.js index 806fdac..8941ec0 100644 --- a/mock/mock-server.js +++ b/mock/mock-server.js @@ -8,7 +8,7 @@ const mockDir = path.join(process.cwd(), 'mock') function registerRoutes(app) { let mockLastIndex - const { default: mocks } = require('./index.js') + const { mocks } = require('./index.js') const mocksForServer = mocks.map(route => { return responseFake(route.url, route.type, route.response) }) @@ -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/table.js b/mock/table.js index ba95f76..bd0e013 100644 --- a/mock/table.js +++ b/mock/table.js @@ -1,4 +1,4 @@ -import Mock from 'mockjs' +const Mock = require('mockjs') const data = Mock.mock({ 'items|30': [{ @@ -11,7 +11,7 @@ const data = Mock.mock({ }] }) -export default [ +module.exports = [ { url: '/vue-admin-template/table/list', type: 'get', diff --git a/mock/user.js b/mock/user.js index f007cd9..7555338 100644 --- a/mock/user.js +++ b/mock/user.js @@ -23,7 +23,7 @@ const users = { } } -export default [ +module.exports = [ // user login { url: '/vue-admin-template/user/login', diff --git a/mock/utils.js b/mock/utils.js new file mode 100644 index 0000000..9eb4c78 --- /dev/null +++ b/mock/utils.js @@ -0,0 +1,23 @@ +/** + * @param {string} url + * @returns {Object} + */ +function param2Obj(url) { + const search = url.split('?')[1] + if (!search) { + return {} + } + return JSON.parse( + '{"' + + decodeURIComponent(search) + .replace(/"/g, '\\"') + .replace(/&/g, '","') + .replace(/=/g, '":"') + .replace(/\+/g, ' ') + + '"}' + ) +} + +module.exports = { + param2Obj +} diff --git a/package.json b/package.json index 6f5189d..a9fc8fc 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,6 @@ "vuex": "3.1.0" }, "devDependencies": { - "@babel/core": "7.0.0", - "@babel/register": "7.0.0", "@vue/cli-plugin-babel": "3.6.0", "@vue/cli-plugin-eslint": "^3.9.1", "@vue/cli-plugin-unit-jest": "3.6.3", From e2fd7c7528d3bb8b840b1383007ef5d347fcd635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Mon, 15 Jun 2020 17:11:28 +0800 Subject: [PATCH 3/6] feat[Menu]: menu icon support el-icon --- src/layout/components/Sidebar/Item.vue | 14 +++++++++++++- src/router/index.js | 4 ++-- src/styles/sidebar.scss | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/layout/components/Sidebar/Item.vue b/src/layout/components/Sidebar/Item.vue index b515f61..aa1f5da 100644 --- a/src/layout/components/Sidebar/Item.vue +++ b/src/layout/components/Sidebar/Item.vue @@ -17,7 +17,11 @@ export default { const vnodes = [] if (icon) { - vnodes.push() + if (icon.includes('el-icon')) { + vnodes.push() + } else { + vnodes.push() + } } if (title) { @@ -27,3 +31,11 @@ export default { } } + + diff --git a/src/router/index.js b/src/router/index.js index f091f0f..d7177f8 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -19,7 +19,7 @@ import Layout from '@/layout' * meta : { roles: ['admin','editor'] control the page roles (you can set multiple roles) title: 'title' the name show in sidebar and breadcrumb (recommend set) - icon: 'svg-name' the icon show in the sidebar + icon: 'svg-name'/'el-icon-x' the icon show in the sidebar breadcrumb: false if set false, the item will hidden in breadcrumb(default is true) activeMenu: '/example/list' if set path, the sidebar will highlight the path you set } @@ -60,7 +60,7 @@ export const constantRoutes = [ component: Layout, redirect: '/example/table', name: 'Example', - meta: { title: 'Example', icon: 'example' }, + meta: { title: 'Example', icon: 'el-icon-s-help' }, children: [ { path: 'table', diff --git a/src/styles/sidebar.scss b/src/styles/sidebar.scss index 3dad4c3..94760cc 100644 --- a/src/styles/sidebar.scss +++ b/src/styles/sidebar.scss @@ -57,6 +57,11 @@ margin-right: 16px; } + .sub-el-icon { + margin-right: 12px; + margin-left: -2px; + } + .el-menu { border: none; height: 100%; @@ -105,6 +110,10 @@ .svg-icon { margin-left: 20px; } + + .sub-el-icon { + margin-left: 19px; + } } } @@ -118,6 +127,10 @@ margin-left: 20px; } + .sub-el-icon { + margin-left: 19px; + } + .el-submenu__icon-arrow { display: none; } @@ -178,6 +191,10 @@ .svg-icon { margin-right: 16px; } + .sub-el-icon { + margin-right: 12px; + margin-left: -2px; + } } .nest-menu .el-submenu>.el-submenu__title, From 8865514c81a6bc38a6d7d06827056cc79436bdf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Mon, 15 Jun 2020 17:13:53 +0800 Subject: [PATCH 4/6] fix[utils]: param2Obj bug when url params includes == --- mock/utils.js | 24 +++++++++++++----------- src/utils/index.js | 22 ++++++++++++---------- tests/unit/utils/param2Obj.spec.js | 21 +++++++++++++++++++++ 3 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 tests/unit/utils/param2Obj.spec.js diff --git a/mock/utils.js b/mock/utils.js index 9eb4c78..41eb494 100644 --- a/mock/utils.js +++ b/mock/utils.js @@ -2,20 +2,22 @@ * @param {string} url * @returns {Object} */ -function param2Obj(url) { - const search = url.split('?')[1] +export function param2Obj(url) { + const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ') if (!search) { return {} } - return JSON.parse( - '{"' + - decodeURIComponent(search) - .replace(/"/g, '\\"') - .replace(/&/g, '","') - .replace(/=/g, '":"') - .replace(/\+/g, ' ') + - '"}' - ) + const obj = {} + const searchArr = search.split('&') + searchArr.forEach(v => { + const index = v.indexOf('=') + if (index !== -1) { + const name = v.substring(0, index) + const val = v.substring(index + 1, v.length) + obj[name] = val + } + }) + return obj } module.exports = { diff --git a/src/utils/index.js b/src/utils/index.js index 37ae434..4830c04 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -99,17 +99,19 @@ export function formatTime(time, option) { * @returns {Object} */ export function param2Obj(url) { - const search = url.split('?')[1] + const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ') if (!search) { return {} } - return JSON.parse( - '{"' + - decodeURIComponent(search) - .replace(/"/g, '\\"') - .replace(/&/g, '","') - .replace(/=/g, '":"') - .replace(/\+/g, ' ') + - '"}' - ) + const obj = {} + const searchArr = search.split('&') + searchArr.forEach(v => { + const index = v.indexOf('=') + if (index !== -1) { + const name = v.substring(0, index) + const val = v.substring(index + 1, v.length) + obj[name] = val + } + }) + return obj } diff --git a/tests/unit/utils/param2Obj.spec.js b/tests/unit/utils/param2Obj.spec.js new file mode 100644 index 0000000..f54c80c --- /dev/null +++ b/tests/unit/utils/param2Obj.spec.js @@ -0,0 +1,21 @@ +/** + * @param {string} url + * @returns {Object} + */ +export function param2Obj(url) { + const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ') + if (!search) { + return {} + } + const obj = {} + const searchArr = search.split('&') + searchArr.forEach(v => { + const index = v.indexOf('=') + if (index !== -1) { + const name = v.substring(0, index) + const val = v.substring(index + 1, v.length) + obj[name] = val + } + }) + return obj +} From 88303a295902a54883e24f36fb54310bbd54c8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Mon, 15 Jun 2020 17:14:28 +0800 Subject: [PATCH 5/6] chore: update element-ui to 2.13.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a9fc8fc..05cf79f 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "axios": "0.18.1", - "element-ui": "2.13.0", + "element-ui": "2.13.2", "js-cookie": "2.2.0", "normalize.css": "7.0.0", "nprogress": "0.2.0", From 4958db1bad1d673916d837c052af79ac3c158492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Mon, 15 Jun 2020 17:15:29 +0800 Subject: [PATCH 6/6] fix typo --- mock/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mock/utils.js b/mock/utils.js index 41eb494..95cc27d 100644 --- a/mock/utils.js +++ b/mock/utils.js @@ -2,7 +2,7 @@ * @param {string} url * @returns {Object} */ -export function param2Obj(url) { +function param2Obj(url) { const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ') if (!search) { return {}