├── .babelrc ├── .editorconfig ├── .gitignore ├── .postcssrc.js ├── LICENSE ├── README.md ├── build ├── build.js ├── check-versions.js ├── logo.png ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js ├── webpack.prod.conf.js └── webpack.test.conf.js ├── config ├── dev.env.js ├── index.js ├── prod.env.js └── test.env.js ├── index.html ├── package-lock.json ├── package.json ├── src ├── App.vue ├── api │ ├── auth.js │ ├── login.js │ ├── resource.js │ ├── role.js │ ├── router.js │ └── user.js ├── assets │ ├── css │ │ └── common.css │ └── images │ │ ├── loading.gif │ │ └── personal_avatar.png ├── components │ ├── resource │ │ └── resourceEdit.vue │ ├── role │ │ ├── roleEdit.vue │ │ └── rolePermission.vue │ ├── router │ │ └── routerEdit.vue │ ├── sidebar │ │ └── index.vue │ └── user │ │ ├── changePassword.vue │ │ ├── personalInfo.vue │ │ └── userEdit.vue ├── icons │ ├── index.js │ └── svg │ │ ├── 404.svg │ │ ├── bug.svg │ │ ├── chart.svg │ │ ├── clipboard.svg │ │ ├── component.svg │ │ ├── dashboard.svg │ │ ├── documentation.svg │ │ ├── drag.svg │ │ ├── email.svg │ │ ├── example.svg │ │ ├── excel.svg │ │ ├── eye.svg │ │ ├── form.svg │ │ ├── icon.svg │ │ ├── international.svg │ │ ├── language.svg │ │ ├── lock.svg │ │ ├── message.svg │ │ ├── money.svg │ │ ├── password.svg │ │ ├── people.svg │ │ ├── peoples.svg │ │ ├── qq.svg │ │ ├── shoppingCard.svg │ │ ├── star.svg │ │ ├── tab.svg │ │ ├── table.svg │ │ ├── theme.svg │ │ ├── trendChart1.svg │ │ ├── trendChart2.svg │ │ ├── trendChart3.svg │ │ ├── user.svg │ │ ├── wechat.svg │ │ └── zip.svg ├── main.js ├── router │ └── index.js ├── store │ ├── actions.js │ ├── getters.js │ ├── index.js │ ├── mutation-types.js │ └── mutations.js ├── utils │ └── request.js └── views │ ├── home │ └── index.vue │ ├── login │ └── index.vue │ ├── resource │ └── index.vue │ ├── role │ └── index.vue │ ├── router │ └── index.vue │ └── user │ └── index.vue ├── static └── .gitkeep └── test ├── e2e ├── custom-assertions │ └── elementCount.js ├── nightwatch.conf.js ├── runner.js └── specs │ └── test.js └── unit ├── .eslintrc ├── jest.conf.js ├── setup.js └── specs └── HelloWorld.spec.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false 5 | }], 6 | "stage-2" 7 | ], 8 | "plugins": ["transform-runtime"], 9 | "env": { 10 | "test": { 11 | "presets": ["env", "stage-2"], 12 | "plugins": ["transform-es2015-modules-commonjs", "dynamic-import-node"] 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #################idea######################## 2 | # DIY 3 | target/ 4 | 5 | # svn 6 | .svn/ 7 | # Linux System 8 | *~ 9 | 10 | # KDE directory preferences 11 | .directory 12 | 13 | # Linux trash folder which might appear on any partition or disk 14 | .Trash-* 15 | 16 | # Windows System 17 | # Windows image file caches 18 | Thumbs.db 19 | ehthumbs.db 20 | 21 | # Folder config file 22 | Desktop.ini 23 | 24 | # Recycle Bin used on file shares 25 | $RECYCLE.BIN/ 26 | 27 | # Windows Installer files 28 | *.cab 29 | *.msi 30 | *.msm 31 | *.msp 32 | 33 | # Windows shortcuts 34 | *.lnk 35 | 36 | # OSX System 37 | .DS_Store 38 | .AppleDouble 39 | .LSOverride 40 | 41 | # Icon must end with two \r 42 | Icon 43 | 44 | 45 | # Thumbnails 46 | ._* 47 | 48 | # Files that might appear in the root of a volume 49 | .DocumentRevisions-V100 50 | .fseventsd 51 | .Spotlight-V100 52 | .TemporaryItems 53 | .Trashes 54 | .VolumeIcon.icns 55 | 56 | # Directories potentially created on remote AFP share 57 | .AppleDB 58 | .AppleDesktop 59 | Network Trash Folder 60 | Temporary Items 61 | .apdisk 62 | 63 | # Eclipse 64 | *.pydevproject 65 | .metadata 66 | .gradle 67 | bin/ 68 | tmp/ 69 | *.tmp 70 | *.bak 71 | *.swp 72 | *~.nib 73 | local.properties 74 | .settings/ 75 | .loadpath 76 | 77 | # Eclipse Core 78 | .project 79 | 80 | # External tool builders 81 | .externalToolBuilders/ 82 | 83 | # Locally stored "Eclipse launch configurations" 84 | *.launch 85 | 86 | # CDT-specific 87 | .cproject 88 | 89 | # JDT-specific (Eclipse Java Development Tools) 90 | .classpath 91 | 92 | # Java annotation processor (APT) 93 | .factorypath 94 | # PDT-specific 95 | .buildpath 96 | # sbteclipse plugin 97 | .target 98 | # TeXlipse plugin 99 | .texlipse 100 | # JetBrains 101 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio 102 | *.iml 103 | ## Directory-based project format: 104 | .idea/ 105 | # if you remove the above rule, at least ignore the following: 106 | # User-specific stuff: 107 | # .idea/workspace.xml 108 | # .idea/tasks.xml 109 | # .idea/dictionaries 110 | # Sensitive or high-churn files: 111 | # .idea/dataSources.ids 112 | # .idea/dataSources.xml 113 | # .idea/sqlDataSources.xml 114 | # .idea/dynamic.xml 115 | # .idea/uiDesigner.xml 116 | # Gradle: 117 | # .idea/gradle.xml 118 | # .idea/libraries 119 | # Mongo Explorer plugin: 120 | # .idea/mongoSettings.xml 121 | ## File-based project format: 122 | *.ipr 123 | *.iws 124 | ## Plugin-specific files: 125 | # IntelliJ 126 | /out/ 127 | # mpeltonen/sbt-idea plugin 128 | .idea_modules/ 129 | # JIRA plugin 130 | atlassian-ide-plugin.xml 131 | # Crashlytics plugin (for Android Studio and IntelliJ) 132 | com_crashlytics_export_strings.xml 133 | crashlytics.properties 134 | crashlytics-build.properties 135 | 136 | ####################Node############## 137 | # Logs 138 | logs 139 | *.log 140 | npm-debug.log* 141 | yarn-debug.log* 142 | yarn-error.log* 143 | 144 | # Runtime data 145 | pids 146 | *.pid 147 | *.seed 148 | *.pid.lock 149 | 150 | # Directory for instrumented libs generated by jscoverage/JSCover 151 | lib-cov 152 | 153 | # Coverage directory used by tools like istanbul 154 | coverage 155 | 156 | # nyc test coverage 157 | .nyc_output 158 | 159 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 160 | .grunt 161 | 162 | # Bower dependency directory (https://bower.io/) 163 | bower_components 164 | 165 | # node-waf configuration 166 | .lock-wscript 167 | 168 | # Compiled binary addons (https://nodejs.org/api/addons.html) 169 | build/Release 170 | 171 | # Dependency directories 172 | node_modules/ 173 | jspm_packages/ 174 | 175 | # TypeScript v1 declaration files 176 | typings/ 177 | 178 | # Optional npm cache directory 179 | .npm 180 | 181 | # Optional eslint cache 182 | .eslintcache 183 | 184 | # Optional REPL history 185 | .node_repl_history 186 | 187 | # Output of 'npm pack' 188 | *.tgz 189 | 190 | # Yarn Integrity file 191 | .yarn-integrity 192 | 193 | # dotenv environment variables file 194 | .env 195 | .env.test 196 | 197 | # parcel-bundler cache (https://parceljs.org/) 198 | .cache 199 | 200 | # next.js build output 201 | .next 202 | 203 | # nuxt.js build output 204 | .nuxt 205 | 206 | # vuepress build output 207 | .vuepress/dist 208 | 209 | # Serverless directories 210 | .serverless/ 211 | 212 | # FuseBox cache 213 | .fusebox/ 214 | 215 | # DynamoDB Local files 216 | .dynamodb/ 217 | 218 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserslist" field in package.json 6 | "postcss-import": {}, 7 | "autoprefixer": {} 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zhcc-view前端权限控制策略 2 | 3 | ### 写在前面 4 | 首先,之前的开发权限控制趋于后端化,以spring security 和 shiro 为代表,都是基于RBAC的思路,以资源为权限基础,再以角色来绑定资源,最后通过角色来绑定用户。这种方式达到权限与用户的单独解耦,另外如果想增加一层,比如不同部门的相同角色,也可以按此方式增加即可。 5 | ### 利用Vue + Vue Router来实现 6 | 相对轻量级的前端框架以及配套的路由方案,与后端的权限即可对应。 7 | 8 | > 为什么不使用 LocalStorage / cookies 去保存登录凭据?这样可以全局访问很方便啊 9 | 10 | 首先是安全问题,不过不是主要问题,在有的方案里面提到,及时更新也是一种不错的方案,所以一种方式就是响应式Session。然后把处理session的js引用到所有组件中,这样就可以在组件内部访问到所有的变量和方法,当然也可以在引用js中访问。所以采用SessionStorage,在用户注销后,存储的jwt会失效。 来达到全局变量的优势,而且能够享受到Vue原本就有的响应式、计算属性等特性。简直就是一个完美的闭包变量。 11 | 上面的方案有个问题就是没有用动态路由,导致用户登录前不能初始化Vue应用,所以登陆页只能单独做,开始我也是这么做的,但始终觉得url跳转的体验不好,所以用动态路由解决了 的解决方案:如果您的公司没有 SSO,那么每个项目都只能重复造轮子做登录页,此时只能借助 vue-router 的钩子函数 beforeEach 控权: 12 | 13 | 其实有一个难点:就是在数据库实时改变权限,页面可以不做任何调整,自动响应(刷新都不需要)---一致性与实时的矛盾吧。 14 | 另外一个点:用到的实际上是vue + vuex + vue Router 15 | 16 | ### 墙裂推荐 17 | 建议使用postman,刚开始可能不习惯,但是花点时间稍微学一下,还是很有帮助的。不仅可以快速测试后端接口,而且可以随意构造http请求,包括认证,另外返回的响应很直观。 18 | 19 | ### 项目地址 20 | - 前端地址:https://github.com/hulichao/zhcc-view-source.git 21 | - 后端地址:https://github.com/hulichao/zhcc-server.git 22 | 23 | ### 参考 24 | 1. [用mixin全局共享状态实现的前端权限](https://github.com/OneWayTech/vue-auth-solution) 25 | 2. [基于Vue/Vue-Router/axios实现的前端用户权限控制解决方案](https://refined-x.com/2017/11/28/Vue2.0%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90%E6%8E%A7%E5%88%B6%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/) 26 | 27 | ## Donate 28 | If you are enjoying this app, please consider making a donation to keep it alive, I will try my best to dedicate more time or even full time to work on it. 29 |
30 |

31 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | require('./check-versions')() 3 | 4 | process.env.NODE_ENV = 'production' 5 | 6 | const ora = require('ora') 7 | const rm = require('rimraf') 8 | const path = require('path') 9 | const chalk = require('chalk') 10 | const webpack = require('webpack') 11 | const config = require('../config') 12 | const webpackConfig = require('./webpack.prod.conf') 13 | 14 | const spinner = ora('building for production...') 15 | spinner.start() 16 | 17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 18 | if (err) throw err 19 | webpack(webpackConfig, (err, stats) => { 20 | spinner.stop() 21 | if (err) throw err 22 | process.stdout.write(stats.toString({ 23 | colors: true, 24 | modules: false, 25 | children: false, 26 | chunks: false, 27 | chunkModules: false 28 | }) + '\n\n') 29 | 30 | if (stats.hasErrors()) { 31 | console.log(chalk.red(' Build failed with errors.\n')) 32 | process.exit(1) 33 | } 34 | 35 | console.log(chalk.cyan(' Build complete.\n')) 36 | console.log(chalk.yellow( 37 | ' Tip: built files are meant to be served over an HTTP server.\n' + 38 | ' Opening index.html over file:// won\'t work.\n' 39 | )) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const chalk = require('chalk') 3 | const semver = require('semver') 4 | const packageConfig = require('../package.json') 5 | const shell = require('shelljs') 6 | 7 | function exec (cmd) { 8 | return require('child_process').execSync(cmd).toString().trim() 9 | } 10 | 11 | const versionRequirements = [ 12 | { 13 | name: 'node', 14 | currentVersion: semver.clean(process.version), 15 | versionRequirement: packageConfig.engines.node 16 | } 17 | ] 18 | 19 | if (shell.which('npm')) { 20 | versionRequirements.push({ 21 | name: 'npm', 22 | currentVersion: exec('npm --version'), 23 | versionRequirement: packageConfig.engines.npm 24 | }) 25 | } 26 | 27 | module.exports = function () { 28 | const warnings = [] 29 | 30 | for (let i = 0; i < versionRequirements.length; i++) { 31 | const mod = versionRequirements[i] 32 | 33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 34 | warnings.push(mod.name + ': ' + 35 | chalk.red(mod.currentVersion) + ' should be ' + 36 | chalk.green(mod.versionRequirement) 37 | ) 38 | } 39 | } 40 | 41 | if (warnings.length) { 42 | console.log('') 43 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 44 | console.log() 45 | 46 | for (let i = 0; i < warnings.length; i++) { 47 | const warning = warnings[i] 48 | console.log(' ' + warning) 49 | } 50 | 51 | console.log() 52 | process.exit(1) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /build/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulichao/zhcc-view-source/bf188bfe97401d78390b8acf5235ab9e1b9fcbbe/build/logo.png -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const config = require('../config') 4 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 5 | const packageConfig = require('../package.json') 6 | 7 | exports.assetsPath = function (_path) { 8 | const assetsSubDirectory = process.env.NODE_ENV === 'production' 9 | ? config.build.assetsSubDirectory 10 | : config.dev.assetsSubDirectory 11 | 12 | return path.posix.join(assetsSubDirectory, _path) 13 | } 14 | 15 | exports.cssLoaders = function (options) { 16 | options = options || {} 17 | 18 | const cssLoader = { 19 | loader: 'css-loader', 20 | options: { 21 | sourceMap: options.sourceMap 22 | } 23 | } 24 | 25 | const postcssLoader = { 26 | loader: 'postcss-loader', 27 | options: { 28 | sourceMap: options.sourceMap 29 | } 30 | } 31 | 32 | // generate loader string to be used with extract text plugin 33 | function generateLoaders (loader, loaderOptions) { 34 | const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader] 35 | 36 | if (loader) { 37 | loaders.push({ 38 | loader: loader + '-loader', 39 | options: Object.assign({}, loaderOptions, { 40 | sourceMap: options.sourceMap 41 | }) 42 | }) 43 | } 44 | 45 | // Extract CSS when that option is specified 46 | // (which is the case during production build) 47 | if (options.extract) { 48 | return ExtractTextPlugin.extract({ 49 | use: loaders, 50 | fallback: 'vue-style-loader' 51 | }) 52 | } else { 53 | return ['vue-style-loader'].concat(loaders) 54 | } 55 | } 56 | 57 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 58 | return { 59 | css: generateLoaders(), 60 | postcss: generateLoaders(), 61 | less: generateLoaders('less'), 62 | sass: generateLoaders('sass', { indentedSyntax: true }), 63 | scss: generateLoaders('sass'), 64 | stylus: generateLoaders('stylus'), 65 | styl: generateLoaders('stylus') 66 | } 67 | } 68 | 69 | // Generate loaders for standalone style files (outside of .vue) 70 | exports.styleLoaders = function (options) { 71 | const output = [] 72 | const loaders = exports.cssLoaders(options) 73 | 74 | for (const extension in loaders) { 75 | const loader = loaders[extension] 76 | output.push({ 77 | test: new RegExp('\\.' + extension + '$'), 78 | use: loader 79 | }) 80 | } 81 | 82 | return output 83 | } 84 | 85 | exports.createNotifierCallback = () => { 86 | const notifier = require('node-notifier') 87 | 88 | return (severity, errors) => { 89 | if (severity !== 'error') return 90 | 91 | const error = errors[0] 92 | const filename = error.file && error.file.split('!').pop() 93 | 94 | notifier.notify({ 95 | title: packageConfig.name, 96 | message: severity + ': ' + error.name, 97 | subtitle: filename || '', 98 | icon: path.join(__dirname, 'logo.png') 99 | }) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const config = require('../config') 4 | const isProduction = process.env.NODE_ENV === 'production' 5 | const sourceMapEnabled = isProduction 6 | ? config.build.productionSourceMap 7 | : config.dev.cssSourceMap 8 | 9 | module.exports = { 10 | loaders: utils.cssLoaders({ 11 | sourceMap: sourceMapEnabled, 12 | extract: isProduction 13 | }), 14 | cssSourceMap: sourceMapEnabled, 15 | cacheBusting: config.dev.cacheBusting, 16 | transformToRequire: { 17 | video: ['src', 'poster'], 18 | source: 'src', 19 | img: 'src', 20 | image: 'xlink:href' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const config = require('../config') 5 | const vueLoaderConfig = require('./vue-loader.conf') 6 | 7 | function resolve (dir) { 8 | return path.join(__dirname, '..', dir) 9 | } 10 | 11 | const createLintingRule = () => ({ 12 | test: /\.(js|vue)$/, 13 | loader: 'eslint-loader', 14 | enforce: 'pre', 15 | include: [resolve('src'), resolve('test')], 16 | options: { 17 | formatter: require('eslint-friendly-formatter'), 18 | emitWarning: !config.dev.showEslintErrorsInOverlay 19 | } 20 | }) 21 | 22 | module.exports = { 23 | context: path.resolve(__dirname, '../'), 24 | entry: { 25 | app: './src/main.js' 26 | }, 27 | output: { 28 | path: config.build.assetsRoot, 29 | filename: '[name].js', 30 | publicPath: process.env.NODE_ENV === 'production' 31 | ? config.build.assetsPublicPath 32 | : config.dev.assetsPublicPath 33 | }, 34 | resolve: { 35 | extensions: ['.js', '.vue', '.json'], 36 | alias: { 37 | 'vue$': 'vue/dist/vue.esm.js', 38 | '@': resolve('src'), 39 | } 40 | }, 41 | module: { 42 | rules: [ 43 | { 44 | test: /\.vue$/, 45 | loader: 'vue-loader', 46 | options: vueLoaderConfig 47 | }, 48 | { 49 | test: /\.js$/, 50 | loader: 'babel-loader', 51 | include: [resolve('src'), resolve('test')] 52 | }, 53 | { 54 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 55 | loader: 'url-loader', 56 | options: { 57 | limit: 10000, 58 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 59 | } 60 | }, 61 | { 62 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 63 | loader: 'url-loader', 64 | options: { 65 | limit: 10000, 66 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 67 | } 68 | }, 69 | { 70 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 71 | loader: 'url-loader', 72 | options: { 73 | limit: 10000, 74 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 75 | } 76 | } 77 | ] 78 | }, 79 | node: { 80 | // prevent webpack from injecting useless setImmediate polyfill because Vue 81 | // source contains it (although only uses it if it's native). 82 | setImmediate: false, 83 | // prevent webpack from injecting mocks to Node native modules 84 | // that does not make sense for the client 85 | dgram: 'empty', 86 | fs: 'empty', 87 | net: 'empty', 88 | tls: 'empty', 89 | child_process: 'empty' 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const webpack = require('webpack') 4 | const config = require('../config') 5 | const merge = require('webpack-merge') 6 | const baseWebpackConfig = require('./webpack.base.conf') 7 | const HtmlWebpackPlugin = require('html-webpack-plugin') 8 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 9 | const portfinder = require('portfinder') 10 | 11 | const HOST = process.env.HOST 12 | const PORT = process.env.PORT && Number(process.env.PORT) 13 | 14 | const devWebpackConfig = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: config.dev.devtool, 20 | 21 | // these devServer options should be customized in /config/index.js 22 | devServer: { 23 | clientLogLevel: 'warning', 24 | historyApiFallback: true, 25 | hot: true, 26 | compress: true, 27 | host: HOST || config.dev.host, 28 | port: PORT || config.dev.port, 29 | open: config.dev.autoOpenBrowser, 30 | overlay: config.dev.errorOverlay 31 | ? { warnings: false, errors: true } 32 | : false, 33 | publicPath: config.dev.assetsPublicPath, 34 | proxy: config.dev.proxyTable, 35 | quiet: true, // necessary for FriendlyErrorsPlugin 36 | watchOptions: { 37 | poll: config.dev.poll, 38 | } 39 | }, 40 | plugins: [ 41 | new webpack.DefinePlugin({ 42 | 'process.env': require('../config/dev.env') 43 | }), 44 | new webpack.HotModuleReplacementPlugin(), 45 | new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update. 46 | new webpack.NoEmitOnErrorsPlugin(), 47 | // https://github.com/ampedandwired/html-webpack-plugin 48 | new HtmlWebpackPlugin({ 49 | filename: 'index.html', 50 | template: 'index.html', 51 | inject: true 52 | }), 53 | ] 54 | }) 55 | 56 | module.exports = new Promise((resolve, reject) => { 57 | portfinder.basePort = process.env.PORT || config.dev.port 58 | portfinder.getPort((err, port) => { 59 | if (err) { 60 | reject(err) 61 | } else { 62 | // publish the new Port, necessary for e2e tests 63 | process.env.PORT = port 64 | // add port to devServer config 65 | devWebpackConfig.devServer.port = port 66 | 67 | // Add FriendlyErrorsPlugin 68 | devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({ 69 | compilationSuccessInfo: { 70 | messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`], 71 | }, 72 | onErrors: config.dev.notifyOnErrors 73 | ? utils.createNotifierCallback() 74 | : undefined 75 | })) 76 | 77 | resolve(devWebpackConfig) 78 | } 79 | }) 80 | }) 81 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const webpack = require('webpack') 5 | const config = require('../config') 6 | const merge = require('webpack-merge') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | const CopyWebpackPlugin = require('copy-webpack-plugin') 9 | const HtmlWebpackPlugin = require('html-webpack-plugin') 10 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 11 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 12 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') 13 | 14 | const env = process.env.NODE_ENV === 'testing' 15 | ? require('../config/test.env') 16 | : require('../config/prod.env') 17 | 18 | const webpackConfig = merge(baseWebpackConfig, { 19 | module: { 20 | rules: utils.styleLoaders({ 21 | sourceMap: config.build.productionSourceMap, 22 | extract: true, 23 | usePostCSS: true 24 | }) 25 | }, 26 | devtool: config.build.productionSourceMap ? config.build.devtool : false, 27 | output: { 28 | path: config.build.assetsRoot, 29 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 30 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 31 | }, 32 | plugins: [ 33 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 34 | new webpack.DefinePlugin({ 35 | 'process.env': env 36 | }), 37 | new UglifyJsPlugin({ 38 | uglifyOptions: { 39 | compress: { 40 | warnings: false 41 | } 42 | }, 43 | sourceMap: config.build.productionSourceMap, 44 | parallel: true 45 | }), 46 | // extract css into its own file 47 | new ExtractTextPlugin({ 48 | filename: utils.assetsPath('css/[name].[contenthash].css'), 49 | // set the following option to `true` if you want to extract CSS from 50 | // codesplit chunks into this main css file as well. 51 | // This will result in *all* of your app's CSS being loaded upfront. 52 | allChunks: false, 53 | }), 54 | // Compress extracted CSS. We are using this plugin so that possible 55 | // duplicated CSS from different components can be deduped. 56 | new OptimizeCSSPlugin({ 57 | cssProcessorOptions: config.build.productionSourceMap 58 | ? { safe: true, map: { inline: false } } 59 | : { safe: true } 60 | }), 61 | // generate dist index.html with correct asset hash for caching. 62 | // you can customize output by editing /index.html 63 | // see https://github.com/ampedandwired/html-webpack-plugin 64 | new HtmlWebpackPlugin({ 65 | filename: process.env.NODE_ENV === 'testing' 66 | ? 'index.html' 67 | : config.build.index, 68 | template: 'index.html', 69 | inject: true, 70 | minify: { 71 | removeComments: true, 72 | collapseWhitespace: true, 73 | removeAttributeQuotes: true 74 | // more options: 75 | // https://github.com/kangax/html-minifier#options-quick-reference 76 | }, 77 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 78 | chunksSortMode: 'dependency' 79 | }), 80 | // keep module.id stable when vender modules does not change 81 | new webpack.HashedModuleIdsPlugin(), 82 | // enable scope hoisting 83 | new webpack.optimize.ModuleConcatenationPlugin(), 84 | // split vendor js into its own file 85 | new webpack.optimize.CommonsChunkPlugin({ 86 | name: 'vendor', 87 | minChunks (module) { 88 | // any required modules inside node_modules are extracted to vendor 89 | return ( 90 | module.resource && 91 | /\.js$/.test(module.resource) && 92 | module.resource.indexOf( 93 | path.join(__dirname, '../node_modules') 94 | ) === 0 95 | ) 96 | } 97 | }), 98 | // extract webpack runtime and module manifest to its own file in order to 99 | // prevent vendor hash from being updated whenever app bundle is updated 100 | new webpack.optimize.CommonsChunkPlugin({ 101 | name: 'manifest', 102 | minChunks: Infinity 103 | }), 104 | // This instance extracts shared chunks from code splitted chunks and bundles them 105 | // in a separate chunk, similar to the vendor chunk 106 | // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk 107 | new webpack.optimize.CommonsChunkPlugin({ 108 | name: 'app', 109 | async: 'vendor-async', 110 | children: true, 111 | minChunks: 3 112 | }), 113 | 114 | // copy custom static assets 115 | new CopyWebpackPlugin([ 116 | { 117 | from: path.resolve(__dirname, '../static'), 118 | to: config.build.assetsSubDirectory, 119 | ignore: ['.*'] 120 | } 121 | ]) 122 | ] 123 | }) 124 | 125 | if (config.build.productionGzip) { 126 | const CompressionWebpackPlugin = require('compression-webpack-plugin') 127 | 128 | webpackConfig.plugins.push( 129 | new CompressionWebpackPlugin({ 130 | asset: '[path].gz[query]', 131 | algorithm: 'gzip', 132 | test: new RegExp( 133 | '\\.(' + 134 | config.build.productionGzipExtensions.join('|') + 135 | ')$' 136 | ), 137 | threshold: 10240, 138 | minRatio: 0.8 139 | }) 140 | ) 141 | } 142 | 143 | if (config.build.bundleAnalyzerReport) { 144 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 145 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 146 | } 147 | 148 | module.exports = webpackConfig 149 | -------------------------------------------------------------------------------- /build/webpack.test.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // This is the webpack config used for unit tests. 3 | 4 | const utils = require('./utils') 5 | const webpack = require('webpack') 6 | const merge = require('webpack-merge') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | 9 | const webpackConfig = merge(baseWebpackConfig, { 10 | // use inline sourcemap for karma-sourcemap-loader 11 | module: { 12 | rules: utils.styleLoaders() 13 | }, 14 | devtool: '#inline-source-map', 15 | resolveLoader: { 16 | alias: { 17 | // necessary to to make lang="scss" work in test when using vue-loader's ?inject option 18 | // see discussion at https://github.com/vuejs/vue-loader/issues/724 19 | 'scss-loader': 'sass-loader' 20 | } 21 | }, 22 | plugins: [ 23 | new webpack.DefinePlugin({ 24 | 'process.env': require('../config/test.env') 25 | }) 26 | ] 27 | }) 28 | 29 | // no need for app entry during tests 30 | delete webpackConfig.entry 31 | 32 | module.exports = webpackConfig 33 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const prodEnv = require('./prod.env') 4 | 5 | module.exports = merge(prodEnv, { 6 | NODE_ENV: '"development"', 7 | BASE_API: '"http://localhost:8080"' 8 | }) 9 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // Template version: 1.2.5 3 | // see http://vuejs-templates.github.io/webpack for documentation. 4 | 5 | const path = require('path') 6 | 7 | module.exports = { 8 | dev: { 9 | 10 | // Paths 11 | assetsSubDirectory: 'static', 12 | assetsPublicPath: '/', 13 | proxyTable: {}, 14 | 15 | // Various Dev Server settings 16 | host: 'localhost', // can be overwritten by process.env.HOST 17 | port: 9090, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined 18 | autoOpenBrowser: false, 19 | errorOverlay: true, 20 | notifyOnErrors: true, 21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- 22 | 23 | // Use Eslint Loader? 24 | // If true, your code will be linted during bundling and 25 | // linting errors and warnings will be shown in the console. 26 | useEslint: true, 27 | // If true, eslint errors and warnings will also be shown in the error overlay 28 | // in the browser. 29 | showEslintErrorsInOverlay: false, 30 | 31 | /** 32 | * Source Maps 33 | */ 34 | 35 | // https://webpack.js.org/configuration/devtool/#development 36 | devtool: 'eval-source-map', 37 | 38 | // If you have problems debugging vue-files in devtools, 39 | // set this to false - it *may* help 40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting 41 | cacheBusting: true, 42 | 43 | // CSS Sourcemaps off by default because relative paths are "buggy" 44 | // with this option, according to the CSS-Loader README 45 | // (https://github.com/webpack/css-loader#sourcemaps) 46 | // In our experience, they generally work as expected, 47 | // just be aware of this issue when enabling this option. 48 | cssSourceMap: false, 49 | }, 50 | 51 | build: { 52 | // Template for index.html 53 | index: path.resolve(__dirname, '../dist/index.html'), 54 | 55 | // Paths 56 | assetsRoot: path.resolve(__dirname, '../dist'), 57 | assetsSubDirectory: 'static', 58 | assetsPublicPath: '/', 59 | 60 | /** 61 | * Source Maps 62 | */ 63 | 64 | productionSourceMap: true, 65 | // https://webpack.js.org/configuration/devtool/#production 66 | devtool: '#source-map', 67 | 68 | // Gzip off by default as many popular static hosts such as 69 | // Surge or Netlify already gzip all static assets for you. 70 | // Before setting to `true`, make sure to: 71 | // npm install --save-dev compression-webpack-plugin 72 | productionGzip: false, 73 | productionGzipExtensions: ['js', 'css'], 74 | 75 | // Run the build command with an extra argument to 76 | // View the bundle analyzer report after build finishes: 77 | // `npm run build --report` 78 | // Set to `true` or `false` to always turn it on or off 79 | bundleAnalyzerReport: process.env.npm_config_report 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = { 3 | NODE_ENV: '"production"', 4 | BASE_API: '"http://localhost:8080"' 5 | } 6 | -------------------------------------------------------------------------------- /config/test.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const devEnv = require('./dev.env') 4 | 5 | module.exports = merge(devEnv, { 6 | NODE_ENV: '"testing"' 7 | }) 8 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | zhcc-view 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zhcc-view", 3 | "version": "1.0.0", 4 | "description": "zhcc web client", 5 | "author": "Hoult", 6 | "private": true, 7 | "scripts": { 8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", 9 | "start": "npm run dev", 10 | "unit": "jest --config test/unit/jest.conf.js --coverage", 11 | "e2e": "node test/e2e/runner.js", 12 | "test": "npm run unit && npm run e2e", 13 | "build": "node build/build.js" 14 | }, 15 | "dependencies": { 16 | "axios": "^0.17.1", 17 | "element-ui": "^2.2.0", 18 | "qs": "^6.5.1", 19 | "requirejs": "^2.3.5", 20 | "vue": "^2.5.13", 21 | "vue-router": "^3.0.1", 22 | "vuex": "^3.0.1" 23 | }, 24 | "devDependencies": { 25 | "autoprefixer": "^7.1.2", 26 | "babel-core": "^6.22.1", 27 | "babel-jest": "^21.0.2", 28 | "babel-loader": "^7.1.1", 29 | "babel-plugin-dynamic-import-node": "^1.2.0", 30 | "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0", 31 | "babel-plugin-transform-runtime": "^6.22.0", 32 | "babel-preset-env": "^1.3.2", 33 | "babel-preset-stage-2": "^6.22.0", 34 | "babel-register": "^6.22.0", 35 | "chalk": "^2.0.1", 36 | "chromedriver": "^2.27.2", 37 | "copy-webpack-plugin": "^4.0.1", 38 | "cross-spawn": "^5.0.1", 39 | "css-loader": "^0.28.0", 40 | "eventsource-polyfill": "^0.9.6", 41 | "extract-text-webpack-plugin": "^3.0.0", 42 | "file-loader": "^1.1.4", 43 | "friendly-errors-webpack-plugin": "^1.6.1", 44 | "html-webpack-plugin": "^2.30.1", 45 | "jest": "^21.2.0", 46 | "jest-serializer-vue": "^0.3.0", 47 | "nightwatch": "^0.9.12", 48 | "node-notifier": "^5.1.2", 49 | "node-sass": "^4.7.2", 50 | "optimize-css-assets-webpack-plugin": "^3.2.0", 51 | "ora": "^1.2.0", 52 | "portfinder": "^1.0.13", 53 | "postcss-import": "^11.0.0", 54 | "postcss-loader": "^2.0.8", 55 | "rimraf": "^2.6.0", 56 | "sass-loader": "^6.0.6", 57 | "selenium-server": "^3.0.1", 58 | "semver": "^5.3.0", 59 | "shelljs": "^0.7.6", 60 | "uglifyjs-webpack-plugin": "^1.1.1", 61 | "url-loader": "^0.5.8", 62 | "vue-jest": "^1.0.2", 63 | "vue-loader": "^13.3.0", 64 | "vue-style-loader": "^3.0.1", 65 | "vue-template-compiler": "^2.5.2", 66 | "webpack": "^3.6.0", 67 | "webpack-bundle-analyzer": "^2.9.0", 68 | "webpack-dev-server": "^2.9.1", 69 | "webpack-merge": "^4.1.0" 70 | }, 71 | "engines": { 72 | "node": ">= 4.0.0", 73 | "npm": ">= 3.0.0" 74 | }, 75 | "browserslist": [ 76 | "> 1%", 77 | "last 2 versions", 78 | "not ie <= 8" 79 | ], 80 | "main": ".postcssrc.js", 81 | "directories": { 82 | "test": "test" 83 | }, 84 | "repository": { 85 | "type": "git", 86 | "url": "git+https://github.com/hulichao/zhcc-view-source.git" 87 | }, 88 | "license": "ISC", 89 | "bugs": { 90 | "url": "https://github.com/hulichao/zhcc-view-source/issues" 91 | }, 92 | "homepage": "https://github.com/hulichao/zhcc-view-source#readme" 93 | } 94 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /src/api/auth.js: -------------------------------------------------------------------------------- 1 | import request from '@/utils/request' 2 | import qs from 'qs' 3 | 4 | export const getToken = (loginName, password) => 5 | request({ 6 | url: '/auth/token', 7 | method: 'post', 8 | data: qs.stringify({ 9 | loginName, 10 | password 11 | }) 12 | }) -------------------------------------------------------------------------------- /src/api/login.js: -------------------------------------------------------------------------------- 1 | import request from '@/utils/request' 2 | import qs from 'qs' 3 | 4 | export const loginByUsername = (username, password) => 5 | request({ 6 | url: '/login', 7 | method: 'post', 8 | data: qs.stringify({ 9 | username, 10 | password 11 | }) 12 | }) -------------------------------------------------------------------------------- /src/api/resource.js: -------------------------------------------------------------------------------- 1 | import request from '@/utils/request' 2 | 3 | export const listResource = (routerId) => 4 | request({ 5 | url: '/resources?routerId=' + routerId, 6 | method: 'get' 7 | }) 8 | 9 | export const getResourceById = (id) => 10 | request({ 11 | url: '/resources/' + id, 12 | method: 'get' 13 | }) 14 | 15 | export const saveResource = (resource) => 16 | request({ 17 | url: '/resources', 18 | method: 'post', 19 | data: resource 20 | }) 21 | 22 | export const updateResource = (id, resource) => 23 | request({ 24 | url: '/resources/' + id, 25 | method: 'put', 26 | data: resource 27 | }) 28 | 29 | export const removeResource = (id) => 30 | request({ 31 | url: '/resources/' + id, 32 | method: 'delete' 33 | }) 34 | 35 | export const listResourcePermission = (routerId) => 36 | request({ 37 | url: '/resources/permissions', 38 | method: 'get', 39 | params: { 40 | routerId: routerId 41 | } 42 | }) 43 | 44 | export const listAvailableResource = () => 45 | request({ 46 | url: '/resources/available', 47 | method: 'get' 48 | }) -------------------------------------------------------------------------------- /src/api/role.js: -------------------------------------------------------------------------------- 1 | import request from '@/utils/request' 2 | 3 | export const listRole = (search) => 4 | request({ 5 | url: '/roles', 6 | method: 'get', 7 | params: { 8 | offset: search.offset, 9 | limit: search.limit, 10 | name: search.name 11 | } 12 | }) 13 | 14 | export const saveRole = (role) => 15 | request({ 16 | url: '/roles', 17 | method: 'post', 18 | data: role 19 | }) 20 | 21 | export const getRoleById = (id) => 22 | request({ 23 | url: '/roles/' + id, 24 | method: 'get' 25 | }) 26 | 27 | export const updateRole = (id, role) => 28 | request({ 29 | url: '/roles/' + id, 30 | method: 'put', 31 | data: role 32 | }) 33 | 34 | export const listAllRole = () => 35 | request({ 36 | url: '/roles/all', 37 | method: 'get' 38 | }) 39 | 40 | export const removeRole = (id) => 41 | request({ 42 | url: '/roles/' + id, 43 | method: 'delete' 44 | }) 45 | 46 | export const listResourcePermission = (id) => 47 | request({ 48 | url: '/roles/' + id + '/resourcePermissions', 49 | method: 'get' 50 | }) 51 | 52 | export const savePermission = (roleId, permission) => 53 | request({ 54 | url: '/roles/' + roleId + '/permissions', 55 | method: 'post', 56 | data: permission 57 | }) -------------------------------------------------------------------------------- /src/api/router.js: -------------------------------------------------------------------------------- 1 | import request from '@/utils/request' 2 | 3 | export const getAuthorizedRouter = () => 4 | request({ 5 | url: '/routers/authorized', 6 | method: 'get' 7 | }) 8 | 9 | export const listRouter = (search) => 10 | request({ 11 | url: '/routers', 12 | method: 'get', 13 | params: { 14 | offset: search.offset, 15 | limit: search.limit, 16 | name: search.name 17 | } 18 | }) 19 | 20 | export const getRouterById = (id) => 21 | request({ 22 | url: '/routers/' + id, 23 | method: 'get' 24 | }) 25 | 26 | export const listByParentId = (parentId) => 27 | request({ 28 | url: '/routers/search', 29 | method: 'get', 30 | params: { 31 | parentId: parentId 32 | } 33 | }) 34 | 35 | export const saveRouter = (router) => 36 | request({ 37 | url: '/routers', 38 | method: 'post', 39 | data: router 40 | }) 41 | 42 | export const updateRouter = (id, router) => 43 | request({ 44 | url: '/routers/' + id, 45 | method: 'put', 46 | data: router 47 | }) 48 | 49 | export const removeRouter = (id) => 50 | request({ 51 | url: '/routers/' + id, 52 | method: 'delete' 53 | }) 54 | 55 | export const listAllRouter = (includeLocked) => 56 | request({ 57 | url: '/routers/all?includeLocked=' + includeLocked, 58 | method: 'get' 59 | }) -------------------------------------------------------------------------------- /src/api/user.js: -------------------------------------------------------------------------------- 1 | import request from '@/utils/request' 2 | 3 | export const listUser = (search) => 4 | request({ 5 | url: '/users', 6 | method: 'get', 7 | params: { 8 | name: search.username, 9 | sort: search.sort, 10 | offset: search.offset, 11 | limit: search.limit 12 | } 13 | }) 14 | 15 | export const getUser = (id) => 16 | request({ 17 | url: '/users/' + id, 18 | method: 'get' 19 | }) 20 | 21 | export const updateUser = (id, user) => 22 | request({ 23 | url: '/users/' + id, 24 | method: 'put', 25 | data: user 26 | }) 27 | 28 | export const saveUser = (user) => 29 | request({ 30 | url: '/users', 31 | method: 'post', 32 | data: user 33 | }) 34 | 35 | export const removeUser = (id) => 36 | request({ 37 | url: '/users/' + id, 38 | method: 'delete' 39 | }) 40 | 41 | export const changePassword = (userId, password) => 42 | request({ 43 | url: '/users/' + userId + "/password", 44 | method: 'put', 45 | params: { 46 | password: password 47 | } 48 | }) 49 | 50 | export const listUserRole = (userId) => 51 | request({ 52 | url: '/users/' + userId + '/roles', 53 | method: 'get' 54 | }) 55 | 56 | export const getCurrentUser = () => 57 | request({ 58 | url: '/users/me', 59 | method: 'get' 60 | }) 61 | 62 | export const updateCurrentUser = (user) => 63 | request({ 64 | url: '/users/me', 65 | method: 'put', 66 | data: user 67 | }) -------------------------------------------------------------------------------- /src/assets/css/common.css: -------------------------------------------------------------------------------- 1 | .el-table { 2 | width: 100%; 3 | color: #111; 4 | font-size: 14px; 5 | } 6 | .el-table .header-row { 7 | background: #F2F6FC; 8 | color: #111; 9 | border-color: #ECEEF4; 10 | } 11 | 12 | .el-pagination { 13 | float: right; 14 | margin-top: 10px; 15 | } 16 | 17 | .el-dialog { 18 | text-align: left; 19 | } 20 | .dialog-header { 21 | width: 100%; 22 | font-weight: bold; 23 | padding-bottom: 8px; 24 | border-bottom: solid 1px #fefefe; 25 | } 26 | .el-dialog__body { 27 | padding-top: 7px; 28 | padding-bottom: 7px; 29 | margin-top: 7px; 30 | margin-bottom: 7px; 31 | } 32 | -------------------------------------------------------------------------------- /src/assets/images/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulichao/zhcc-view-source/bf188bfe97401d78390b8acf5235ab9e1b9fcbbe/src/assets/images/loading.gif -------------------------------------------------------------------------------- /src/assets/images/personal_avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulichao/zhcc-view-source/bf188bfe97401d78390b8acf5235ab9e1b9fcbbe/src/assets/images/personal_avatar.png -------------------------------------------------------------------------------- /src/components/resource/resourceEdit.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 155 | 156 | -------------------------------------------------------------------------------- /src/components/role/roleEdit.vue: -------------------------------------------------------------------------------- 1 | 23 | 24 | 132 | 133 | -------------------------------------------------------------------------------- /src/components/role/rolePermission.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 167 | 168 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /src/components/router/routerEdit.vue: -------------------------------------------------------------------------------- 1 | 71 | 72 | 185 | 186 | 194 | 195 | 196 | -------------------------------------------------------------------------------- /src/components/sidebar/index.vue: -------------------------------------------------------------------------------- 1 | 24 | 25 | 31 | 32 | 37 | -------------------------------------------------------------------------------- /src/components/user/changePassword.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 124 | 125 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /src/components/user/personalInfo.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 161 | 162 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /src/components/user/userEdit.vue: -------------------------------------------------------------------------------- 1 | 44 | 45 | 218 | 219 | 224 | 225 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /src/icons/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import SvgIcon from '@/components/SvgIcon'// svg组件 3 | import generateIconsView from '@/views/svg-icons/generateIconsView.js'// just for @/views/icons , you can delete it 4 | 5 | // register globally 6 | Vue.component('svg-icon', SvgIcon) 7 | 8 | const requireAll = requireContext => requireContext.keys().map(requireContext) 9 | const req = require.context('./svg', false, /\.svg$/) 10 | const iconMap = requireAll(req) 11 | 12 | generateIconsView.generate(iconMap) // just for @/views/icons , you can delete it 13 | -------------------------------------------------------------------------------- /src/icons/svg/404.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/bug.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/chart.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/clipboard.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/component.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/dashboard.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/documentation.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/icons/svg/drag.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/email.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/example.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/excel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/eye.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/form.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/icon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/international.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/language.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/icons/svg/lock.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/message.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/money.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/password.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/people.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/peoples.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/qq.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/shoppingCard.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/star.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/tab.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/table.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/theme.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/trendChart1.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/trendChart2.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/trendChart3.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/user.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/wechat.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/svg/zip.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | import App from './App' 5 | import store from './store' 6 | import router from './router' 7 | 8 | import ElementUI from 'element-ui' 9 | import 'element-ui/lib/theme-chalk/index.css' 10 | 11 | Vue.config.productionTip = false 12 | 13 | Vue.use(ElementUI) 14 | /* eslint-disable no-new */ 15 | new Vue({ 16 | el: '#app', 17 | store, 18 | router, 19 | template: '', 20 | components: { App } 21 | }) 22 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import LoginView from '@/views/login/index' 4 | 5 | Vue.use(Router) 6 | 7 | //按需加载 8 | /** 9 | * 有时候我们想把某个路由下的所有组件都打包在同个异步 chunk 中。 10 | * 只需要 给 chunk 命名,提供 require.ensure 第三个参数作为 chunk 的名称。 11 | * Webpack 将相同 chunk 下的所有异步模块打包到一个异步块里面, 12 | * 这也意味着我们无须明确列出 require.ensure 的依赖(传空数组就行)。 13 | */ 14 | //const Index = resolve => require(['@/views/index'], resolve) 15 | //const foodList = r => require.ensure([], () => r(require('@/page/foodList')), 'foodList'); 16 | 17 | const router = new Router({ 18 | routes: [ 19 | { 20 | path: '/login', 21 | name: "login", 22 | component: LoginView, 23 | meta: { requiresAuth: false } 24 | },{ 25 | path: '/index', 26 | redirect: '/', 27 | meta: { requiresAuth: true } 28 | } 29 | ] 30 | }); 31 | generateIndexRouter(); 32 | 33 | // 验证token,存在才跳转 34 | router.beforeEach((to, from, next) => { 35 | let token = sessionStorage.getItem('token') 36 | if(to.path === '/') { 37 | if(!token) { 38 | next({ 39 | path: '/login', 40 | query: { redirect: to.fullPath } 41 | }) 42 | return 43 | } 44 | } 45 | 46 | if(to.meta.requiresAuth) { 47 | if(token) { 48 | next() 49 | } else { 50 | next({ 51 | path: '/login', 52 | query: { redirect: to.fullPath } 53 | }) 54 | } 55 | } else { 56 | next() 57 | } 58 | }); 59 | 60 | router.afterEach((to, from) => { 61 | // 设置面包屑 62 | let breadCrumbItems = [] 63 | let homePageCrumb = { 64 | title: '首页', 65 | to: '/' 66 | } 67 | breadCrumbItems.push(homePageCrumb) 68 | if(to.meta.nameFullPath) { 69 | let fullPathSplit = to.meta.nameFullPath.split('/') 70 | fullPathSplit.forEach(( item, index ) => { 71 | let routerBreadCrumb = { 72 | title: item, 73 | to: (index == fullPathSplit.length - 1 ? to.path : '') 74 | } 75 | breadCrumbItems.push(routerBreadCrumb) 76 | }); 77 | } 78 | // 更新到state 79 | router.app.$store.dispatch('setBreadcurmbItems', breadCrumbItems) 80 | }) 81 | 82 | // 生成首页路由 83 | function generateIndexRouter() { 84 | if (!sessionStorage.routers) { 85 | return 86 | } 87 | let indexRouter = { 88 | path: "/", 89 | name: "/", 90 | component: resolve => require(['@/views/home/index'], resolve), 91 | children: [ 92 | ...generateChildRouters() 93 | ] 94 | } 95 | router.addRoutes([indexRouter]) 96 | } 97 | 98 | // 生成嵌套路由(子路由) 99 | function generateChildRouters() { 100 | let routers = JSON.parse(sessionStorage.routers) 101 | let childRouters = [] 102 | for(let router of routers) { 103 | if(router.code != null) { 104 | let routerProps = JSON.parse(router.properties) 105 | let childRouter = { 106 | path: router.url, 107 | name: router.code, 108 | component: resolve => require(['@/views/' + router.code + '/index'], resolve), 109 | meta: { routerId: router.id, requiresAuth: routerProps.meta.requiresAuth, nameFullPath: routerProps.nameFullPath } 110 | } 111 | childRouters.push(childRouter) 112 | } 113 | } 114 | return childRouters 115 | } 116 | 117 | export default router; 118 | -------------------------------------------------------------------------------- /src/store/actions.js: -------------------------------------------------------------------------------- 1 | import * as types from './mutation-types' 2 | 3 | export default { 4 | setLoading({commit}, data) { 5 | commit(types.SET_LOADING, data) 6 | }, 7 | setBreadcurmbItems({commit}, data) { 8 | commit(types.SET_BREADCRUMB_ITEMS, data) 9 | } 10 | } -------------------------------------------------------------------------------- /src/store/getters.js: -------------------------------------------------------------------------------- 1 | const getters = { 2 | showLoading: state => state.showLoading, 3 | breadcrumbItems: state => state.breadcrumbItems 4 | } 5 | 6 | export default getters -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue" 2 | import Vuex from 'vuex' 3 | import mutations from './mutations' 4 | import actions from './actions' 5 | import getters from './getters' 6 | 7 | Vue.use(Vuex); 8 | 9 | const state = { 10 | showLoading: false, 11 | breadcrumbItems: [] 12 | }; 13 | 14 | export default new Vuex.Store({ 15 | state, 16 | mutations, 17 | actions, 18 | getters 19 | }); -------------------------------------------------------------------------------- /src/store/mutation-types.js: -------------------------------------------------------------------------------- 1 | export const SET_LOADING = 'SET_LOADING' 2 | export const SET_BREADCRUMB_ITEMS = 'SET_BREADCRUMB_ITEMS' -------------------------------------------------------------------------------- /src/store/mutations.js: -------------------------------------------------------------------------------- 1 | import * as types from './mutation-types' 2 | 3 | const mutations = { 4 | [types.SET_LOADING]: (state, data) => { 5 | state.showLoading = data 6 | }, 7 | [types.SET_BREADCRUMB_ITEMS]: (state, data) => { 8 | state.breadcrumbItems = data 9 | } 10 | } 11 | 12 | export default mutations -------------------------------------------------------------------------------- /src/utils/request.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | // 创建axios实例 4 | const service = axios.create({ 5 | // api的base_url 6 | baseURL: process.env.BASE_API, 7 | // 请求超时时间 8 | timeout: 5000 9 | }) 10 | 11 | // request拦截器 12 | service.interceptors.request.use(config => { 13 | // Do something before request is sent 14 | if (sessionStorage.getItem('token')) { 15 | // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改 16 | config.headers['X-Token'] = sessionStorage.getItem('token') 17 | } 18 | return config 19 | }, error => { 20 | // Do something with request error 21 | Promise.reject(error) 22 | }) 23 | 24 | // respone拦截器 25 | service.interceptors.response.use( 26 | response => { 27 | 28 | if (response.data.errCode == 2) { 29 | router.push({ 30 | path: "/login", 31 | // 从哪个页面跳转 32 | querry: { redirect: router.currentRoute.fullPath } 33 | }) 34 | } 35 | return response; 36 | }, 37 | error => { 38 | return Promise.reject(error) 39 | }) 40 | 41 | export default service 42 | -------------------------------------------------------------------------------- /src/views/home/index.vue: -------------------------------------------------------------------------------- 1 | 53 | 54 | 122 | 123 | 124 | 127 | 128 | 220 | -------------------------------------------------------------------------------- /src/views/login/index.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 133 | 134 | 155 | -------------------------------------------------------------------------------- /src/views/resource/index.vue: -------------------------------------------------------------------------------- 1 | 40 | 41 | 188 | 189 | 210 | -------------------------------------------------------------------------------- /src/views/role/index.vue: -------------------------------------------------------------------------------- 1 | 57 | 58 | 181 | 182 | -------------------------------------------------------------------------------- /src/views/router/index.vue: -------------------------------------------------------------------------------- 1 | 52 | 53 | 200 | 201 | 216 | -------------------------------------------------------------------------------- /src/views/user/index.vue: -------------------------------------------------------------------------------- 1 | 58 | 59 | 203 | 204 | 219 | 220 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulichao/zhcc-view-source/bf188bfe97401d78390b8acf5235ab9e1b9fcbbe/static/.gitkeep -------------------------------------------------------------------------------- /test/e2e/custom-assertions/elementCount.js: -------------------------------------------------------------------------------- 1 | // A custom Nightwatch assertion. 2 | // The assertion name is the filename. 3 | // Example usage: 4 | // 5 | // browser.assert.elementCount(selector, count) 6 | // 7 | // For more information on custom assertions see: 8 | // http://nightwatchjs.org/guide#writing-custom-assertions 9 | 10 | exports.assertion = function (selector, count) { 11 | this.message = 'Testing if element <' + selector + '> has count: ' + count 12 | this.expected = count 13 | this.pass = function (val) { 14 | return val === this.expected 15 | } 16 | this.value = function (res) { 17 | return res.value 18 | } 19 | this.command = function (cb) { 20 | var self = this 21 | return this.api.execute(function (selectorToCount) { 22 | return document.querySelectorAll(selectorToCount).length 23 | }, [selector], function (res) { 24 | cb.call(self, res) 25 | }) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/e2e/nightwatch.conf.js: -------------------------------------------------------------------------------- 1 | require('babel-register') 2 | var config = require('../../config') 3 | 4 | // http://nightwatchjs.org/gettingstarted#settings-file 5 | module.exports = { 6 | src_folders: ['test/e2e/specs'], 7 | output_folder: 'test/e2e/reports', 8 | custom_assertions_path: ['test/e2e/custom-assertions'], 9 | 10 | selenium: { 11 | start_process: true, 12 | server_path: require('selenium-server').path, 13 | host: '127.0.0.1', 14 | port: 4444, 15 | cli_args: { 16 | 'webdriver.chrome.driver': require('chromedriver').path 17 | } 18 | }, 19 | 20 | test_settings: { 21 | default: { 22 | selenium_port: 4444, 23 | selenium_host: 'localhost', 24 | silent: true, 25 | globals: { 26 | devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port) 27 | } 28 | }, 29 | 30 | chrome: { 31 | desiredCapabilities: { 32 | browserName: 'chrome', 33 | javascriptEnabled: true, 34 | acceptSslCerts: true 35 | } 36 | }, 37 | 38 | firefox: { 39 | desiredCapabilities: { 40 | browserName: 'firefox', 41 | javascriptEnabled: true, 42 | acceptSslCerts: true 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/e2e/runner.js: -------------------------------------------------------------------------------- 1 | // 1. start the dev server using production config 2 | process.env.NODE_ENV = 'testing' 3 | 4 | const webpack = require('webpack') 5 | const DevServer = require('webpack-dev-server') 6 | 7 | const webpackConfig = require('../../build/webpack.prod.conf') 8 | const devConfigPromise = require('../../build/webpack.dev.conf') 9 | 10 | let server 11 | 12 | devConfigPromise.then(devConfig => { 13 | const devServerOptions = devConfig.devServer 14 | const compiler = webpack(webpackConfig) 15 | server = new DevServer(compiler, devServerOptions) 16 | const port = devServerOptions.port 17 | const host = devServerOptions.host 18 | return server.listen(port, host) 19 | }) 20 | .then(() => { 21 | // 2. run the nightwatch test suite against it 22 | // to run in additional browsers: 23 | // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings" 24 | // 2. add it to the --env flag below 25 | // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` 26 | // For more information on Nightwatch's config file, see 27 | // http://nightwatchjs.org/guide#settings-file 28 | let opts = process.argv.slice(2) 29 | if (opts.indexOf('--config') === -1) { 30 | opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']) 31 | } 32 | if (opts.indexOf('--env') === -1) { 33 | opts = opts.concat(['--env', 'chrome']) 34 | } 35 | 36 | const spawn = require('cross-spawn') 37 | const runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }) 38 | 39 | runner.on('exit', function (code) { 40 | server.close() 41 | process.exit(code) 42 | }) 43 | 44 | runner.on('error', function (err) { 45 | server.close() 46 | throw err 47 | }) 48 | }) 49 | -------------------------------------------------------------------------------- /test/e2e/specs/test.js: -------------------------------------------------------------------------------- 1 | // For authoring Nightwatch tests, see 2 | // http://nightwatchjs.org/guide#usage 3 | 4 | module.exports = { 5 | 'default e2e tests': function (browser) { 6 | // automatically uses dev Server port from /config.index.js 7 | // default: http://localhost:8080 8 | // see nightwatch.conf.js 9 | const devServer = browser.globals.devServerURL 10 | 11 | browser 12 | .url(devServer) 13 | .waitForElementVisible('#app', 5000) 14 | .assert.elementPresent('.hello') 15 | .assert.containsText('h1', 'Welcome to Your Vue.js App') 16 | .assert.elementCount('img', 1) 17 | .end() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/unit/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "jest": true 4 | }, 5 | "globals": { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/unit/jest.conf.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | 3 | module.exports = { 4 | rootDir: path.resolve(__dirname, '../../'), 5 | moduleFileExtensions: [ 6 | 'js', 7 | 'json', 8 | 'vue' 9 | ], 10 | moduleNameMapper: { 11 | '^@/(.*)$': '/src/$1' 12 | }, 13 | transform: { 14 | '^.+\\.js$': '/node_modules/babel-jest', 15 | '.*\\.(vue)$': '/node_modules/vue-jest' 16 | }, 17 | testPathIgnorePatterns: [ 18 | '/test/e2e' 19 | ], 20 | snapshotSerializers: ['/node_modules/jest-serializer-vue'], 21 | setupFiles: ['/test/unit/setup'], 22 | mapCoverage: true, 23 | coverageDirectory: '/test/unit/coverage', 24 | collectCoverageFrom: [ 25 | 'src/**/*.{js,vue}', 26 | '!src/main.js', 27 | '!src/router/index.js', 28 | '!**/node_modules/**' 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /test/unit/setup.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | Vue.config.productionTip = false 4 | -------------------------------------------------------------------------------- /test/unit/specs/HelloWorld.spec.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import HelloWorld from '@/components/HelloWorld' 3 | 4 | describe('HelloWorld.vue', () => { 5 | it('should render correct contents', () => { 6 | const Constructor = Vue.extend(HelloWorld) 7 | const vm = new Constructor().$mount() 8 | expect(vm.$el.querySelector('.hello h1').textContent) 9 | .toEqual('Welcome to Your Vue.js App') 10 | }) 11 | }) 12 | --------------------------------------------------------------------------------