├── src ├── store │ ├── actions.js │ ├── getters.js │ ├── state.js │ ├── mutations.js │ ├── mutation-types.js │ ├── modules │ │ ├── menu.js │ │ └── login.js │ └── index.js ├── css │ ├── vars.css │ ├── fonts │ │ ├── iconfont.eot │ │ ├── iconfont.ttf │ │ ├── iconfont.woff │ │ └── iconfont.svg │ ├── iconfont.css │ └── common.css ├── assets │ └── logo.png ├── App.vue ├── modules │ ├── code-splitting-demo │ │ ├── module-a.js │ │ ├── module-b.js │ │ ├── module-c.js │ │ └── index.js │ ├── page2 │ │ └── index.vue │ ├── page1 │ │ └── index.vue │ ├── index │ │ └── index.vue │ ├── login │ │ └── index.vue │ └── home │ │ └── index.vue ├── apis │ ├── tokens.js │ └── mock │ │ └── index.js ├── config │ ├── menu.js │ └── routes.js ├── components │ ├── CWaves.vue │ ├── CMain.vue │ ├── js │ │ └── cwaves.js │ └── CMenu.vue ├── main.js └── utils │ └── request.js ├── config ├── prod.env.js ├── test.env.js ├── dev.env.js └── index.js ├── doc └── img │ ├── logo.png │ └── vue2admin.png ├── .gitignore ├── test ├── unit │ ├── .eslintrc │ ├── specs │ │ └── CMenu.spec.js │ ├── index.js │ └── karma.conf.js └── e2e │ ├── specs │ └── test.js │ ├── custom-assertions │ └── elementCount.js │ ├── runner.js │ └── nightwatch.conf.js ├── .editorconfig ├── .travis.yml ├── index.html ├── .babelrc ├── package.json └── README.md /src/store/actions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/7. 3 | */ 4 | -------------------------------------------------------------------------------- /src/store/getters.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/7. 3 | */ 4 | -------------------------------------------------------------------------------- /src/store/state.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/8. 3 | */ 4 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /src/store/mutations.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/7. 3 | */ 4 | -------------------------------------------------------------------------------- /src/css/vars.css: -------------------------------------------------------------------------------- 1 | /* css预定义变量 */ 2 | :root { 3 | --color-main: #ff0000; 4 | } 5 | -------------------------------------------------------------------------------- /doc/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rootsli/vue2admin/HEAD/doc/img/logo.png -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rootsli/vue2admin/HEAD/src/assets/logo.png -------------------------------------------------------------------------------- /doc/img/vue2admin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rootsli/vue2admin/HEAD/doc/img/vue2admin.png -------------------------------------------------------------------------------- /src/css/fonts/iconfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rootsli/vue2admin/HEAD/src/css/fonts/iconfont.eot -------------------------------------------------------------------------------- /src/css/fonts/iconfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rootsli/vue2admin/HEAD/src/css/fonts/iconfont.ttf -------------------------------------------------------------------------------- /src/css/fonts/iconfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rootsli/vue2admin/HEAD/src/css/fonts/iconfont.woff -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log 5 | test/unit/coverage 6 | test/e2e/reports 7 | selenium-debug.log 8 | -------------------------------------------------------------------------------- /test/unit/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "globals": { 6 | "expect": true, 7 | "sinon": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /config/test.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var devEnv = require('./dev.env') 3 | 4 | module.exports = merge(devEnv, { 5 | NODE_ENV: '"testing"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /src/modules/code-splitting-demo/module-a.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/3/20. 3 | */ 4 | export default { 5 | start(){ 6 | console.log('*********** I AM module-a ***********'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/modules/code-splitting-demo/module-b.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/3/20. 3 | */ 4 | export default { 5 | start(){ 6 | console.log('*********** I AM module-b ***********'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/modules/code-splitting-demo/module-c.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/3/20. 3 | */ 4 | export default { 5 | start(){ 6 | console.log('*********** I AM module-c ***********'); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/apis/tokens.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/9. 3 | */ 4 | import request from '../utils/request' 5 | 6 | export default { 7 | getTokens(name, pass){ 8 | return request.get('/login') 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | #指定运行环境 2 | language: node_js 3 | #指定nodejs版本,可以指定多个 4 | node_js: 5 | - 5.4.1 6 | 7 | #运行的脚本命令 8 | script: 9 | - npm run unit 10 | 11 | #指定分支,只有指定的分支提交时才会运行脚本 12 | branches: 13 | only: 14 | - master 15 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | vue2admin 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/store/mutation-types.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/7. 3 | */ 4 | //菜单折叠 5 | export const TOGGLE_MAIN_MENU = 'menu/TOGGLE_MAIN_MENU' 6 | 7 | //登录 8 | export const LOGIN_IN = 'login/LOGIN_IN' 9 | export const LOGIN_OUT = 'login/LOGIN_OUT' 10 | 11 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["es2015", { "modules": false }], 4 | "stage-2" 5 | ], 6 | "plugins": ["transform-runtime"], 7 | "comments": false, 8 | "env": { 9 | "test": { 10 | "plugins": [ "istanbul" ] 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/apis/mock/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/10. 3 | */ 4 | import MockFetch from 'mock-fetch-api' 5 | 6 | export default { 7 | start(){ 8 | // if (process.env.NODE_ENV !== 'production') { 9 | MockFetch.when('GET', '/login').respondWith(200, '{"tokens":"6C15B16A70AE9FEDC6546343E79103532AB88DCE1B91B0DF77BE49AE9F493D04"}'); 10 | // } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/modules/page2/index.vue: -------------------------------------------------------------------------------- 1 | 15 | -------------------------------------------------------------------------------- /test/unit/specs/CMenu.spec.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Hello from 'src/components/CMenu' 3 | 4 | describe('CMenu.vue', () => { 5 | it('should render correct contents', () => { 6 | const vm = new Vue({ 7 | el: document.createElement('div'), 8 | render: (h) => h(Hello) 9 | }) 10 | expect(vm.$el.querySelector('.feed-back a').textContent) 11 | .to.equal('FAQ中心') 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /test/unit/index.js: -------------------------------------------------------------------------------- 1 | // Polyfill fn.bind() for PhantomJS 2 | /* eslint-disable no-extend-native */ 3 | Function.prototype.bind = require('function-bind') 4 | 5 | // require all test files (files that ends with .spec.js) 6 | const testsContext = require.context('./specs', true, /\.spec$/) 7 | testsContext.keys().forEach(testsContext) 8 | 9 | // require all src files except main.js for coverage. 10 | // you can also change this to match only the subset of files that 11 | // you want coverage for. 12 | const srcContext = require.context('src', true, /^\.\/(?!main(\.js)?$)/) 13 | srcContext.keys().forEach(srcContext) 14 | -------------------------------------------------------------------------------- /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('.grid-content') 15 | .assert.containsText('div', '登录页面') 16 | // .assert.elementCount('img', 1) 17 | .end() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/store/modules/menu.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/7. 3 | */ 4 | import {TOGGLE_MAIN_MENU} from '../mutation-types' 5 | 6 | // initial state 7 | const state = { 8 | isFold: false 9 | } 10 | 11 | // getters 12 | const getters = { 13 | menuIsFold: state => state.isFold 14 | } 15 | 16 | //actions 17 | const actions = { 18 | toggleMenu({commit}){ 19 | commit(TOGGLE_MAIN_MENU) 20 | } 21 | } 22 | 23 | //mutations 24 | const mutations = { 25 | [TOGGLE_MAIN_MENU] (state) { 26 | state.isFold = !state.isFold 27 | }, 28 | } 29 | 30 | //export 31 | export default { 32 | state, 33 | getters, 34 | actions, 35 | mutations 36 | } 37 | -------------------------------------------------------------------------------- /src/config/menu.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/1/24. 3 | */ 4 | export default [ 5 | { 6 | name: '概览', 7 | items: [ 8 | { 9 | name: '页面1', 10 | path: '/home/page1' 11 | }, { 12 | name: '页面2', 13 | path: '/home/page2' 14 | } 15 | ] 16 | }, 17 | { 18 | name: '环境', 19 | items: [ 20 | { 21 | name: '页面1', 22 | path: '/env/page2' 23 | }, { 24 | name: '页面2', 25 | path: '/env/page2' 26 | }, { 27 | name: '页面3', 28 | path: '/env/page3' 29 | }, { 30 | name: '页面4', 31 | path: '/env/page4' 32 | } 33 | ] 34 | } 35 | ] 36 | -------------------------------------------------------------------------------- /src/modules/page1/index.vue: -------------------------------------------------------------------------------- 1 | 10 | 22 | 23 | -------------------------------------------------------------------------------- /src/modules/code-splitting-demo/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/3/20. 3 | * 4 | */ 5 | export default { 6 | /** 7 | * webpack的code spliting(Using require.ensure)功能可以将require.ensure及其回调内依赖的包合并到一个独立的模块(chunk)中, 8 | * 并且webpack使用jsonp对这个模块进行异步静默加载 9 | * @好处:在中大型项目中,避免合并后的文件过大;此外,也有利于优化项目的资源加载速度 10 | * @结果:此处module-a.js,module-b.js,module-c.js将被打包到一个独立的chunk中。可以通过 npm run build查看打包结果。 11 | */ 12 | start(){ 13 | console.log('webpack2 code splitting demo(Using require.ensure) start...') 14 | require.ensure(['./module-a', './module-b'], function (require) { 15 | require('./module-c') 16 | console.log('webpack2 code splitting demo(Using require.ensure) end!') 17 | }); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/css/iconfont.css: -------------------------------------------------------------------------------- 1 | 2 | @font-face {font-family: "v2"; 3 | src: url('./fonts/iconfont.eot?t=1485340575763'); /* IE9*/ 4 | src: url('./fonts/iconfont.eot?t=1485340575763#iefix') format('embedded-opentype'), /* IE6-IE8 */ 5 | url('./fonts/iconfont.woff?t=1485340575763') format('woff'), /* chrome, firefox */ 6 | url('./fonts/iconfont.ttf?t=1485340575763') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/ 7 | url('./fonts/iconfont.svg?t=1485340575763#v2') format('svg'); /* iOS 4.1- */ 8 | } 9 | 10 | .v2 { 11 | font-family:"v2" !important; 12 | font-size:16px; 13 | font-style:normal; 14 | -webkit-font-smoothing: antialiased; 15 | -moz-osx-font-smoothing: grayscale; 16 | } 17 | 18 | .v2-slidebar-packup:before { content: "\e698"; } 19 | 20 | .v2-announcement:before { content: "\e61b"; } 21 | 22 | .v2-slidebar-packup-copy:before { content: "\e9a7"; } 23 | 24 | -------------------------------------------------------------------------------- /test/e2e/custom-assertions/elementCount.js: -------------------------------------------------------------------------------- 1 | // A custom Nightwatch assertion. 2 | // the name of the method is the filename. 3 | // can be used in tests like this: 4 | // 5 | // browser.assert.elementCount(selector, count) 6 | // 7 | // for how to write custom assertions see 8 | // http://nightwatchjs.org/guide#writing-custom-assertions 9 | exports.assertion = function (selector, count) { 10 | this.message = 'Testing if element <' + selector + '> has count: ' + count 11 | this.expected = count 12 | this.pass = function (val) { 13 | return val === this.expected 14 | } 15 | this.value = function (res) { 16 | return res.value 17 | } 18 | this.command = function (cb) { 19 | var self = this 20 | return this.api.execute(function (selector) { 21 | return document.querySelectorAll(selector).length 22 | }, [selector], function (res) { 23 | cb.call(self, res) 24 | }) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/store/modules/login.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/7. 3 | */ 4 | import {LOGIN_IN, LOGIN_OUT} from '../mutation-types' 5 | import tokens from '../../apis/tokens' 6 | 7 | // initial state 8 | const state = { 9 | tokens: '' 10 | } 11 | 12 | // getters 13 | const getters = { 14 | tokens: state => state.tokens 15 | } 16 | 17 | //actions 18 | const actions = { 19 | login({commit, state}, user){ 20 | tokens.getTokens(user.name, user.pass).then((data) => { 21 | //success 22 | commit(LOGIN_IN, {tokens: data.tokens}) 23 | }, (error) => { 24 | //fail 25 | commit(LOGIN_IN, {tokens: ''}) 26 | }) 27 | }, 28 | logout({commit}){ 29 | commit(LOGIN_OUT) 30 | } 31 | } 32 | 33 | //mutations 34 | const mutations = { 35 | [LOGIN_IN] (state, {tokens}) { 36 | state.tokens = tokens 37 | }, 38 | [LOGIN_OUT] (state) { 39 | state.tokens = '' 40 | } 41 | } 42 | 43 | //export 44 | export default { 45 | state, 46 | getters, 47 | actions, 48 | mutations 49 | } 50 | -------------------------------------------------------------------------------- /src/css/common.css: -------------------------------------------------------------------------------- 1 | body { 2 | height: 100%; 3 | overflow: hidden; 4 | margin: 0; 5 | background-color: #f0f2f5; 6 | font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif; 7 | font-weight: 400; 8 | -webkit-font-smoothing: antialiased; 9 | } 10 | 11 | ::-webkit-scrollbar { 12 | width: 4px; 13 | height: 10px; 14 | } 15 | 16 | ::-webkit-scrollbar-thumb { 17 | border-radius: 2px; 18 | background: #9598a7; 19 | } 20 | 21 | ::-webkit-scrollbar-track { 22 | background: #e3e3e3; 23 | } 24 | 25 | a { 26 | text-decoration: none; 27 | color: #3074bd; 28 | cursor: pointer; 29 | } 30 | 31 | a:hover { 32 | opacity: 0.8; 33 | } 34 | 35 | ul, ol { 36 | list-style: none; 37 | } 38 | 39 | .fl { 40 | float: left !important; 41 | } 42 | 43 | .fr { 44 | float: right !important; 45 | } 46 | 47 | .height100 { 48 | height: 100%; 49 | } 50 | 51 | button, input, select, textarea { 52 | font-family: inherit; 53 | font-size: inherit; 54 | line-height: inherit; 55 | color: inherit; 56 | } 57 | -------------------------------------------------------------------------------- /src/config/routes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/1/24. 3 | */ 4 | 5 | 6 | /** 7 | * auth true登录才能访问,false不需要登录,默认true 8 | */ 9 | export default [ 10 | { 11 | path: '/', 12 | meta: {auth: false}, 13 | component: resolve => require(['../modules/index/'], resolve) 14 | }, 15 | { 16 | path: '/login', 17 | meta: {auth: false}, 18 | component: resolve => require(['../modules/login/'], resolve) 19 | }, 20 | { 21 | path: '/home', 22 | meta: {auth: true}, 23 | component: resolve => require(['../modules/home/'], resolve), 24 | children: [ 25 | { 26 | path: 'page1', 27 | meta: {auth: true}, 28 | component: resolve => require(['../modules/page1/'], resolve) 29 | }, 30 | { 31 | path: 'page2', 32 | meta: {auth: true}, 33 | component: resolve => require(['../modules/page2/'], resolve) 34 | }, 35 | ] 36 | }, 37 | { 38 | path: '*', 39 | meta: {auth: false}, 40 | component: resolve => require(['../modules/login/'], resolve) 41 | }, 42 | ] 43 | -------------------------------------------------------------------------------- /test/unit/karma.conf.js: -------------------------------------------------------------------------------- 1 | // This is a karma config file. For more details see 2 | // http://karma-runner.github.io/0.13/config/configuration-file.html 3 | // we are also using it with karma-webpack 4 | // https://github.com/webpack/karma-webpack 5 | 6 | var webpackConfig = require('../../build/webpack.test.conf') 7 | 8 | module.exports = function (config) { 9 | config.set({ 10 | // to run in additional browsers: 11 | // 1. install corresponding karma launcher 12 | // http://karma-runner.github.io/0.13/config/browsers.html 13 | // 2. add it to the `browsers` array below. 14 | browsers: ['PhantomJS'], 15 | frameworks: ['mocha', 'sinon-chai'], 16 | reporters: ['spec', 'coverage'], 17 | files: ['./index.js'], 18 | preprocessors: { 19 | './index.js': ['webpack', 'sourcemap'] 20 | }, 21 | webpack: webpackConfig, 22 | webpackMiddleware: { 23 | noInfo: true 24 | }, 25 | coverageReporter: { 26 | dir: './coverage', 27 | reporters: [ 28 | { type: 'lcov', subdir: '.' }, 29 | { type: 'text-summary' } 30 | ] 31 | } 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/7. 3 | */ 4 | import Vue from 'vue' 5 | import Vuex from 'vuex' 6 | import createLogger from 'vuex/dist/logger' 7 | import createPersistedState from 'vuex-persistedstate' //vuex持久化localstorage插件 8 | import * as Cookies from 'js-cookie'; 9 | import * as state from './state' 10 | import * as mutations from './mutations' 11 | import * as actions from './actions' 12 | import * as getters from './getters' 13 | import menu from './modules/menu' 14 | import login from './modules/login' 15 | 16 | Vue.use(Vuex) 17 | 18 | const debug = process.env.NODE_ENV !== 'production' 19 | 20 | let persistedState = { 21 | paths: ['login.tokens'], 22 | getState: (key) => Cookies.getJSON(key), 23 | setState: (key, state) => Cookies.set(key, state, {expires: 3}) //expires->cookie过期时间,单位为天 24 | } 25 | 26 | export default new Vuex.Store({ 27 | state, 28 | mutations, 29 | actions, 30 | getters, 31 | modules: { 32 | menu, 33 | login 34 | }, 35 | strict: debug, 36 | plugins: debug ? [createLogger(), createPersistedState(persistedState)] : [createPersistedState(persistedState)] 37 | }) 38 | -------------------------------------------------------------------------------- /test/e2e/runner.js: -------------------------------------------------------------------------------- 1 | // 1. start the dev server using production config 2 | process.env.NODE_ENV = 'testing' 3 | var server = require('../../build/dev-server.js') 4 | 5 | // 2. run the nightwatch test suite against it 6 | // to run in additional browsers: 7 | // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings" 8 | // 2. add it to the --env flag below 9 | // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` 10 | // For more information on Nightwatch's config file, see 11 | // http://nightwatchjs.org/guide#settings-file 12 | var opts = process.argv.slice(2) 13 | if (opts.indexOf('--config') === -1) { 14 | opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']) 15 | } 16 | if (opts.indexOf('--env') === -1) { 17 | opts = opts.concat(['--env', 'chrome']) 18 | } 19 | 20 | var spawn = require('cross-spawn') 21 | var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }) 22 | 23 | runner.on('exit', function (code) { 24 | server.close() 25 | process.exit(code) 26 | }) 27 | 28 | runner.on('error', function (err) { 29 | server.close() 30 | throw err 31 | }) 32 | -------------------------------------------------------------------------------- /src/components/CWaves.vue: -------------------------------------------------------------------------------- 1 | 32 | 42 | 54 | -------------------------------------------------------------------------------- /test/e2e/nightwatch.conf.js: -------------------------------------------------------------------------------- 1 | require('babel-register') 2 | var config = require('../../config') 3 | 4 | // http://nightwatchjs.org/guide#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 | -------------------------------------------------------------------------------- /src/modules/index/index.vue: -------------------------------------------------------------------------------- 1 | 29 | 43 | 52 | -------------------------------------------------------------------------------- /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 store from './store' 5 | import VueRouter from 'vue-router' 6 | import ElementUI from 'element-ui' 7 | import 'element-ui/lib/theme-default/index.css' 8 | import './css/common.css' 9 | import './css/iconfont.css' 10 | import mock from './apis/mock' 11 | 12 | import routes from './config/routes' 13 | import App from './App' 14 | import splitting from './modules/code-splitting-demo' 15 | 16 | Vue.use(VueRouter) //路由注册 17 | Vue.use(ElementUI) //UI框架注册 18 | 19 | const router = new VueRouter({ 20 | routes 21 | }) 22 | 23 | router.beforeEach(({meta, path}, from, next) => { 24 | let {auth = true} = meta 25 | let isLogin = Boolean(store.state.login.tokens != '') //true用户已登录, false用户未登录 26 | 27 | if (auth && !isLogin && path !== '/login') { 28 | return next({path: '/login'}) 29 | } 30 | 31 | if (isLogin && (path == '/login' || path == '/')) { //已登录过,则跳转到主页 32 | return next({path: '/home/page1'}) 33 | } 34 | 35 | next() 36 | }) 37 | 38 | mock.start() //启动ajax mock服务 39 | 40 | splitting.start() //demo:运行webpack2 code splitting示例 41 | 42 | new Vue({ 43 | el: '#app', 44 | router, 45 | store, 46 | render: h => h(App) 47 | }); 48 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '/', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'], 18 | // Run the build command with an extra argument to 19 | // View the bundle analyzer report after build finishes: 20 | // `npm run build --report` 21 | // Set to `true` or `false` to always turn it on or off 22 | bundleAnalyzerReport: process.env.npm_config_report 23 | }, 24 | dev: { 25 | env: require('./dev.env'), 26 | port: 8080, 27 | autoOpenBrowser: true, 28 | assetsSubDirectory: 'static', 29 | assetsPublicPath: '/', 30 | proxyTable: {}, 31 | // CSS Sourcemaps off by default because relative paths are "buggy" 32 | // with this option, according to the CSS-Loader README 33 | // (https://github.com/webpack/css-loader#sourcemaps) 34 | // In our experience, they generally work as expected, 35 | // just be aware of this issue when enabling this option. 36 | cssSourceMap: false 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/utils/request.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/2/9. 3 | */ 4 | import 'whatwg-fetch' 5 | 6 | export default { 7 | /** 8 | * 基于 fetch 封装的 GET请求 9 | * @param url 10 | * @param params {} 11 | * @param headers 12 | * @returns {Promise} 13 | */ 14 | get(url, params, headers) { 15 | if (params) { 16 | let paramsArray = []; 17 | //encodeURIComponent 18 | Object.keys(params).forEach(key => paramsArray.push(key + '=' + params[key])) 19 | if (url.search(/\?/) === -1) { 20 | url += '?' + paramsArray.join('&') 21 | } else { 22 | url += '&' + paramsArray.join('&') 23 | } 24 | } 25 | return new Promise(function (resolve, reject) { 26 | fetch(url, { 27 | method: 'GET', 28 | headers: headers, 29 | }) 30 | .then((response) => { 31 | if (response.ok) { 32 | return response.json(); 33 | } else { 34 | reject({status: response.status}) 35 | } 36 | }) 37 | .then((response) => { 38 | resolve(response); 39 | }) 40 | .catch((err) => { 41 | reject({status: -1}); 42 | }) 43 | }) 44 | }, 45 | /** 46 | * 基于 fetch 封装的 POST请求 FormData 表单数据 47 | * @param url 48 | * @param formData 49 | * @param headers 50 | * @returns {Promise} 51 | */ 52 | post(url, formData, headers) { 53 | return new Promise(function (resolve, reject) { 54 | fetch(url, { 55 | method: 'POST', 56 | headers: headers, 57 | body: formData, 58 | }) 59 | .then((response) => { 60 | if (response.ok) { 61 | return response.json(); 62 | } else { 63 | reject({status: response.status}) 64 | } 65 | }) 66 | .then((response) => { 67 | resolve(response); 68 | }) 69 | .catch((err) => { 70 | reject({status: -1}); 71 | }) 72 | }) 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /src/components/CMain.vue: -------------------------------------------------------------------------------- 1 | 72 | 85 | 97 | -------------------------------------------------------------------------------- /src/modules/login/index.vue: -------------------------------------------------------------------------------- 1 | 13 | 33 | 91 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue2admin-v2", 3 | "version": "1.0.0", 4 | "description": "基于vue2 + vue-router + vuex + fetch + PostCSS + element-ui + webpack2 实现的一个后台管理系统基础框架。", 5 | "author": "lichbin@hotmail.com", 6 | "private": true, 7 | "scripts": { 8 | "dev": "node build/dev-server.js", 9 | "build": "node build/build.js", 10 | "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run", 11 | "e2e": "node test/e2e/runner.js", 12 | "test": "npm run unit && npm run e2e" 13 | }, 14 | "dependencies": { 15 | "element-ui": "^1.2.2", 16 | "js-cookie": "^2.1.3", 17 | "three": "^0.84.0", 18 | "vue": "^2.2.1", 19 | "vue-router": "^2.3.0", 20 | "vuex": "^2.2.1", 21 | "vuex-persistedstate": "^1.2.0", 22 | "whatwg-fetch": "^2.0.2" 23 | }, 24 | "devDependencies": { 25 | "autoprefixer": "^6.7.2", 26 | "babel-core": "^6.22.1", 27 | "babel-loader": "^6.2.10", 28 | "babel-plugin-istanbul": "^3.1.2", 29 | "babel-plugin-transform-runtime": "^6.22.0", 30 | "babel-preset-es2015": "^6.22.0", 31 | "babel-preset-stage-2": "^6.22.0", 32 | "babel-register": "^6.22.0", 33 | "chai": "^3.5.0", 34 | "chalk": "^1.1.3", 35 | "chromedriver": "^2.27.2", 36 | "connect-history-api-fallback": "^1.3.0", 37 | "cross-env": "^3.1.4", 38 | "cross-spawn": "^5.0.1", 39 | "css-loader": "^0.26.1", 40 | "eventsource-polyfill": "^0.9.6", 41 | "express": "^4.14.1", 42 | "extract-text-webpack-plugin": "^2.0.0-rc.2", 43 | "file-loader": "^0.10.0", 44 | "friendly-errors-webpack-plugin": "^1.1.3", 45 | "function-bind": "^1.1.0", 46 | "html-webpack-plugin": "^2.28.0", 47 | "http-proxy-middleware": "^0.17.3", 48 | "inject-loader": "^2.0.1", 49 | "karma": "^1.4.1", 50 | "karma-coverage": "^1.1.1", 51 | "karma-mocha": "^1.3.0", 52 | "karma-phantomjs-launcher": "^1.0.2", 53 | "karma-sinon-chai": "^1.2.4", 54 | "karma-sourcemap-loader": "^0.3.7", 55 | "karma-spec-reporter": "0.0.26", 56 | "karma-webpack": "^2.0.2", 57 | "lolex": "^1.5.2", 58 | "mocha": "^3.2.0", 59 | "mock-fetch-api": "^1.0.7", 60 | "nightwatch": "^0.9.12", 61 | "opn": "^4.0.2", 62 | "ora": "^1.1.0", 63 | "phantomjs-prebuilt": "^2.1.14", 64 | "postcss-cssnext": "^2.9.0", 65 | "postcss-import": "^9.1.0", 66 | "selenium-server": "^3.0.1", 67 | "semver": "^5.3.0", 68 | "shelljs": "^0.7.6", 69 | "sinon": "^1.17.7", 70 | "sinon-chai": "^2.8.0", 71 | "url-loader": "^0.5.7", 72 | "vue-loader": "^10.3.0", 73 | "vue-style-loader": "^2.0.0", 74 | "vue-template-compiler": "^2.1.10", 75 | "webpack": "^2.2.1", 76 | "webpack-bundle-analyzer": "^2.2.1", 77 | "webpack-dev-middleware": "^1.10.0", 78 | "webpack-hot-middleware": "^2.16.1", 79 | "webpack-merge": "^2.6.1" 80 | }, 81 | "engines": { 82 | "node": ">= 4.0.0", 83 | "npm": ">= 3.0.0" 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/modules/home/index.vue: -------------------------------------------------------------------------------- 1 | 68 | 82 | 91 | 117 | -------------------------------------------------------------------------------- /src/css/fonts/iconfont.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Created by FontForge 20120731 at Wed Jan 25 18:36:15 2017 6 | By admin 7 | 8 | 9 | 10 | 24 | 26 | 28 | 30 | 32 | 34 | 38 | 40 | 45 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://github.com/rootsli/vue2admin/blob/master/doc/img/logo.png) 2 | 3 | vue2-admin - A scaffolding base Vue2.js 4 | ======================================================== 5 | 6 | [![Vuejs](https://img.shields.io/badge/%20Powered%20by-Vuejs%202.1.x%20-brightgreen.svg)](https://github.com/vuejs/vue) [![Build Status](https://travis-ci.org/rootsli/vue2admin.svg?branch=master)](https://travis-ci.org/rootsli/vue2admin) [![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php) [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges) 7 | 8 | > 基于vue2 + vue-router + vuex + fetch + PostCSS + [element-ui](http://element.eleme.io/)(也可以使用其他UI,例如[iView](https://www.iviewui.com/)) + webpack2 实现的一个后台管理系统基础框架。 9 | 10 | #### 框架能力: 11 | - 完全的基于组件化的架构 12 | - 基于组件的CSS命名空间独立,不相互污染 13 | - 登录功能(利用vuex与cookie的持久化方案进行登录认证缓存) 14 | - 多级路由支持 15 | - 基于vuex2的状态管理(开发时建议安装chrome插件vue.js devtools跟踪状态) 16 | - vuex2与cookie的持久化支持(支持对指定vuex状态进行持久化,并能指定cookie的过期时间)。具体示例请见项目源码:src\store\index.js 17 | - PostCSS支持:支持自动拼装前缀(autoprefixer插件),支持最新css语法(postcss-cssnext插件),支持@import方式引入css。具体示例请见项目源码:src\modules\page1\index.vue 18 | - 基于fetch的网络服务(源码路径:src\utils\request.js) 19 | - 支持mock数据服务(mock示例路径:src\apis\mock) 20 | - 基于webpack2的开发构建编译:支持开发阶段的HRM,支持模块依赖,静态资源优化,模块打包和Hash指纹等编译功能,一个命令,即可完成整个项目的构建编译 21 | - 提供了一个webpack大项目打包方案(On demand code-splitting)的示例,请见目录:src\modules\code-splitting-demo 22 | 23 | [点此查看运行效果](http://vue2admin.duapp.com)(用户名密码不限) 24 | 25 | ``` 26 | 说明:项目框架已经集成了大部分前端项目必须的插件服务和项目逻辑架构,可以拿来即用。让框架尽量简单,逻辑尽量清晰,编译构建过程完全可定制,也是本框架追求的目标之一。 27 | ``` 28 | 29 | ## Build Setup 30 | 31 | ``` 32 | 依赖环境:运行项目前请确认本地已安装nodejs和npm。依赖的版本如下: 33 | - "node": ">= 4.0.0" 34 | - "npm": ">= 3.0.0" 35 | 36 | ※ 开发和运行时阶段依赖的其他包请到package.json中查看 37 | ``` 38 | 39 | ``` bash 40 | # 安装依赖-国内用户推荐使用npm淘宝镜像,设置方法: 41 | # step1.npm config set registry https://registry.npm.taobao.org 42 | # step2.npm info underscore 43 | npm install 44 | 45 | # serve with hot reload at localhost:8080 46 | npm run dev 47 | 48 | # build for production with minification 49 | npm run build 50 | 51 | # build for production and view the bundle analyzer report 52 | npm run build --report 53 | 54 | # run unit tests 55 | npm run unit 56 | 57 | # run e2e tests 58 | npm run e2e 59 | 60 | # run all tests 61 | npm test 62 | ``` 63 | 64 | 65 | ## 工程目录结构 66 | ``` 67 | src:项目源码。开发的时候代码写在这里。 68 | |--assets # 项目静态资源,编译时不进行处理的资源都放这里 69 | |--components # 项目公共组件库 70 | |--config # 公共配置文件,例如路由配置等 71 | |--css # 项目公共样式库 72 | |--modules # 项目应用模块,根据应用需要,还可以有子模块,各子模块目录结构和顶级子模块类似 73 | | |--components # 模块级公共组件 74 | | |--views # 模块视图 75 | | |--css # 模块样式 76 | | |--js # 模块脚本 77 | |--App.vue # 项目根视图 78 | |--main.js # 项目入口文件 79 | |--store # 基于vuex的状态管理模块 80 | | |--index.js # 入口及store初始化 81 | | |--mutation-types.js # mutation名称定义 82 | | |--state.js # 根state 83 | | |--mutations.js # 根mutation 84 | | |--getters.js # 根getter 85 | | |--actions.js # 根action 86 | | |--modules # 子模块的store对象 87 | | | |--menu.js # menu模块 88 | |--apis # 服务层ajax请求服务 89 | | |--mock # api数据mock服务 90 | |--utils # 公共库函数 91 | | |--request.js # 网络请求服务,实现了对fetch的二次封装(目前只封装了get,post;实际项目中可按着示例封装其他请求) 92 | 93 | ``` 94 | 95 | ## 页面结构 96 | 97 | ![页面结构](https://github.com/rootsli/vue2admin/blob/master/doc/img/vue2admin.png) 98 | 99 | ## todo 100 | - fetch与Service Workers的本地缓存方案 101 | - 国际化 102 | - 图表插件 103 | 104 | -------------------------------------------------------------------------------- /src/components/js/cwaves.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by lichb on 2017/4/10. 3 | */ 4 | import { 5 | Scene, 6 | PerspectiveCamera, 7 | WebGLRenderer, 8 | Texture, 9 | Vector3, 10 | SpriteMaterial, 11 | Object3D, 12 | Sprite, 13 | Math as Math2 14 | } from 'three'; 15 | const SEPARATION = 100, AMOUNTX = 50, AMOUNTY = 50; // 圆点间隔、x轴方向个数、y轴方向个数 16 | const waveStep = 0.04; // 波动速度 17 | const rotateStep = 0.02; // 旋转速度 18 | const CAMERAMOVERADIUS = 1000; // 相机旋转半径 19 | const cameraDefPos = new Vector3(0, 180, CAMERAMOVERADIUS); // 相机初始位置 20 | const focusDefPos = new Vector3(0, 700, 0); // 相机注视点位置 21 | 22 | let container; // canvas容器 23 | let scene, camera, renderer; 24 | let particles, particle, count = 0; 25 | let theta = 0; 26 | let focusObject; 27 | 28 | // 生成贴图 29 | function generateTexture() { 30 | let canvas = document.createElement('canvas'); 31 | let context = canvas.getContext('2d'); 32 | canvas.width = 128; 33 | canvas.height = 128; 34 | drawCircle(context, {x: 64, y: 64, r: 60, c: '#fff'}); 35 | return canvas; 36 | } 37 | 38 | // 画圆 39 | function drawCircle(context, arg) { 40 | let PI2 = Math.PI * 2; 41 | arg = arg || {x: 0, y: 0, r: 0.5, c: '#fff'}; 42 | context.fillStyle = arg.c; 43 | context.beginPath(); 44 | context.arc(arg.x, arg.y, arg.r, 0, PI2, true); 45 | context.fill(); 46 | } 47 | 48 | // 生成材质 49 | function getMaterial() { 50 | let texture = new Texture(generateTexture()); 51 | texture.needsUpdate = true; // important! 52 | let material = new SpriteMaterial({color: 0xffffff, map: texture}); 53 | return material; 54 | } 55 | 56 | function onWindowResize() { 57 | camera.aspect = container.clientWidth / container.clientHeight; 58 | camera.updateProjectionMatrix(); 59 | renderer.setSize(container.clientWidth, container.clientHeight); 60 | } 61 | 62 | function drawWaves() { 63 | camera = new PerspectiveCamera(100, container.clientWidth / container.clientHeight, 1, 10000); 64 | camera.position.x = cameraDefPos.x; 65 | camera.position.y = cameraDefPos.y; 66 | camera.position.z = cameraDefPos.z; 67 | 68 | scene = new Scene(); 69 | 70 | focusObject = new Object3D(); 71 | focusObject.position.x = focusDefPos.x; 72 | focusObject.position.y = focusDefPos.y; 73 | focusObject.position.z = focusDefPos.z; 74 | scene.add(focusObject); 75 | 76 | particles = []; 77 | let material = getMaterial(); 78 | let i = 0; 79 | for (let ix = 0; ix < AMOUNTX; ix++) { 80 | for (let iy = 0; iy < AMOUNTY; iy++) { 81 | particle = particles[i++] = new Sprite(material); 82 | particle.position.x = ix * SEPARATION - ((AMOUNTX * SEPARATION - 1) / 2); 83 | particle.position.z = iy * SEPARATION - ((AMOUNTY * SEPARATION - 1) / 2); 84 | scene.add(particle); 85 | } 86 | } 87 | 88 | renderer = new WebGLRenderer({alpha: true}); 89 | renderer.setPixelRatio(window.devicePixelRatio); 90 | renderer.setSize(container.clientWidth, container.clientHeight); 91 | container.appendChild(renderer.domElement); 92 | window.addEventListener('resize', onWindowResize, false); 93 | } 94 | 95 | function animate() { 96 | requestAnimationFrame(animate); 97 | render(); 98 | } 99 | 100 | function render() { 101 | let i = 0; 102 | for (let ix = 0; ix < AMOUNTX; ix++) { 103 | for (let iy = 0; iy < AMOUNTY; iy++) { 104 | particle = particles[i++]; 105 | particle.position.y = (Math.sin((ix + count) * 0.3) * 26) + 106 | (Math.sin((iy + count) * 0.4) * 26); 107 | particle.scale.x = particle.scale.y = (Math.sin((ix + count) * 0.3) + 1) * 3 + 108 | (Math.sin((iy + count) * 0.4) + 1) * 3; 109 | } 110 | } 111 | 112 | theta += rotateStep; 113 | camera.position.x = CAMERAMOVERADIUS * Math.sin(Math2.degToRad(theta)); 114 | camera.position.z = CAMERAMOVERADIUS * Math.cos(Math2.degToRad(theta)); 115 | camera.lookAt(focusObject.position); 116 | 117 | renderer.render(scene, camera); 118 | count += waveStep; 119 | } 120 | 121 | export default { 122 | init(id) { 123 | container = document.querySelector('#' + id); 124 | drawWaves(); 125 | animate(); 126 | }, 127 | removeEvent(){ 128 | window.removeEventListener('resize', onWindowResize); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/components/CMenu.vue: -------------------------------------------------------------------------------- 1 | 187 | 216 | 227 | --------------------------------------------------------------------------------