From a5d4bbda7577a0173b36b0f34dc66e6e0b2c27a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Fri, 19 Apr 2019 20:41:52 +0800 Subject: [PATCH] [release]4.1.0 (#211) --- .babelrc | 12 -- .env.development | 14 ++ .env.production | 6 + .env.staging | 8 + .eslintignore | 3 +- .eslintrc.js | 8 +- .gitignore | 1 + .postcssrc.js | 6 +- README-zh.md | 80 ++++---- README.md | 85 ++++----- babel.config.js | 5 + build/build.js | 45 ----- build/check-versions.js | 64 ------- build/index.js | 35 ++++ build/logo.png | Bin 6849 -> 0 bytes build/utils.js | 108 ----------- build/vue-loader.conf.js | 5 - build/webpack.base.conf.js | 108 ----------- build/webpack.dev.conf.js | 95 ---------- build/webpack.prod.conf.js | 177 ------------------ config/dev.env.js | 8 - config/index.js | 86 --------- config/prod.env.js | 5 - index.html | 12 -- jest.config.js | 24 +++ mock/index.js | 80 ++++++-- mock/mock-server.js | 64 +++++++ mock/table.js | 41 ++-- mock/user.js | 68 ++++--- mock/utils.js | 14 -- package.json | 101 ++++------ favicon.ico => public/favicon.ico | Bin public/index.html | 17 ++ src/App.vue | 2 +- src/api/{login.js => user.js} | 7 +- src/components/Breadcrumb/index.vue | 37 ++-- src/components/Hamburger/index.vue | 16 +- src/components/SvgIcon/index.vue | 2 +- src/icons/index.js | 4 +- src/icons/svg/dashboard.svg | 1 + src/icons/svg/eye-open.svg | 2 +- src/icons/svg/link.svg | 2 +- src/icons/svg/table.svg | 2 +- src/{views => }/layout/components/AppMain.vue | 14 +- src/layout/components/Navbar.vue | 139 ++++++++++++++ src/layout/components/Sidebar/FixiOSBug.js | 26 +++ .../layout/components/Sidebar/Item.vue | 17 +- .../layout/components/Sidebar/Link.vue | 2 +- src/layout/components/Sidebar/Logo.vue | 82 ++++++++ .../layout/components/Sidebar/SidebarItem.vue | 18 +- src/layout/components/Sidebar/index.vue | 54 ++++++ src/{views => }/layout/components/index.js | 0 .../layout/Layout.vue => layout/index.vue} | 36 +++- src/layout/mixin/ResizeHandler.js | 45 +++++ src/main.js | 14 +- src/permission.js | 69 +++++-- src/router/index.js | 82 +++++--- src/settings.js | 16 ++ src/store/getters.js | 3 +- src/store/index.js | 8 +- src/store/modules/app.js | 73 ++++---- src/store/modules/permission.js | 69 +++++++ src/store/modules/settings.js | 31 +++ src/store/modules/user.js | 175 +++++++++-------- src/styles/element-ui.scss | 20 +- src/styles/index.scss | 23 +-- src/styles/sidebar.scss | 23 ++- src/styles/transition.scss | 8 +- src/styles/variables.scss | 2 +- src/utils/get-page-title.js | 10 + src/utils/index.js | 90 +++++++++ src/utils/request.js | 68 ++++--- src/utils/validate.js | 20 +- src/views/404.vue | 12 +- src/views/dashboard/index.vue | 6 +- src/views/form/index.vue | 26 +-- src/views/layout/components/Navbar.vue | 95 ---------- src/views/layout/components/Sidebar/index.vue | 39 ---- src/views/layout/mixin/ResizeHandler.js | 40 ---- src/views/login/index.vue | 135 ++++++++----- src/views/nested/menu1/index.vue | 2 +- src/views/nested/menu1/menu1-1/index.vue | 2 +- src/views/table/index.vue | 7 +- static/.gitkeep | 0 tests/unit/.eslintrc.js | 5 + tests/unit/components/Breadcrumb.spec.js | 98 ++++++++++ tests/unit/components/Hamburger.spec.js | 18 ++ tests/unit/components/SvgIcon.spec.js | 22 +++ tests/unit/utils/formatTime.spec.js | 30 +++ tests/unit/utils/parseTime.spec.js | 28 +++ tests/unit/utils/validate.spec.js | 17 ++ vue.config.js | 133 +++++++++++++ 92 files changed, 1916 insertions(+), 1496 deletions(-) delete mode 100644 .babelrc create mode 100644 .env.development create mode 100644 .env.production create mode 100644 .env.staging create mode 100644 babel.config.js delete mode 100644 build/build.js delete mode 100644 build/check-versions.js create mode 100644 build/index.js delete mode 100644 build/logo.png delete mode 100644 build/utils.js delete mode 100644 build/vue-loader.conf.js delete mode 100644 build/webpack.base.conf.js delete mode 100644 build/webpack.dev.conf.js delete mode 100644 build/webpack.prod.conf.js delete mode 100644 config/dev.env.js delete mode 100644 config/index.js delete mode 100644 config/prod.env.js delete mode 100644 index.html create mode 100644 jest.config.js create mode 100644 mock/mock-server.js delete mode 100644 mock/utils.js rename favicon.ico => public/favicon.ico (100%) create mode 100644 public/index.html rename src/api/{login.js => user.js} (78%) create mode 100644 src/icons/svg/dashboard.svg rename src/{views => }/layout/components/AppMain.vue (59%) create mode 100644 src/layout/components/Navbar.vue create mode 100644 src/layout/components/Sidebar/FixiOSBug.js rename src/{views => }/layout/components/Sidebar/Item.vue (64%) rename src/{views => }/layout/components/Sidebar/Link.vue (97%) create mode 100644 src/layout/components/Sidebar/Logo.vue rename src/{views => }/layout/components/Sidebar/SidebarItem.vue (82%) create mode 100644 src/layout/components/Sidebar/index.vue rename src/{views => }/layout/components/index.js (100%) rename src/{views/layout/Layout.vue => layout/index.vue} (66%) create mode 100644 src/layout/mixin/ResizeHandler.js create mode 100644 src/settings.js create mode 100644 src/store/modules/permission.js create mode 100644 src/store/modules/settings.js create mode 100644 src/utils/get-page-title.js create mode 100644 src/utils/index.js delete mode 100644 src/views/layout/components/Navbar.vue delete mode 100644 src/views/layout/components/Sidebar/index.vue delete mode 100644 src/views/layout/mixin/ResizeHandler.js delete mode 100644 static/.gitkeep create mode 100644 tests/unit/.eslintrc.js create mode 100644 tests/unit/components/Breadcrumb.spec.js create mode 100644 tests/unit/components/Hamburger.spec.js create mode 100644 tests/unit/components/SvgIcon.spec.js create mode 100644 tests/unit/utils/formatTime.spec.js create mode 100644 tests/unit/utils/parseTime.spec.js create mode 100644 tests/unit/utils/validate.spec.js create mode 100644 vue.config.js diff --git a/.babelrc b/.babelrc deleted file mode 100644 index a2a380f..0000000 --- a/.babelrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "presets": [ - ["env", { - "modules": false, - "targets": { - "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] - } - }], - "stage-2" - ], - "plugins":["transform-vue-jsx", "transform-runtime"] -} diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..8f5856d --- /dev/null +++ b/.env.development @@ -0,0 +1,14 @@ +# just a flag +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/.env.production b/.env.production new file mode 100644 index 0000000..80c8103 --- /dev/null +++ b/.env.production @@ -0,0 +1,6 @@ +# just a flag +ENV = 'production' + +# base api +VUE_APP_BASE_API = '/prod-api' + diff --git a/.env.staging b/.env.staging new file mode 100644 index 0000000..a8793a0 --- /dev/null +++ b/.env.staging @@ -0,0 +1,8 @@ +NODE_ENV = production + +# just a flag +ENV = 'staging' + +# base api +VUE_APP_BASE_API = '/stage-api' + diff --git a/.eslintignore b/.eslintignore index e3a4037..e6529fc 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ build/*.js -config/*.js src/assets +public +dist diff --git a/.eslintrc.js b/.eslintrc.js index 0e5c28a..c977505 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -21,7 +21,10 @@ module.exports = { "allowFirstLine": false } }], + "vue/singleline-html-element-content-newline": "off", + "vue/multiline-html-element-content-newline":"off", "vue/name-property-casing": ["error", "PascalCase"], + "vue/no-v-html": "off", 'accessor-pairs': 2, 'arrow-spacing': [2, { 'before': true, @@ -44,7 +47,7 @@ module.exports = { 'curly': [2, 'multi-line'], 'dot-location': [2, 'property'], 'eol-last': 2, - 'eqeqeq': [2, 'allow-null'], + 'eqeqeq': ["error", "always", {"null": "ignore"}], 'generator-star-spacing': [2, { 'before': true, 'after': true @@ -73,7 +76,7 @@ module.exports = { 'no-class-assign': 2, 'no-cond-assign': 2, 'no-const-assign': 2, - 'no-control-regex': 2, + 'no-control-regex': 0, 'no-delete-var': 2, 'no-dupe-args': 2, 'no-dupe-class-members': 2, @@ -193,4 +196,3 @@ module.exports = { 'array-bracket-spacing': [2, 'never'] } } - diff --git a/.gitignore b/.gitignore index 78a0ead..9ad28d2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ npm-debug.log* yarn-debug.log* yarn-error.log* package-lock.json +tests/**/coverage/ # Editor directories and files .idea diff --git a/.postcssrc.js b/.postcssrc.js index eee3e92..10473ef 100644 --- a/.postcssrc.js +++ b/.postcssrc.js @@ -1,10 +1,8 @@ // https://github.com/michael-ciniawsky/postcss-load-config module.exports = { - "plugins": { - "postcss-import": {}, - "postcss-url": {}, + 'plugins': { // to edit target browsers: use "browserslist" field in package.json - "autoprefixer": {} + 'autoprefixer': {} } } diff --git a/README-zh.md b/README-zh.md index d3c3690..573deca 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,19 +1,17 @@ # vue-admin-template -> 这是一个 极简的 vue admin 管理后台 它只包含了 Element UI & axios & iconfont & permission control & lint,这些搭建后台必要的东西。 +> 这是一个极简的 vue admin 管理后台。它只包含了 Element UI & axios & iconfont & permission control & lint,这些搭建后台必要的东西。 [线上地址](http://panjiachen.github.io/vue-admin-template) [国内访问](https://panjiachen.gitee.io/vue-admin-template) +目前版本为 `v4.0+` 基于 `vue-cli` 进行构建,若发现问题,欢迎提 issue。若你想使用旧版本,可以切换分支到[tag/3.11.0](https://github.com/PanJiaChen/vue-admin-template/tree/tag/3.11.0),它不依赖 `vue-cli`。 + ## Extra 如果你想要根据用户角色来动态生成侧边栏和 router,你可以使用该分支[permission-control](https://github.com/PanJiaChen/vue-admin-template/tree/permission-control) -本项目基于`webpack4`开发,若还想使用`webpack3`开发,请使用该分支[webpack3](https://github.com/PanJiaChen/vue-admin-template/tree/webpack3) - -如果你想使用基于 vue + typescript 的管理后台, 可以看看这个项目: [vue-typescript-admin-template](https://github.com/Armour/vue-typescript-admin-template) (鸣谢: [@Armour](https://github.com/Armour)) - ## 相关项目 [vue-element-admin](https://github.com/PanJiaChen/vue-element-admin) @@ -33,54 +31,56 @@ ## Build Setup ```bash -# Clone project +# 克隆项目 git clone https://github.com/PanJiaChen/vue-admin-template.git -# Install dependencies +# 进入项目目录 +cd vue-admin-template + +# 安装依赖 npm install -# 建议不要用cnpm 安装有各种诡异的bug 可以通过如下操作解决npm速度慢的问题 +# 建议不要直接使用 cnpm 安装以来,会有各种诡异的 bug。可以通过如下操作解决 npm 下载速度慢的问题 npm install --registry=https://registry.npm.taobao.org -# Serve with hot reload at localhost:9528 +# 启动服务 npm run dev - -# Build for production with minification -npm run build - -# Build for production and view the bundle analyzer report -npm run build --report ``` +浏览器访问 [http://localhost:9528](http://localhost:9528) + +## 发布 + +```bash +# 构建测试环境 +npm run build:stage + +# 构建生产环境 +npm run build:prod +``` + +## 其它 + +```bash +# 预览发布环境效果 +npm run preview + +# 预览发布环境效果 + 静态资源分析 +npm run preview -- --report + +# 代码格式检查 +npm run lint + +# 代码格式检查并自动修复 +npm run lint -- --fix +``` + +更多信息请参考 [使用文档](https://panjiachen.github.io/vue-element-admin-site/zh/) + ## Demo ![demo](https://github.com/PanJiaChen/PanJiaChen.github.io/blob/master/images/demo.gif) -### Element-Ui 使用 cdn 教程 - -首先找到 `index.html` ([根目录下](https://github.com/PanJiaChen/vue-admin-template/blob/element-ui-cdn/index.html)) - -引入 Element 的 css 和 js ,并且引入 vue 。因为 Element-Ui 是依赖 vue 的,所以必须在它之前引入 vue 。 - -之后找到 [webpack.base.conf.js](https://github.com/PanJiaChen/vue-admin-template/blob/element-ui-cdn/build/webpack.base.conf.js) 加入 `externals` 让 webpack 不打包 vue 和 element - -``` -externals: { - vue: 'Vue', - 'element-ui':'ELEMENT' -} -``` - -之后还有一个小细节是如果你用了全局对象方式引入 vue,就不需要 手动 `Vue.use(Vuex)` ,它会自动挂载,具体见 [issue](https://github.com/vuejs/vuex/issues/731) - -最终你可以使用 `npm run build --report` 查看效果 -如图: -![demo](https://panjiachen.github.io/images/element-cdn.png) - -**[具体代码](https://github.com/PanJiaChen/vue-admin-template/commit/746aff560932704ae821f82f10b8b2a9681d5177)** - -**[对应分支](https://github.com/PanJiaChen/vue-admin-template/tree/element-ui-cdn)** - ## Browsers support Modern browsers and Internet Explorer 10+. diff --git a/README.md b/README.md index e65db28..7ceba5b 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,61 @@ # vue-admin-template +English | [简体中文](./README.zh-CN.md) + > A minimal vue admin template with Element UI & axios & iconfont & permission control & lint **Live demo:** http://panjiachen.github.io/vue-admin-template -[中文文档](https://github.com/PanJiaChen/vue-admin-template/blob/master/README-zh.md) + +**The current version is `v4.0+` build on `vue-cli`. If you want to use the old version , you can switch branch to [tag/3.11.0](https://github.com/PanJiaChen/vue-admin-template/tree/tag/3.11.0), it does not rely on `vue-cli'** ## Build Setup -```bash -# Clone project -git clone https://github.com/PanJiaChen/vue-admin-template.git -# Install dependencies +```bash +# clone the project +git clone https://github.com/PanJiaChen/vue-element-admin.git + +# enter the project directory +cd vue-element-admin + +# install dependency npm install -# Serve with hot reload at localhost:9528 +# develop npm run dev - -# Build for production with minification -npm run build - -# Build for production and view the bundle analyzer report -npm run build --report ``` +This will automatically open http://localhost:9527 + +## Build + +```bash +# build for test environment +npm run build:stage + +# build for production environment +npm run build:prod +``` + +## Advanced + +```bash +# preview the release environment effect +npm run preview + +# preview the release environment effect + static resource analysis +npm run preview -- --report + +# code format check +npm run lint + +# code format check and auto fix +npm run lint -- --fix +``` + +Refer to [Documentation](https://panjiachen.github.io/vue-element-admin-site/guide/essentials/deploy.html) for more information + ## Demo ![demo](https://github.com/PanJiaChen/PanJiaChen.github.io/blob/master/images/demo.gif) @@ -33,8 +64,6 @@ npm run build --report If you want router permission && generate menu by user roles , you can use this branch [permission-control](https://github.com/PanJiaChen/vue-admin-template/tree/permission-control) -This project is based on `webpack4` development. If you want to use `webpack3` development, please use this branch [webpack3](https://github.com/PanJiaChen/vue-admin-template/tree/webpack3) - For `typescript` version, you can use [vue-typescript-admin-template](https://github.com/Armour/vue-typescript-admin-template) (Credits: [@Armour](https://github.com/Armour)) ## Related Project @@ -45,34 +74,6 @@ For `typescript` version, you can use [vue-typescript-admin-template](https://gi [vue-typescript-admin-template](https://github.com/Armour/vue-typescript-admin-template) -### Element-Ui using cdn tutorial - -First find `index.html`([root directory](https://github.com/PanJiaChen/vue-admin-template/blob/element-ui-cdn/index.html)) - -Import css and js of `Element`, and then import vue. Because `Element` is vue-dependent, vue must be import before it. - -Then find [webpack.base.conf.js](https://github.com/PanJiaChen/vue-admin-template/blob/element-ui-cdn/build/webpack.base.conf.js) -Add `externals` to make webpack not package vue and element. - -``` -externals: { - vue: 'Vue', - 'element-ui':'ELEMENT' -} -``` - -Finally there is a small detail to pay attention to that if you import vue in global, you don't need to manually `Vue.use(Vuex)`, it will be automatically mounted, see -[issue](https://github.com/vuejs/vuex/issues/731) - -And you can use `npm run build --report` to see the effect - -Pictured: -![demo](https://panjiachen.github.io/images/element-cdn.png) - -**[Detailed code](https://github.com/PanJiaChen/vue-admin-template/commit/746aff560932704ae821f82f10b8b2a9681d5177)** - -**[Branch](https://github.com/PanJiaChen/vue-admin-template/tree/element-ui-cdn)** - ## Browsers support Modern browsers and Internet Explorer 10+. diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..ba17966 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,5 @@ +module.exports = { + presets: [ + '@vue/app' + ] +} diff --git a/build/build.js b/build/build.js deleted file mode 100644 index 8c6cebd..0000000 --- a/build/build.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict' -require('./check-versions')() - -process.env.NODE_ENV = 'production' - -const ora = require('ora') -const rm = require('rimraf') -const path = require('path') -const chalk = require('chalk') -const webpack = require('webpack') -const config = require('../config') -const webpackConfig = require('./webpack.prod.conf') - -const spinner = ora('building for production...') -spinner.start() - -rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { - if (err) throw err - webpack(webpackConfig, (err, stats) => { - spinner.stop() - if (err) throw err - process.stdout.write( - stats.toString({ - colors: true, - modules: false, - children: false, - chunks: false, - chunkModules: false - }) + '\n\n' - ) - - if (stats.hasErrors()) { - console.log(chalk.red(' Build failed with errors.\n')) - process.exit(1) - } - - console.log(chalk.cyan(' Build complete.\n')) - console.log( - chalk.yellow( - ' Tip: built files are meant to be served over an HTTP server.\n' + - " Opening index.html over file:// won't work.\n" - ) - ) - }) -}) diff --git a/build/check-versions.js b/build/check-versions.js deleted file mode 100644 index c5c29e9..0000000 --- a/build/check-versions.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict' -const chalk = require('chalk') -const semver = require('semver') -const packageConfig = require('../package.json') -const shell = require('shelljs') - -function exec(cmd) { - return require('child_process') - .execSync(cmd) - .toString() - .trim() -} - -const versionRequirements = [ - { - name: 'node', - currentVersion: semver.clean(process.version), - versionRequirement: packageConfig.engines.node - } -] - -if (shell.which('npm')) { - versionRequirements.push({ - name: 'npm', - currentVersion: exec('npm --version'), - versionRequirement: packageConfig.engines.npm - }) -} - -module.exports = function() { - const warnings = [] - - for (let i = 0; i < versionRequirements.length; i++) { - const mod = versionRequirements[i] - - if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { - warnings.push( - mod.name + - ': ' + - chalk.red(mod.currentVersion) + - ' should be ' + - chalk.green(mod.versionRequirement) - ) - } - } - - if (warnings.length) { - console.log('') - console.log( - chalk.yellow( - 'To use this template, you must update following to modules:' - ) - ) - console.log() - - for (let i = 0; i < warnings.length; i++) { - const warning = warnings[i] - console.log(' ' + warning) - } - - console.log() - process.exit(1) - } -} diff --git a/build/index.js b/build/index.js new file mode 100644 index 0000000..0c57de2 --- /dev/null +++ b/build/index.js @@ -0,0 +1,35 @@ +const { run } = require('runjs') +const chalk = require('chalk') +const config = require('../vue.config.js') +const rawArgv = process.argv.slice(2) +const args = rawArgv.join(' ') + +if (process.env.npm_config_preview || rawArgv.includes('--preview')) { + const report = rawArgv.includes('--report') + + run(`vue-cli-service build ${args}`) + + const port = 9526 + const publicPath = config.publicPath + + var connect = require('connect') + var serveStatic = require('serve-static') + const app = connect() + + app.use( + publicPath, + serveStatic('./dist', { + index: ['index.html', '/'] + }) + ) + + app.listen(port, function () { + console.log(chalk.green(`> Preview at http://localhost:${port}${publicPath}`)) + if (report) { + console.log(chalk.green(`> Report at http://localhost:${port}${publicPath}report.html`)) + } + + }) +} else { + run(`vue-cli-service build ${args}`) +} diff --git a/build/logo.png b/build/logo.png deleted file mode 100644 index f3d2503fc2a44b5053b0837ebea6e87a2d339a43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6849 zcmaKRcUV(fvo}bjDT-7nLI_nlK}sT_69H+`qzVWDA|yaU?}j417wLi^B1KB1SLsC& zL0ag7$U(XW5YR7p&Ux?sP$d4lvMt8C^+TcQu4F zQqv!UF!I+kw)c0jhd6+g6oCr9P?7)?!qX1ui*iL{p}sKCAGuJ{{W)0z1pLF|=>h}& zt(2Lr0Z`2ig8<5i%Zk}cO5Fm=LByqGWaS`oqChZdEFmc`0hSb#gg|Aap^{+WKOYcj zHjINK)KDG%&s?Mt4CL(T=?;~U@bU2x_mLKN!#GJuK_CzbNw5SMEJorG!}_5;?R>@1 zSl)jns3WlU7^J%=(hUtfmuUCU&C3%8B5C^f5>W2Cy8jW3#{Od{lF1}|?c61##3dzA zsPlFG;l_FzBK}8>|H_Ru_H#!_7$UH4UKo3lKOA}g1(R&|e@}GINYVzX?q=_WLZCgh z)L|eJMce`D0EIwgRaNETDsr+?vQknSGAi=7H00r`QnI%oQnFxm`G2umXso9l+8*&Q z7WqF|$p49js$mdzo^BXpH#gURy=UO;=IMrYc5?@+sR4y_?d*~0^YP7d+y0{}0)zBM zIKVM(DBvICK#~7N0a+PY6)7;u=dutmNqK3AlsrUU9U`d;msiucB_|8|2kY=(7XA;G zwDA8AR)VCA#JOkxm#6oHNS^YVuOU;8p$N)2{`;oF|rQ?B~K$%rHDxXs+_G zF5|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e6EHHw*l68j;>(ya`g^S&y2{O8U>1*>4zR zq*WSI_2o$CHQ?x0!wl9bpx|Cm2+kFMR)oMud1%n2=qn5nE&t@Fgr#=Zv2?}wtEz^T z9rrj=?IH*qI5{G@Rn&}^Z{+TW}mQeb9=8b<_a`&Cm#n%n~ zU47MvCBsdXFB1+adOO)03+nczfWa#vwk#r{o{dF)QWya9v2nv43Zp3%Ps}($lA02*_g25t;|T{A5snSY?3A zrRQ~(Ygh_ebltHo1VCbJb*eOAr;4cnlXLvI>*$-#AVsGg6B1r7@;g^L zFlJ_th0vxO7;-opU@WAFe;<}?!2q?RBrFK5U{*ai@NLKZ^};Ul}beukveh?TQn;$%9=R+DX07m82gP$=}Uo_%&ngV`}Hyv8g{u z3SWzTGV|cwQuFIs7ZDOqO_fGf8Q`8MwL}eUp>q?4eqCmOTcwQuXtQckPy|4F1on8l zP*h>d+cH#XQf|+6c|S{7SF(Lg>bR~l(0uY?O{OEVlaxa5@e%T&xju=o1`=OD#qc16 zSvyH*my(dcp6~VqR;o(#@m44Lug@~_qw+HA=mS#Z^4reBy8iV?H~I;{LQWk3aKK8$bLRyt$g?- { - const notifier = require('node-notifier') - - return (severity, errors) => { - if (severity !== 'error') return - - const error = errors[0] - const filename = error.file && error.file.split('!').pop() - - notifier.notify({ - title: packageConfig.name, - message: severity + ': ' + error.name, - subtitle: filename || '', - icon: path.join(__dirname, 'logo.png') - }) - } -} diff --git a/build/vue-loader.conf.js b/build/vue-loader.conf.js deleted file mode 100644 index 5496c93..0000000 --- a/build/vue-loader.conf.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict' - -module.exports = { - //You can set the vue-loader configuration by yourself. -} diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js deleted file mode 100644 index c9529f7..0000000 --- a/build/webpack.base.conf.js +++ /dev/null @@ -1,108 +0,0 @@ -'use strict' -const path = require('path') -const utils = require('./utils') -const config = require('../config') -const { VueLoaderPlugin } = require('vue-loader') -const vueLoaderConfig = require('./vue-loader.conf') - -function resolve(dir) { - return path.join(__dirname, '..', dir) -} - -const createLintingRule = () => ({ - test: /\.(js|vue)$/, - loader: 'eslint-loader', - enforce: 'pre', - include: [resolve('src'), resolve('test')], - options: { - formatter: require('eslint-friendly-formatter'), - emitWarning: !config.dev.showEslintErrorsInOverlay - } -}) - -module.exports = { - context: path.resolve(__dirname, '../'), - entry: { - app: './src/main.js' - }, - output: { - path: config.build.assetsRoot, - filename: '[name].js', - publicPath: - process.env.NODE_ENV === 'production' - ? config.build.assetsPublicPath - : config.dev.assetsPublicPath - }, - resolve: { - extensions: ['.js', '.vue', '.json'], - alias: { - '@': resolve('src') - } - }, - module: { - rules: [ - ...(config.dev.useEslint ? [createLintingRule()] : []), - { - test: /\.vue$/, - loader: 'vue-loader', - options: vueLoaderConfig - }, - { - test: /\.js$/, - loader: 'babel-loader', - include: [ - resolve('src'), - resolve('test'), - resolve('mock'), - resolve('node_modules/webpack-dev-server/client') - ] - }, - { - test: /\.svg$/, - loader: 'svg-sprite-loader', - include: [resolve('src/icons')], - options: { - symbolId: 'icon-[name]' - } - }, - { - test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, - loader: 'url-loader', - exclude: [resolve('src/icons')], - options: { - limit: 10000, - name: utils.assetsPath('img/[name].[hash:7].[ext]') - } - }, - { - test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, - loader: 'url-loader', - options: { - limit: 10000, - name: utils.assetsPath('media/[name].[hash:7].[ext]') - } - }, - { - test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, - loader: 'url-loader', - options: { - limit: 10000, - name: utils.assetsPath('fonts/[name].[hash:7].[ext]') - } - } - ] - }, - plugins: [new VueLoaderPlugin()], - node: { - // prevent webpack from injecting useless setImmediate polyfill because Vue - // source contains it (although only uses it if it's native). - setImmediate: false, - // prevent webpack from injecting mocks to Node native modules - // that does not make sense for the client - dgram: 'empty', - fs: 'empty', - net: 'empty', - tls: 'empty', - child_process: 'empty' - } -} diff --git a/build/webpack.dev.conf.js b/build/webpack.dev.conf.js deleted file mode 100644 index d92516f..0000000 --- a/build/webpack.dev.conf.js +++ /dev/null @@ -1,95 +0,0 @@ -'use strict' -const path = require('path') -const utils = require('./utils') -const webpack = require('webpack') -const config = require('../config') -const merge = require('webpack-merge') -const baseWebpackConfig = require('./webpack.base.conf') -const HtmlWebpackPlugin = require('html-webpack-plugin') -const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') -const portfinder = require('portfinder') - -function resolve(dir) { - return path.join(__dirname, '..', dir) -} - -const HOST = process.env.HOST -const PORT = process.env.PORT && Number(process.env.PORT) - -const devWebpackConfig = merge(baseWebpackConfig, { - mode: 'development', - module: { - rules: utils.styleLoaders({ - sourceMap: config.dev.cssSourceMap, - usePostCSS: true - }) - }, - // cheap-module-eval-source-map is faster for development - devtool: config.dev.devtool, - - // these devServer options should be customized in /config/index.js - devServer: { - clientLogLevel: 'warning', - historyApiFallback: true, - hot: true, - compress: true, - host: HOST || config.dev.host, - port: PORT || config.dev.port, - open: config.dev.autoOpenBrowser, - overlay: config.dev.errorOverlay - ? { warnings: false, errors: true } - : false, - publicPath: config.dev.assetsPublicPath, - proxy: config.dev.proxyTable, - quiet: true, // necessary for FriendlyErrorsPlugin - watchOptions: { - poll: config.dev.poll - } - }, - plugins: [ - new webpack.DefinePlugin({ - 'process.env': require('../config/dev.env') - }), - new webpack.HotModuleReplacementPlugin(), - // https://github.com/ampedandwired/html-webpack-plugin - new HtmlWebpackPlugin({ - filename: 'index.html', - template: 'index.html', - inject: true, - favicon: resolve('favicon.ico'), - title: 'vue-admin-template' - }) - ] -}) - -module.exports = new Promise((resolve, reject) => { - portfinder.basePort = process.env.PORT || config.dev.port - portfinder.getPort((err, port) => { - if (err) { - reject(err) - } else { - // publish the new Port, necessary for e2e tests - process.env.PORT = port - // add port to devServer config - devWebpackConfig.devServer.port = port - - // Add FriendlyErrorsPlugin - devWebpackConfig.plugins.push( - new FriendlyErrorsPlugin({ - compilationSuccessInfo: { - messages: [ - `Your application is running here: http://${ - devWebpackConfig.devServer.host - }:${port}` - ] - }, - onErrors: config.dev.notifyOnErrors - ? utils.createNotifierCallback() - : undefined - }) - ) - - resolve(devWebpackConfig) - } - }) -}) diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js deleted file mode 100644 index 9009b9d..0000000 --- a/build/webpack.prod.conf.js +++ /dev/null @@ -1,177 +0,0 @@ -'use strict' -const path = require('path') -const utils = require('./utils') -const webpack = require('webpack') -const config = require('../config') -const merge = require('webpack-merge') -const baseWebpackConfig = require('./webpack.base.conf') -const CopyWebpackPlugin = require('copy-webpack-plugin') -const HtmlWebpackPlugin = require('html-webpack-plugin') -const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin') -const MiniCssExtractPlugin = require('mini-css-extract-plugin') -const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin') -const UglifyJsPlugin = require('uglifyjs-webpack-plugin') - -function resolve(dir) { - return path.join(__dirname, '..', dir) -} - -const env = require('../config/prod.env') - -// For NamedChunksPlugin -const seen = new Set() -const nameLength = 4 - -const webpackConfig = merge(baseWebpackConfig, { - mode: 'production', - module: { - rules: utils.styleLoaders({ - sourceMap: config.build.productionSourceMap, - extract: true, - usePostCSS: true - }) - }, - devtool: config.build.productionSourceMap ? config.build.devtool : false, - output: { - path: config.build.assetsRoot, - filename: utils.assetsPath('js/[name].[chunkhash:8].js'), - chunkFilename: utils.assetsPath('js/[name].[chunkhash:8].js') - }, - plugins: [ - // http://vuejs.github.io/vue-loader/en/workflow/production.html - new webpack.DefinePlugin({ - 'process.env': env - }), - // extract css into its own file - new MiniCssExtractPlugin({ - filename: utils.assetsPath('css/[name].[contenthash:8].css'), - chunkFilename: utils.assetsPath('css/[name].[contenthash:8].css') - }), - // generate dist index.html with correct asset hash for caching. - // you can customize output by editing /index.html - // see https://github.com/ampedandwired/html-webpack-plugin - new HtmlWebpackPlugin({ - filename: config.build.index, - template: 'index.html', - inject: true, - favicon: resolve('favicon.ico'), - title: 'vue-admin-template', - minify: { - removeComments: true, - collapseWhitespace: true, - removeAttributeQuotes: true - // more options: - // https://github.com/kangax/html-minifier#options-quick-reference - } - // default sort mode uses toposort which cannot handle cyclic deps - // in certain cases, and in webpack 4, chunk order in HTML doesn't - // matter anyway - }), - new ScriptExtHtmlWebpackPlugin({ - //`runtime` must same as runtimeChunk name. default is `runtime` - inline: /runtime\..*\.js$/ - }), - // keep chunk.id stable when chunk has no name - new webpack.NamedChunksPlugin(chunk => { - if (chunk.name) { - return chunk.name - } - const modules = Array.from(chunk.modulesIterable) - if (modules.length > 1) { - const hash = require('hash-sum') - const joinedHash = hash(modules.map(m => m.id).join('_')) - let len = nameLength - while (seen.has(joinedHash.substr(0, len))) len++ - seen.add(joinedHash.substr(0, len)) - return `chunk-${joinedHash.substr(0, len)}` - } else { - return modules[0].id - } - }), - // keep module.id stable when vender modules does not change - new webpack.HashedModuleIdsPlugin(), - // copy custom static assets - new CopyWebpackPlugin([ - { - from: path.resolve(__dirname, '../static'), - to: config.build.assetsSubDirectory, - ignore: ['.*'] - } - ]) - ], - optimization: { - splitChunks: { - chunks: 'all', - cacheGroups: { - libs: { - name: 'chunk-libs', - test: /[\\/]node_modules[\\/]/, - priority: 10, - chunks: 'initial' // 只打包初始时依赖的第三方 - }, - elementUI: { - name: 'chunk-elementUI', // 单独将 elementUI 拆包 - priority: 20, // 权重要大于 libs 和 app 不然会被打包进 libs 或者 app - test: /[\\/]node_modules[\\/]element-ui[\\/]/ - } - } - }, - runtimeChunk: 'single', - minimizer: [ - new UglifyJsPlugin({ - uglifyOptions: { - mangle: { - safari10: true - } - }, - sourceMap: config.build.productionSourceMap, - cache: true, - parallel: true - }), - // Compress extracted CSS. We are using this plugin so that possible - // duplicated CSS from different components can be deduped. - new OptimizeCSSAssetsPlugin() - ] - } -}) - -if (config.build.productionGzip) { - const CompressionWebpackPlugin = require('compression-webpack-plugin') - - webpackConfig.plugins.push( - new CompressionWebpackPlugin({ - algorithm: 'gzip', - test: new RegExp( - '\\.(' + config.build.productionGzipExtensions.join('|') + ')$' - ), - threshold: 10240, - minRatio: 0.8 - }) - ) -} - -if (config.build.generateAnalyzerReport || config.build.bundleAnalyzerReport) { - const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') - .BundleAnalyzerPlugin - - if (config.build.bundleAnalyzerReport) { - webpackConfig.plugins.push( - new BundleAnalyzerPlugin({ - analyzerPort: 8080, - generateStatsFile: false - }) - ) - } - - if (config.build.generateAnalyzerReport) { - webpackConfig.plugins.push( - new BundleAnalyzerPlugin({ - analyzerMode: 'static', - reportFilename: 'bundle-report.html', - openAnalyzer: false - }) - ) - } -} - -module.exports = webpackConfig diff --git a/config/dev.env.js b/config/dev.env.js deleted file mode 100644 index e3c8ffc..0000000 --- a/config/dev.env.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict' -const merge = require('webpack-merge') -const prodEnv = require('./prod.env') - -module.exports = merge(prodEnv, { - NODE_ENV: '"development"', - BASE_API: '"https://easy-mock.com/mock/5950a2419adc231f356a6636/vue-admin"', -}) diff --git a/config/index.js b/config/index.js deleted file mode 100644 index a42218c..0000000 --- a/config/index.js +++ /dev/null @@ -1,86 +0,0 @@ -'use strict' -// Template version: 1.2.6 -// see http://vuejs-templates.github.io/webpack for documentation. - -const path = require('path') - -module.exports = { - dev: { - // Paths - assetsSubDirectory: 'static', - assetsPublicPath: '/', - proxyTable: {}, - - // Various Dev Server settings - host: 'localhost', // can be overwritten by process.env.HOST - port: 9528, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined - autoOpenBrowser: true, - errorOverlay: true, - notifyOnErrors: false, - poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- - - // Use Eslint Loader? - // If true, your code will be linted during bundling and - // linting errors and warnings will be shown in the console. - useEslint: true, - // If true, eslint errors and warnings will also be shown in the error overlay - // in the browser. - showEslintErrorsInOverlay: false, - - /** - * Source Maps - */ - - // https://webpack.js.org/configuration/devtool/#development - devtool: 'cheap-source-map', - - // CSS Sourcemaps off by default because relative paths are "buggy" - // with this option, according to the CSS-Loader README - // (https://github.com/webpack/css-loader#sourcemaps) - // In our experience, they generally work as expected, - // just be aware of this issue when enabling this option. - cssSourceMap: false - }, - - build: { - // Template for index.html - index: path.resolve(__dirname, '../dist/index.html'), - - // Paths - assetsRoot: path.resolve(__dirname, '../dist'), - assetsSubDirectory: 'static', - - /** - * You can set by youself according to actual condition - * You will need to set this if you plan to deploy your site under a sub path, - * for example GitHub pages. If you plan to deploy your site to https://foo.github.io/bar/, - * then assetsPublicPath should be set to "/bar/". - * In most cases please use '/' !!! - */ - assetsPublicPath: '/', - - /** - * Source Maps - */ - - productionSourceMap: false, - // https://webpack.js.org/configuration/devtool/#production - devtool: 'source-map', - - // Gzip off by default as many popular static hosts such as - // Surge or Netlify already gzip all static assets for you. - // Before setting to `true`, make sure to: - // npm install --save-dev compression-webpack-plugin - productionGzip: false, - productionGzipExtensions: ['js', 'css'], - - // Run the build command with an extra argument to - // View the bundle analyzer report after build finishes: - // `npm run build --report` - // Set to `true` or `false` to always turn it on or off - bundleAnalyzerReport: process.env.npm_config_report || false, - - // `npm run build:prod --generate_report` - generateAnalyzerReport: process.env.npm_config_generate_report || false - } -} diff --git a/config/prod.env.js b/config/prod.env.js deleted file mode 100644 index 836ec67..0000000 --- a/config/prod.env.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict' -module.exports = { - NODE_ENV: '"production"', - BASE_API: '"https://easy-mock.com/mock/5950a2419adc231f356a6636/vue-admin"', -} diff --git a/index.html b/index.html deleted file mode 100644 index 8be7f4b..0000000 --- a/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - vue-admin-template - - -
- - - diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..143cdc8 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,24 @@ +module.exports = { + moduleFileExtensions: ['js', 'jsx', 'json', 'vue'], + transform: { + '^.+\\.vue$': 'vue-jest', + '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': + 'jest-transform-stub', + '^.+\\.jsx?$': 'babel-jest' + }, + moduleNameMapper: { + '^@/(.*)$': '/src/$1' + }, + snapshotSerializers: ['jest-serializer-vue'], + testMatch: [ + '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)' + ], + collectCoverageFrom: ['src/utils/**/*.{js,vue}', '!src/utils/auth.js', '!src/utils/request.js', 'src/components/**/*.{js,vue}'], + coverageDirectory: '/tests/unit/coverage', + // 'collectCoverage': true, + 'coverageReporters': [ + 'lcov', + 'text-summary' + ], + testURL: 'http://localhost/' +} diff --git a/mock/index.js b/mock/index.js index 9eb5a47..e14f94e 100644 --- a/mock/index.js +++ b/mock/index.js @@ -1,26 +1,66 @@ import Mock from 'mockjs' -import userAPI from './user' -import tableAPI from './table' +import { param2Obj } from '../src/utils' -// Fix an issue with setting withCredentials = true, cross-domain request lost cookies -// https://github.com/nuysoft/Mock/issues/300 -Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send -Mock.XHR.prototype.send = function() { - if (this.custom.xhr) { - this.custom.xhr.withCredentials = this.withCredentials || false +import user from './user' +import table from './table' + +const mocks = [ + ...user, + ...table +] + +// 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() { + // mock patch + // https://github.com/nuysoft/Mock/issues/300 + Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send + Mock.XHR.prototype.send = function() { + if (this.custom.xhr) { + this.custom.xhr.withCredentials = this.withCredentials || false + + if (this.responseType) { + this.custom.xhr.responseType = this.responseType + } + } + this.proxy_send(...arguments) + } + + function XHR2ExpressReqWrap(respond) { + return function(options) { + let result = null + if (respond instanceof Function) { + const { body, type, url } = options + // https://expressjs.com/en/4x/api.html#req + result = respond({ + method: type, + body: JSON.parse(body), + query: param2Obj(url) + }) + } else { + result = respond + } + return Mock.mock(result) + } + } + + for (const i of mocks) { + Mock.mock(new RegExp(i.url), i.type || 'get', XHR2ExpressReqWrap(i.response)) } - this.proxy_send(...arguments) } -// Mock.setup({ -// timeout: '350-600' -// }) -// User -Mock.mock(/\/user\/login/, 'post', userAPI.login) -Mock.mock(/\/user\/info/, 'get', userAPI.getInfo) -Mock.mock(/\/user\/logout/, 'post', userAPI.logout) +// for mock server +const responseFake = (url, type, respond) => { + return { + url: new RegExp(`/mock${url}`), + type: type || 'get', + response(req, res) { + res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond)) + } + } +} -// Table -Mock.mock(/\/table\/list/, 'get', tableAPI.list) - -export default Mock +export default mocks.map(route => { + return responseFake(route.url, route.type, route.response) +}) diff --git a/mock/mock-server.js b/mock/mock-server.js new file mode 100644 index 0000000..ccce04d --- /dev/null +++ b/mock/mock-server.js @@ -0,0 +1,64 @@ +const chokidar = require('chokidar') +const bodyParser = require('body-parser') +const chalk = require('chalk') +const path = require('path') + +const mockDir = path.join(process.cwd(), 'mock') + +function registerRoutes(app) { + let mockLastIndex + const { default: mocks } = require('./index.js') + for (const mock of mocks) { + app[mock.type](mock.url, mock.response) + mockLastIndex = app._router.stack.length + } + const mockRoutesLength = Object.keys(mocks).length + return { + mockRoutesLength: mockRoutesLength, + mockStartIndex: mockLastIndex - mockRoutesLength + } +} + +function unregisterRoutes() { + Object.keys(require.cache).forEach(i => { + if (i.includes(mockDir)) { + delete require.cache[require.resolve(i)] + } + }) +} + +module.exports = app => { + // es6 polyfill + require('@babel/register') + + // parse app.body + // https://expressjs.com/en/4x/api.html#req.body + app.use(bodyParser.json()) + app.use(bodyParser.urlencoded({ + extended: true + })) + + const mockRoutes = registerRoutes(app) + var mockRoutesLength = mockRoutes.mockRoutesLength + var mockStartIndex = mockRoutes.mockStartIndex + + // watch files, hot reload mock server + chokidar.watch(mockDir, { + ignored: /mock-server/, + ignoreInitial: true + }).on('all', (event, path) => { + if (event === 'change' || event === 'add') { + // remove mock routes stack + app._router.stack.splice(mockStartIndex, mockRoutesLength) + + // clear routes cache + unregisterRoutes() + + const mockRoutes = registerRoutes(app) + mockRoutesLength = mockRoutes.mockRoutesLength + mockStartIndex = mockRoutes.mockStartIndex + + console.log(chalk.magentaBright(`\n > Mock Server hot reload success! changed ${path}`)) + } + }) +} diff --git a/mock/table.js b/mock/table.js index 810b3c1..a072a21 100644 --- a/mock/table.js +++ b/mock/table.js @@ -1,20 +1,29 @@ import Mock from 'mockjs' -export default { - list: () => { - const items = Mock.mock({ - 'items|30': [{ - id: '@id', - title: '@sentence(10, 20)', - 'status|1': ['published', 'draft', 'deleted'], - author: 'name', - display_time: '@datetime', - pageviews: '@integer(300, 5000)' - }] - }) - return { - code: 20000, - data: items +const data = Mock.mock({ + 'items|30': [{ + id: '@id', + title: '@sentence(10, 20)', + 'status|1': ['published', 'draft', 'deleted'], + author: 'name', + display_time: '@datetime', + pageviews: '@integer(300, 5000)' + }] +}) + +export default [ + { + url: '/table/list', + type: 'get', + response: config => { + const items = data.items + return { + code: 20000, + data: { + total: items.length, + items: items + } + } } } -} +] diff --git a/mock/user.js b/mock/user.js index 81e82e0..43f93a0 100644 --- a/mock/user.js +++ b/mock/user.js @@ -1,4 +1,3 @@ -import { param2Obj } from './utils' const tokens = { admin: { @@ -24,41 +23,62 @@ const users = { } } -export default { - login: res => { - const { username } = JSON.parse(res.body) - const data = tokens[username] +export default [ + // user login + { + url: '/user/login', + type: 'post', + response: config => { + const { username } = config.body + const token = tokens[username] + + // mock error + if (!token) { + return { + code: 60204, + message: 'Account and password are incorrect.' + } + } - if (data) { return { code: 20000, - data + data: token } } - return { - code: 60204, - message: 'Account and password are incorrect.' - } }, - getInfo: res => { - const { token } = param2Obj(res.url) - const info = users[token] - if (info) { + // get user info + { + url: '/user/info\.*', + type: 'get', + response: config => { + const { token } = config.query + const info = users[token] + + // mock error + if (!info) { + return { + code: 50008, + message: 'Login failed, unable to get user details.' + } + } + return { code: 20000, data: info } } - return { - code: 50008, - message: 'Login failed, unable to get user details.' - } }, - logout: () => { - return { - code: 20000, - data: 'success' + + // user logout + { + url: '/user/logout', + type: 'post', + response: _ => { + return { + code: 20000, + data: 'success' + } } } -} +] diff --git a/mock/utils.js b/mock/utils.js deleted file mode 100644 index 7d5f7cb..0000000 --- a/mock/utils.js +++ /dev/null @@ -1,14 +0,0 @@ -export function param2Obj(url) { - const search = url.split('?')[1] - if (!search) { - return {} - } - return JSON.parse( - '{"' + - decodeURIComponent(search) - .replace(/"/g, '\\"') - .replace(/&/g, '","') - .replace(/=/g, '":"') + - '"}' - ) -} diff --git a/package.json b/package.json index 12294f9..bd8e864 100644 --- a/package.json +++ b/package.json @@ -1,82 +1,59 @@ { "name": "vue-admin-template", - "version": "3.9.0", - "license": "MIT", + "version": "4.1.0", "description": "A vue admin template with Element UI & axios & iconfont & permission control & lint", "author": "Pan ", + "license": "MIT", "scripts": { - "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", - "start": "npm run dev", - "build": "node build/build.js", - "build:report": "npm_config_report=true npm run build", + "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", "lint": "eslint --ext .js,.vue src", - "test": "npm run lint", + "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" }, "dependencies": { "axios": "0.18.0", - "element-ui": "2.4.6", + "element-ui": "2.7.2", "js-cookie": "2.2.0", - "mockjs": "1.0.1-beta3", "normalize.css": "7.0.0", "nprogress": "0.2.0", - "vue": "2.5.17", - "vue-router": "3.0.1", - "vuex": "3.0.1" + "path-to-regexp": "2.4.0", + "vue": "2.6.10", + "vue-router": "3.0.6", + "vuex": "3.1.0" }, "devDependencies": { - "autoprefixer": "8.5.0", - "babel-core": "6.26.0", - "babel-eslint": "8.2.6", - "babel-helper-vue-jsx-merge-props": "2.0.3", - "babel-loader": "7.1.5", - "babel-plugin-syntax-jsx": "6.18.0", - "babel-plugin-transform-runtime": "6.23.0", - "babel-plugin-transform-vue-jsx": "3.7.0", - "babel-preset-env": "1.7.0", - "babel-preset-stage-2": "6.24.1", - "chalk": "2.4.1", - "compression-webpack-plugin": "2.0.0", - "copy-webpack-plugin": "4.5.2", - "css-loader": "1.0.0", - "eslint": "4.19.1", - "eslint-friendly-formatter": "4.0.1", - "eslint-loader": "2.0.0", - "eslint-plugin-vue": "4.7.1", - "eventsource-polyfill": "0.9.6", - "file-loader": "1.1.11", - "friendly-errors-webpack-plugin": "1.7.0", - "html-webpack-plugin": "4.0.0-alpha", - "mini-css-extract-plugin": "0.4.1", - "node-notifier": "5.2.1", - "node-sass": "^4.7.2", - "optimize-css-assets-webpack-plugin": "5.0.0", - "ora": "3.0.0", - "path-to-regexp": "2.4.0", - "portfinder": "1.0.16", - "postcss-import": "12.0.0", - "postcss-loader": "2.1.6", - "postcss-url": "7.3.2", - "rimraf": "2.6.2", - "sass-loader": "7.0.3", - "script-ext-html-webpack-plugin": "2.0.1", - "semver": "5.5.0", - "shelljs": "0.8.2", - "svg-sprite-loader": "3.8.0", - "svgo": "1.0.5", - "uglifyjs-webpack-plugin": "1.2.7", - "url-loader": "1.0.1", - "vue-loader": "15.3.0", - "vue-style-loader": "4.1.2", - "vue-template-compiler": "2.5.17", - "webpack": "4.16.5", - "webpack-bundle-analyzer": "2.13.1", - "webpack-cli": "3.1.0", - "webpack-dev-server": "3.1.14", - "webpack-merge": "4.1.4" + "@babel/core": "7.0.0", + "@babel/register": "7.0.0", + "@vue/cli-plugin-babel": "3.6.0", + "@vue/cli-plugin-eslint": "3.6.0", + "@vue/cli-plugin-unit-jest": "3.6.3", + "@vue/cli-service": "3.6.0", + "@vue/test-utils": "1.0.0-beta.29", + "babel-core": "7.0.0-bridge.0", + "babel-eslint": "10.0.1", + "babel-jest": "23.6.0", + "chalk": "2.4.2", + "connect": "3.6.6", + "eslint": "5.15.3", + "eslint-plugin-vue": "5.2.2", + "html-webpack-plugin": "3.2.0", + "mockjs": "1.0.1-beta3", + "node-sass": "^4.9.0", + "runjs": "^4.3.2", + "sass-loader": "^7.1.0", + "script-ext-html-webpack-plugin": "2.1.3", + "script-loader": "0.7.2", + "serve-static": "^1.13.2", + "svg-sprite-loader": "4.1.3", + "svgo": "1.2.2", + "vue-template-compiler": "2.6.10" }, "engines": { - "node": ">= 6.0.0", + "node": ">=8.9", "npm": ">= 3.0.0" }, "browserslist": [ diff --git a/favicon.ico b/public/favicon.ico similarity index 100% rename from favicon.ico rename to public/favicon.ico diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..fa2be91 --- /dev/null +++ b/public/index.html @@ -0,0 +1,17 @@ + + + + + + + + <%= webpackConfig.name %> + + + +
+ + + diff --git a/src/App.vue b/src/App.vue index 721d3a3..ec9032c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,6 @@ diff --git a/src/api/login.js b/src/api/user.js similarity index 78% rename from src/api/login.js rename to src/api/user.js index 3758dec..de69f70 100644 --- a/src/api/login.js +++ b/src/api/user.js @@ -1,13 +1,10 @@ import request from '@/utils/request' -export function login(username, password) { +export function login(data) { return request({ url: '/user/login', method: 'post', - data: { - username, - password - } + data }) } diff --git a/src/components/Breadcrumb/index.vue b/src/components/Breadcrumb/index.vue index 0c8a7fb..29f9a04 100644 --- a/src/components/Breadcrumb/index.vue +++ b/src/components/Breadcrumb/index.vue @@ -2,7 +2,7 @@ - {{ item.meta.title }} + {{ item.meta.title }} {{ item.meta.title }} @@ -28,15 +28,23 @@ export default { }, methods: { getBreadcrumb() { - let matched = this.$route.matched.filter(item => item.name) - + // only show routes with meta.title + let matched = this.$route.matched.filter(item => item.meta && item.meta.title) const first = matched[0] - if (first && first.name !== 'dashboard') { + + if (!this.isDashboard(first)) { matched = [{ path: '/dashboard', meta: { title: 'Dashboard' }}].concat(matched) } this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false) }, + isDashboard(route) { + const name = route && route.name + if (!name) { + return false + } + return name.trim().toLocaleLowerCase() === 'Dashboard'.toLocaleLowerCase() + }, pathCompile(path) { // To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561 const { params } = this.$route @@ -55,15 +63,16 @@ export default { } - diff --git a/src/components/Hamburger/index.vue b/src/components/Hamburger/index.vue index 220d67e..368b002 100644 --- a/src/components/Hamburger/index.vue +++ b/src/components/Hamburger/index.vue @@ -1,5 +1,5 @@