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/9] 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/9] 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/9] 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/9] 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/9] 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/9] 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 {} From b292e46f452e7f4625ca1b022505cb952848dd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Fri, 19 Jun 2020 15:52:59 +0800 Subject: [PATCH 7/9] fix: fixed param2Obj.spec.js --- tests/unit/utils/param2Obj.spec.js | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/tests/unit/utils/param2Obj.spec.js b/tests/unit/utils/param2Obj.spec.js index f54c80c..e106ed8 100644 --- a/tests/unit/utils/param2Obj.spec.js +++ b/tests/unit/utils/param2Obj.spec.js @@ -1,21 +1,14 @@ -/** - * @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 - } +import { param2Obj } from '@/utils/index.js' +describe('Utils:param2Obj', () => { + const url = 'https://github.com/PanJiaChen/vue-element-admin?name=bill&age=29&sex=1&field=dGVzdA==&key=%E6%B5%8B%E8%AF%95' + + it('param2Obj test', () => { + expect(param2Obj(url)).toEqual({ + name: 'bill', + age: '29', + sex: '1', + field: window.btoa('test'), + key: '测试' + }) }) - return obj -} +}) From 83f3a9cc579b6d330271671a202646478e4c9d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Sun, 21 Jun 2020 21:46:49 +0800 Subject: [PATCH 8/9] bump: update to vue-cli@4 (#591) --- .env.development | 9 -------- babel.config.js | 13 +++++++++-- package.json | 41 ++++++++++++++++++----------------- src/store/modules/settings.js | 1 + 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/.env.development b/.env.development index 8f5856d..de583d0 100644 --- a/.env.development +++ b/.env.development @@ -3,12 +3,3 @@ ENV = 'development' # base api VUE_APP_BASE_API = '/dev-api' - -# vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable, -# to control whether the babel-plugin-dynamic-import-node plugin is enabled. -# It only does one thing by converting all import() to require(). -# This configuration can significantly increase the speed of hot updates, -# when you have a large number of pages. -# Detail: https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/babel-preset-app/index.js - -VUE_CLI_BABEL_TRANSPILE_MODULES = true diff --git a/babel.config.js b/babel.config.js index ba17966..fb82b27 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,5 +1,14 @@ module.exports = { presets: [ - '@vue/app' - ] + // https://github.com/vuejs/vue-cli/tree/master/packages/@vue/babel-preset-app + '@vue/cli-plugin-babel/preset' + ], + 'env': { + 'development': { + // babel-plugin-dynamic-import-node plugin only does one thing by converting all import() to require(). + // This plugin can significantly increase the speed of hot updates, when you have a large number of pages. + // https://panjiachen.github.io/vue-element-admin-site/guide/advanced/lazy-loading.html + 'plugins': ['dynamic-import-node'] + } + } } diff --git a/package.json b/package.json index 05cf79f..b00f3ed 100644 --- a/package.json +++ b/package.json @@ -3,19 +3,19 @@ "version": "4.3.0", "description": "A vue admin template with Element UI & axios & iconfont & permission control & lint", "author": "Pan ", - "license": "MIT", "scripts": { "dev": "vue-cli-service serve", "build:prod": "vue-cli-service build", "build:stage": "vue-cli-service build --mode staging", "preview": "node build/index.js --preview", + "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml", "lint": "eslint --ext .js,.vue src", "test:unit": "jest --clearCache && vue-cli-service test:unit", - "test:ci": "npm run lint && npm run test:unit", - "svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml" + "test:ci": "npm run lint && npm run test:unit" }, "dependencies": { "axios": "0.18.1", + "core-js": "3.6.5", "element-ui": "2.13.2", "js-cookie": "2.2.0", "normalize.css": "7.0.0", @@ -26,36 +26,37 @@ "vuex": "3.1.0" }, "devDependencies": { - "@vue/cli-plugin-babel": "3.6.0", - "@vue/cli-plugin-eslint": "^3.9.1", - "@vue/cli-plugin-unit-jest": "3.6.3", - "@vue/cli-service": "3.6.0", + "@vue/cli-plugin-babel": "4.4.4", + "@vue/cli-plugin-eslint": "4.4.4", + "@vue/cli-plugin-unit-jest": "4.4.4", + "@vue/cli-service": "4.4.4", "@vue/test-utils": "1.0.0-beta.29", - "autoprefixer": "^9.5.1", - "babel-core": "7.0.0-bridge.0", - "babel-eslint": "10.0.1", + "autoprefixer": "9.5.1", + "babel-eslint": "10.1.0", "babel-jest": "23.6.0", + "babel-plugin-dynamic-import-node": "2.3.3", "chalk": "2.4.2", "connect": "3.6.6", - "eslint": "5.15.3", - "eslint-plugin-vue": "5.2.2", + "eslint": "6.7.2", + "eslint-plugin-vue": "6.2.2", "html-webpack-plugin": "3.2.0", "mockjs": "1.0.1-beta3", - "runjs": "^4.3.2", - "sass": "^1.26.8", - "sass-loader": "^7.1.0", + "runjs": "4.3.2", + "sass": "1.26.8", + "sass-loader": "8.0.2", "script-ext-html-webpack-plugin": "2.1.3", - "serve-static": "^1.13.2", + "serve-static": "1.13.2", "svg-sprite-loader": "4.1.3", "svgo": "1.2.2", "vue-template-compiler": "2.6.10" }, + "browserslist": [ + "> 1%", + "last 2 versions" + ], "engines": { "node": ">=8.9", "npm": ">= 3.0.0" }, - "browserslist": [ - "> 1%", - "last 2 versions" - ] + "license": "MIT" } diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js index aab31a2..b3f33f8 100644 --- a/src/store/modules/settings.js +++ b/src/store/modules/settings.js @@ -10,6 +10,7 @@ const state = { const mutations = { CHANGE_SETTING: (state, { key, value }) => { + // eslint-disable-next-line no-prototype-builtins if (state.hasOwnProperty(key)) { state[key] = value } From bbabeda803c32d3fb1e6dfa75140be406266514f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Sun, 21 Jun 2020 21:54:51 +0800 Subject: [PATCH 9/9] [release] 4.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b00f3ed..2413824 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-admin-template", - "version": "4.3.0", + "version": "4.4.0", "description": "A vue admin template with Element UI & axios & iconfont & permission control & lint", "author": "Pan ", "scripts": {