From b44c7384dc8332e8354e8aba20cc3c0fc6dd314d Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 30 Aug 2017 17:42:06 +0800 Subject: [PATCH] refactor --- .eslintrc.js | 408 +++++++++-------------------- build/webpack.base.conf.js | 11 +- package.json | 17 +- src/App.vue | 4 +- src/api/login.js | 11 +- src/api/table.js | 6 +- src/assets/iconfont/iconfont.js | 1 - src/components/Hamburger/index.vue | 47 ++-- src/icons/index.js | 9 + src/icons/svg/404.svg | 1 + src/icons/svg/EXCEL.svg | 1 + src/icons/svg/QQ.svg | 1 + src/icons/svg/a.svg | 1 + src/icons/svg/b.svg | 1 + src/icons/svg/bug.svg | 1 + src/icons/svg/c.svg | 1 + src/icons/svg/email.svg | 1 + src/icons/svg/from.svg | 1 + src/icons/svg/icons.svg | 1 + src/icons/svg/mima.svg | 1 + src/icons/svg/quanxian.svg | 1 + src/icons/svg/shouce.svg | 1 + src/icons/svg/tab.svg | 1 + src/icons/svg/table.svg | 1 + src/icons/svg/theme.svg | 1 + src/icons/svg/tubiao.svg | 1 + src/icons/svg/tuozhuai.svg | 1 + src/icons/svg/weixin.svg | 1 + src/icons/svg/wujiaoxing.svg | 1 + src/icons/svg/xinrenzhinan.svg | 1 + src/icons/svg/yanjing.svg | 1 + src/icons/svg/yonghuming.svg | 1 + src/icons/svg/zonghe.svg | 1 + src/icons/svg/zujian.svg | 1 + src/main.js | 52 +--- src/permission.js | 38 +++ src/router/_import_development.js | 2 +- src/router/index.js | 30 +-- src/store/getters.js | 2 +- src/store/index.js | 16 +- src/store/modules/app.js | 12 +- src/store/modules/permission.js | 14 +- src/store/modules/user.js | 71 +++-- src/utils/fetch.js | 39 ++- src/utils/index.js | 36 +-- src/utils/validate.js | 21 +- src/views/dashboard/index.vue | 22 +- src/views/layout/AppMain.vue | 24 +- src/views/layout/Layout.vue | 45 ++-- src/views/layout/Levelbar.vue | 70 ++--- src/views/layout/Navbar.vue | 86 +++--- src/views/layout/Sidebar.vue | 29 +- src/views/layout/SidebarItem.vue | 70 ++--- src/views/layout/index.js | 8 +- src/views/login/index.vue | 110 ++++---- src/views/page/form.vue | 128 ++++----- src/views/table/index.vue | 40 +-- 57 files changed, 680 insertions(+), 824 deletions(-) delete mode 100644 src/assets/iconfont/iconfont.js create mode 100644 src/icons/index.js create mode 100644 src/icons/svg/404.svg create mode 100644 src/icons/svg/EXCEL.svg create mode 100644 src/icons/svg/QQ.svg create mode 100644 src/icons/svg/a.svg create mode 100644 src/icons/svg/b.svg create mode 100644 src/icons/svg/bug.svg create mode 100644 src/icons/svg/c.svg create mode 100644 src/icons/svg/email.svg create mode 100644 src/icons/svg/from.svg create mode 100644 src/icons/svg/icons.svg create mode 100644 src/icons/svg/mima.svg create mode 100644 src/icons/svg/quanxian.svg create mode 100644 src/icons/svg/shouce.svg create mode 100644 src/icons/svg/tab.svg create mode 100644 src/icons/svg/table.svg create mode 100644 src/icons/svg/theme.svg create mode 100644 src/icons/svg/tubiao.svg create mode 100644 src/icons/svg/tuozhuai.svg create mode 100644 src/icons/svg/weixin.svg create mode 100644 src/icons/svg/wujiaoxing.svg create mode 100644 src/icons/svg/xinrenzhinan.svg create mode 100644 src/icons/svg/yanjing.svg create mode 100644 src/icons/svg/yonghuming.svg create mode 100644 src/icons/svg/zonghe.svg create mode 100644 src/icons/svg/zujian.svg create mode 100644 src/permission.js diff --git a/.eslintrc.js b/.eslintrc.js index a388ba2..006e982 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,7 +6,8 @@ module.exports = { }, env: { browser: true, - node: true + node: true, + es6: true, }, extends: 'eslint:recommended', // required to lint *.vue files @@ -22,297 +23,122 @@ module.exports = { } }, // add your custom rules here + //it is base on https://github.com/vuejs/eslint-config-vue 'rules': { - // don't require .vue extension when importing - // 'import/extensions': ['error', 'always', { - // 'js': 'never', - // 'vue': 'never' - // }], - // allow debugger during development - 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, - /* - * Possible Errors - */ - - // disallow unnecessary parentheses - 'no-extra-parens': ['error', 'all', {'nestedBinaryExpressions': false}], - - // disallow negating the left operand of relational operators - 'no-unsafe-negation': 'error', - - // enforce valid JSDoc comments - 'valid-jsdoc': 'off', - - /* - * Best Practices - */ - - // enforce return statements in callbacks of array methods - 'array-callback-return': 'error', - - // enforce consistent brace style for all control statements - curly: ['error', 'multi-line'], - - // enforce consistent newlines before and after dots - 'dot-location': ['error', 'property'], - - // enforce dot notation whenever possible - 'dot-notation': 'error', - - // require the use of === and !== - 'eqeqeq': ['error', 'smart'], - - // disallow the use of arguments.caller or arguments.callee - 'no-caller': 'error', - - // disallow empty functions - 'no-empty-function': 'error', - - // disallow unnecessary calls to .bind() - 'no-extra-bind': 'error', - - // disallow unnecessary labels - 'no-extra-label': 'error', - - // disallow leading or trailing decimal points in numeric literals - 'no-floating-decimal': 'error', - - // disallow assignments to native objects or read-only global variables - 'no-global-assign': 'error', - - // disallow the use of eval()-like methods - 'no-implied-eval': 'error', - - // disallow the use of the __iterator__ property - 'no-iterator': 'error', - - // disallow unnecessary nested blocks - 'no-lone-blocks': 'error', - - // disallow multiple spaces - 'no-multi-spaces': 'error', - - // disallow new operators with the String, Number, and Boolean objects - 'no-new-wrappers': 'error', - - // disallow octal escape sequences in string literals - 'no-octal-escape': 'error', - - // disallow the use of the __proto__ property - 'no-proto': 'error', - - // disallow comparisons where both sides are exactly the same - 'no-self-compare': 'error', - - // disallow throwing literals as exceptions - 'no-throw-literal': 'error', - - // disallow unused expressions - 'no-unused-expressions': 'error', - - // disallow unnecessary calls to .call() and .apply() - 'no-useless-call': 'error', - - // disallow unnecessary concatenation of literals or template literals - 'no-useless-concat': 'error', - - // disallow unnecessary escape characters - 'no-useless-escape': 'error', - - // disallow void operators - 'no-void': 'error', - - // require parentheses around immediate function invocations - 'wrap-iife': 'error', - - // require or disallow “Yoda” conditions - yoda: 'error', - - /* - * Variables - */ - - // disallow labels that share a name with a variable - 'no-label-var': 'error', - - // disallow initializing variables to undefined - 'no-undef-init': 'error', - 'no-undef': 'off', - // disallow the use of variables before they are defined - 'no-use-before-define': 'error', - - /* - * Node.js and CommonJS - */ - - // disallow new operators with calls to require - 'no-new-require': 'error', - - /* - * Stylistic Issues - */ - - // enforce consistent spacing inside array brackets - 'array-bracket-spacing': 'error', - - // enforce consistent spacing inside single-line blocks - 'block-spacing': 'error', - - // enforce consistent brace style for blocks - 'brace-style': ['error', '1tbs', {'allowSingleLine': true}], - - // require or disallow trailing commas - 'comma-dangle': 'error', - - // enforce consistent spacing before and after commas - 'comma-spacing': 'error', - - // enforce consistent comma style - 'comma-style': 'error', - - // enforce consistent spacing inside computed property brackets - 'computed-property-spacing': 'error', - - // require or disallow spacing between function identifiers and their invocations - 'func-call-spacing': 'error', - - // enforce consistent indentation - indent: ['error', 2, {SwitchCase: 1}], - - // enforce the consistent use of either double or single quotes in JSX attributes - 'jsx-quotes': 'error', - - // enforce consistent spacing between keys and values in object literal properties - 'key-spacing': 'error', - - // enforce consistent spacing before and after keywords - 'keyword-spacing': 'error', - - // enforce consistent linebreak style - 'linebreak-style': 'error', - - // require or disallow newlines around directives - 'lines-around-directive': 'error', - - // require constructor names to begin with a capital letter - 'new-cap': 'off', - - // require parentheses when invoking a constructor with no arguments - 'new-parens': 'error', - - // disallow Array constructors - 'no-array-constructor': 'error', - - // disallow Object constructors - 'no-new-object': 'error', - - // disallow trailing whitespace at the end of lines - 'no-trailing-spaces': 'error', - - // disallow ternary operators when simpler alternatives exist - 'no-unneeded-ternary': 'error', - - // disallow whitespace before properties - 'no-whitespace-before-property': 'error', - - // enforce consistent spacing inside braces - 'object-curly-spacing': ['error', 'always'], - - // require or disallow padding within blocks - 'padded-blocks': ['error', 'never'], - - // require quotes around object literal property names - 'quote-props': ['error', 'as-needed'], - - // enforce the consistent use of either backticks, double, or single quotes - quotes: ['error', 'single'], - - // enforce consistent spacing before and after semicolons - 'semi-spacing': 'error', - - // require or disallow semicolons instead of ASI - // semi: ['error', 'never'], - - // enforce consistent spacing before blocks - 'space-before-blocks': 'error', - + 'accessor-pairs': 2, + 'arrow-spacing': [2, { 'before': true, 'after': true }], + 'block-spacing': [2, 'always'], + 'brace-style': [2, '1tbs', { 'allowSingleLine': true }], + 'camelcase': [0, { 'properties': 'always' }], + 'comma-dangle': [2, 'never'], + 'comma-spacing': [2, { 'before': false, 'after': true }], + 'comma-style': [2, 'last'], + 'constructor-super': 2, + 'curly': [2, 'multi-line'], + 'dot-location': [2, 'property'], + 'eol-last': 2, + 'eqeqeq': [2, 'allow-null'], + 'generator-star-spacing': [2, { 'before': true, 'after': true }], + 'handle-callback-err': [2, '^(err|error)$' ], + 'indent': [2, 2, { 'SwitchCase': 1 }], + 'jsx-quotes': [2, 'prefer-single'], + 'key-spacing': [2, { 'beforeColon': false, 'afterColon': true }], + 'keyword-spacing': [2, { 'before': true, 'after': true }], + 'new-cap': [2, { 'newIsCap': true, 'capIsNew': false }], + 'new-parens': 2, + 'no-array-constructor': 2, + 'no-caller': 2, 'no-console': 'off', - - // enforce consistent spacing before function definition opening parenthesis - 'space-before-function-paren': ['error', 'never'], - - // enforce consistent spacing inside parentheses - 'space-in-parens': 'error', - - // require spacing around infix operators - 'space-infix-ops': 'error', - - // enforce consistent spacing before or after unary operators - 'space-unary-ops': 'error', - - // enforce consistent spacing after the // or /* in a comment - 'spaced-comment': 'error', - - // require or disallow Unicode byte order mark (BOM) - 'unicode-bom': 'error', - - - /* - * ECMAScript 6 - */ - - // require braces around arrow function bodies - 'arrow-body-style': 'error', - - // require parentheses around arrow function arguments - 'arrow-parens': ['error', 'as-needed'], - - // enforce consistent spacing before and after the arrow in arrow functions - 'arrow-spacing': 'error', - - // enforce consistent spacing around * operators in generator functions - 'generator-star-spacing': ['error', 'after'], - - // disallow duplicate module imports - 'no-duplicate-imports': 'error', - - // disallow unnecessary computed property keys in object literals - 'no-useless-computed-key': 'error', - - // disallow unnecessary constructors - 'no-useless-constructor': 'error', - - // disallow renaming import, export, and destructured assignments to the same name - 'no-useless-rename': 'error', - - // require let or const instead of var - 'no-var': 'error', - - // require or disallow method and property shorthand syntax for object literals - 'object-shorthand': 'error', - - // require arrow functions as callbacks - 'prefer-arrow-callback': 'error', - - // require const declarations for variables that are never reassigned after declared - 'prefer-const': 'error', - - // disallow parseInt() in favor of binary, octal, and hexadecimal literals - 'prefer-numeric-literals': 'error', - - // require rest parameters instead of arguments - 'prefer-rest-params': 'error', - - // require spread operators instead of .apply() - 'prefer-spread': 'error', - - // enforce spacing between rest and spread operators and their expressions - 'rest-spread-spacing': 'error', - - // require or disallow spacing around embedded expressions of template strings - 'template-curly-spacing': 'error', - - // require or disallow spacing around the * in yield* expressions - 'yield-star-spacing': 'error' + 'no-class-assign': 2, + 'no-cond-assign': 2, + 'no-const-assign': 2, + 'no-control-regex': 2, + 'no-delete-var': 2, + 'no-dupe-args': 2, + 'no-dupe-class-members': 2, + 'no-dupe-keys': 2, + 'no-duplicate-case': 2, + 'no-empty-character-class': 2, + 'no-empty-pattern': 2, + 'no-eval': 2, + 'no-ex-assign': 2, + 'no-extend-native': 2, + 'no-extra-bind': 2, + 'no-extra-boolean-cast': 2, + 'no-extra-parens': [2, 'functions'], + 'no-fallthrough': 2, + 'no-floating-decimal': 2, + 'no-func-assign': 2, + 'no-implied-eval': 2, + 'no-inner-declarations': [2, 'functions'], + 'no-invalid-regexp': 2, + 'no-irregular-whitespace': 2, + 'no-iterator': 2, + 'no-label-var': 2, + 'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }], + 'no-lone-blocks': 2, + 'no-mixed-spaces-and-tabs': 2, + 'no-multi-spaces': 2, + 'no-multi-str': 2, + 'no-multiple-empty-lines': [2, { 'max': 1 }], + 'no-native-reassign': 2, + 'no-negated-in-lhs': 2, + 'no-new-object': 2, + 'no-new-require': 2, + 'no-new-symbol': 2, + 'no-new-wrappers': 2, + 'no-obj-calls': 2, + 'no-octal': 2, + 'no-octal-escape': 2, + 'no-path-concat': 2, + 'no-proto': 2, + 'no-redeclare': 2, + 'no-regex-spaces': 2, + 'no-return-assign': [2, 'except-parens'], + 'no-self-assign': 2, + 'no-self-compare': 2, + 'no-sequences': 2, + 'no-shadow-restricted-names': 2, + 'no-spaced-func': 2, + 'no-sparse-arrays': 2, + 'no-this-before-super': 2, + 'no-throw-literal': 2, + 'no-trailing-spaces': 2, + 'no-undef': 2, + 'no-undef-init': 2, + 'no-unexpected-multiline': 2, + 'no-unmodified-loop-condition': 2, + 'no-unneeded-ternary': [2, { 'defaultAssignment': false }], + 'no-unreachable': 2, + 'no-unsafe-finally': 2, + 'no-unused-vars': [2, { 'vars': 'all', 'args': 'none' }], + 'no-useless-call': 2, + 'no-useless-computed-key': 2, + 'no-useless-constructor': 2, + 'no-useless-escape': 0, + 'no-whitespace-before-property': 2, + 'no-with': 2, + 'one-var': [2, { 'initialized': 'never' }], + 'operator-linebreak': [2, 'after', { 'overrides': { '?': 'before', ':': 'before' } }], + 'padded-blocks': [2, 'never'], + 'quotes': [2, 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true }], + 'semi': [2, 'never'], + 'semi-spacing': [2, { 'before': false, 'after': true }], + 'space-before-blocks': [2, 'always'], + 'space-before-function-paren': [2, 'never'], + 'space-in-parens': [2, 'never'], + 'space-infix-ops': 2, + 'space-unary-ops': [2, { 'words': true, 'nonwords': false }], + 'spaced-comment': [2, 'always', { 'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','] }], + 'template-curly-spacing': [2, 'never'], + 'use-isnan': 2, + 'valid-typeof': 2, + 'wrap-iife': [2, 'any'], + 'yield-star-spacing': [2, 'both'], + 'yoda': [2, 'never'], + 'prefer-const': 2, + 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, + 'object-curly-spacing': [2, 'always', { objectsInObjects: false }], + 'array-bracket-spacing': [2, 'never'] } } diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js index 30817ad..72005d0 100644 --- a/build/webpack.base.conf.js +++ b/build/webpack.base.conf.js @@ -46,10 +46,19 @@ module.exports = { loader: 'babel-loader', include: [resolve('src'), resolve('test')] }, + { + test: /\.svg$/, + loader: 'svg-sprite-loader', + include: [resolve('src/icons')], + options: { + symbolId: 'icon-[name]' + } + }, { test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', - options: { + exclude: [resolve('src/icons')], + query: { limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } diff --git a/package.json b/package.json index 5c18afb..92cdb2e 100644 --- a/package.json +++ b/package.json @@ -12,12 +12,12 @@ }, "dependencies": { "axios": "0.16.2", - "element-ui": "1.3.7", - "js-cookie": "^2.1.4", - "normalize.css": "3.0.2", - "nprogress": "^0.2.0", - "vue": "2.3.3", - "vue-router": "2.5.3", + "element-ui": "1.4.3", + "js-cookie": "2.1.4", + "normalize.css": "7.0.0", + "nprogress": "0.2.0", + "vue": "2.4.2", + "vue-router": "2.7.0", "vuex": "2.3.1" }, "devDependencies": { @@ -53,10 +53,11 @@ "rimraf": "2.6.0", "node-sass": "^4.5.0", "sass-loader": "6.0.5", + "svg-sprite-loader": "3.2.4", "url-loader": "0.5.8", - "vue-loader": "12.1.0", + "vue-loader": "13.0.4", "vue-style-loader": "3.0.1", - "vue-template-compiler": "2.3.3", + "vue-template-compiler": "2.4.2", "webpack": "2.6.1", "webpack-dev-middleware": "1.10.0", "webpack-hot-middleware": "2.18.0", diff --git a/src/App.vue b/src/App.vue index 16fce5e..d042fd4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,8 +9,8 @@ export default { name: 'app' } + - - diff --git a/src/api/login.js b/src/api/login.js index 1b14881..eed7c5b 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -1,4 +1,4 @@ -import fetch from '@/utils/fetch'; +import fetch from '@/utils/fetch' export function login(email, password) { return fetch({ @@ -8,7 +8,7 @@ export function login(email, password) { email, password } - }); + }) } export function getInfo(token) { @@ -16,15 +16,12 @@ export function getInfo(token) { url: '/user/info', method: 'get', params: { token } - }); + }) } export function logout() { return fetch({ url: '/user/logout', method: 'post' - }); + }) } - - - diff --git a/src/api/table.js b/src/api/table.js index b475c0a..7079817 100644 --- a/src/api/table.js +++ b/src/api/table.js @@ -1,11 +1,9 @@ -import fetch from '@/utils/fetch'; +import fetch from '@/utils/fetch' export function getList(params) { return fetch({ url: '/table/list', method: 'get', params - }); + }) } - - diff --git a/src/assets/iconfont/iconfont.js b/src/assets/iconfont/iconfont.js deleted file mode 100644 index 11a01bd..0000000 --- a/src/assets/iconfont/iconfont.js +++ /dev/null @@ -1 +0,0 @@ -(function(window){var svgSprite=""+""+''+""+''+""+""+""+''+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+''+""+""+""+''+""+''+""+''+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+''+""+''+""+""+""+"";var script=function(){var scripts=document.getElementsByTagName("script");return scripts[scripts.length-1]}();var shouldInjectCss=script.getAttribute("data-injectcss");var ready=function(fn){if(document.addEventListener){if(~["complete","loaded","interactive"].indexOf(document.readyState)){setTimeout(fn,0)}else{var loadFn=function(){document.removeEventListener("DOMContentLoaded",loadFn,false);fn()};document.addEventListener("DOMContentLoaded",loadFn,false)}}else if(document.attachEvent){IEContentLoaded(window,fn)}function IEContentLoaded(w,fn){var d=w.document,done=false,init=function(){if(!done){done=true;fn()}};var polling=function(){try{d.documentElement.doScroll("left")}catch(e){setTimeout(polling,50);return}init()};polling();d.onreadystatechange=function(){if(d.readyState=="complete"){d.onreadystatechange=null;init()}}}};var before=function(el,target){target.parentNode.insertBefore(el,target)};var prepend=function(el,target){if(target.firstChild){before(el,target.firstChild)}else{target.appendChild(el)}};function appendSvg(){var div,svg;div=document.createElement("div");div.innerHTML=svgSprite;svgSprite=null;svg=div.getElementsByTagName("svg")[0];if(svg){svg.setAttribute("aria-hidden","true");svg.style.position="absolute";svg.style.width=0;svg.style.height=0;svg.style.overflow="hidden";prepend(svg,document.body)}}if(shouldInjectCss&&!window.__iconfont__svg__cssinject__){window.__iconfont__svg__cssinject__=true;try{document.write("")}catch(e){console&&console.log(e)}}ready(appendSvg)})(window) \ No newline at end of file diff --git a/src/components/Hamburger/index.vue b/src/components/Hamburger/index.vue index b0d1597..9ad0bb2 100644 --- a/src/components/Hamburger/index.vue +++ b/src/components/Hamburger/index.vue @@ -1,32 +1,31 @@ \ No newline at end of file diff --git a/src/icons/svg/EXCEL.svg b/src/icons/svg/EXCEL.svg new file mode 100644 index 0000000..e5dd5ce --- /dev/null +++ b/src/icons/svg/EXCEL.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/QQ.svg b/src/icons/svg/QQ.svg new file mode 100644 index 0000000..97aee71 --- /dev/null +++ b/src/icons/svg/QQ.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/a.svg b/src/icons/svg/a.svg new file mode 100644 index 0000000..6297fe8 --- /dev/null +++ b/src/icons/svg/a.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/b.svg b/src/icons/svg/b.svg new file mode 100644 index 0000000..0c08ff0 --- /dev/null +++ b/src/icons/svg/b.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/bug.svg b/src/icons/svg/bug.svg new file mode 100644 index 0000000..a12a939 --- /dev/null +++ b/src/icons/svg/bug.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/c.svg b/src/icons/svg/c.svg new file mode 100644 index 0000000..17124d9 --- /dev/null +++ b/src/icons/svg/c.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/email.svg b/src/icons/svg/email.svg new file mode 100644 index 0000000..8a87e14 --- /dev/null +++ b/src/icons/svg/email.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/from.svg b/src/icons/svg/from.svg new file mode 100644 index 0000000..7a4bd16 --- /dev/null +++ b/src/icons/svg/from.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/icons.svg b/src/icons/svg/icons.svg new file mode 100644 index 0000000..906af96 --- /dev/null +++ b/src/icons/svg/icons.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/mima.svg b/src/icons/svg/mima.svg new file mode 100644 index 0000000..920b500 --- /dev/null +++ b/src/icons/svg/mima.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/quanxian.svg b/src/icons/svg/quanxian.svg new file mode 100644 index 0000000..37c6070 --- /dev/null +++ b/src/icons/svg/quanxian.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/shouce.svg b/src/icons/svg/shouce.svg new file mode 100644 index 0000000..94c68bb --- /dev/null +++ b/src/icons/svg/shouce.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/tab.svg b/src/icons/svg/tab.svg new file mode 100644 index 0000000..657057d --- /dev/null +++ b/src/icons/svg/tab.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/table.svg b/src/icons/svg/table.svg new file mode 100644 index 0000000..083bc8c --- /dev/null +++ b/src/icons/svg/table.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/theme.svg b/src/icons/svg/theme.svg new file mode 100644 index 0000000..9c0873c --- /dev/null +++ b/src/icons/svg/theme.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/tubiao.svg b/src/icons/svg/tubiao.svg new file mode 100644 index 0000000..b1b3133 --- /dev/null +++ b/src/icons/svg/tubiao.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/tuozhuai.svg b/src/icons/svg/tuozhuai.svg new file mode 100644 index 0000000..819c8d5 --- /dev/null +++ b/src/icons/svg/tuozhuai.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/weixin.svg b/src/icons/svg/weixin.svg new file mode 100644 index 0000000..d88a64b --- /dev/null +++ b/src/icons/svg/weixin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/wujiaoxing.svg b/src/icons/svg/wujiaoxing.svg new file mode 100644 index 0000000..685a301 --- /dev/null +++ b/src/icons/svg/wujiaoxing.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/xinrenzhinan.svg b/src/icons/svg/xinrenzhinan.svg new file mode 100644 index 0000000..3985ab5 --- /dev/null +++ b/src/icons/svg/xinrenzhinan.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/yanjing.svg b/src/icons/svg/yanjing.svg new file mode 100644 index 0000000..194aa45 --- /dev/null +++ b/src/icons/svg/yanjing.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/yonghuming.svg b/src/icons/svg/yonghuming.svg new file mode 100644 index 0000000..5971dee --- /dev/null +++ b/src/icons/svg/yonghuming.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/zonghe.svg b/src/icons/svg/zonghe.svg new file mode 100644 index 0000000..681422e --- /dev/null +++ b/src/icons/svg/zonghe.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/zujian.svg b/src/icons/svg/zujian.svg new file mode 100644 index 0000000..d183e56 --- /dev/null +++ b/src/icons/svg/zujian.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/main.js b/src/main.js index 40793c8..3562169 100644 --- a/src/main.js +++ b/src/main.js @@ -1,56 +1,16 @@ -// The Vue build version to load with the `import` command -// (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' +import ElementUI from 'element-ui' +import 'element-ui/lib/theme-default/index.css' import App from './App' import router from './router' import store from './store' -import ElementUI from 'element-ui' -import 'element-ui/lib/theme-default/index.css' -import NProgress from 'nprogress' -import 'nprogress/nprogress.css' -import 'normalize.css/normalize.css' -import '@/assets/iconfont/iconfont' -import IconSvg from '@/components/Icon-svg/index.vue' -import { getToken } from '@/utils/auth' +import '@/icons' // icon +import '@/permission' // 权限 + +Vue.use(ElementUI) Vue.config.productionTip = false -Vue.use(ElementUI); -Vue.component('icon-svg', IconSvg) - -const whiteList = ['/login']; -router.beforeEach((to, from, next) => { - NProgress.start(); - if (getToken()) { - if (to.path === '/login') { - next({ path: '/' }); - } else { - if (store.getters.roles.length === 0) { - store.dispatch('GetInfo').then(res => { - const roles = res.data.role; - store.dispatch('GenerateRoutes', { roles }).then(() => { - router.addRoutes(store.getters.addRouters); - next({ ...to }); - }) - }) - } else { - next(); - } - } - } else { - if (whiteList.indexOf(to.path) !== -1) { - next() - } else { - next('/login'); - NProgress.done(); - } - } -}); - -router.afterEach(() => { - NProgress.done(); -}); - new Vue({ el: '#app', router, diff --git a/src/permission.js b/src/permission.js new file mode 100644 index 0000000..f327b4d --- /dev/null +++ b/src/permission.js @@ -0,0 +1,38 @@ +import router from './router' +import store from './store' +import NProgress from 'nprogress' // Progress 进度条 +import 'nprogress/nprogress.css'// Progress 进度条样式 +import { getToken } from '@/utils/auth' // 验权 + +const whiteList = ['/login'] +router.beforeEach((to, from, next) => { + NProgress.start() + if (getToken()) { + if (to.path === '/login') { + next({ path: '/' }) + } else { + if (store.getters.roles.length === 0) { + store.dispatch('GetInfo').then(res => { + const roles = res.data.role + store.dispatch('GenerateRoutes', { roles }).then(() => { + router.addRoutes(store.getters.addRouters) + next({ ...to }) + }) + }) + } else { + next() + } + } + } else { + if (whiteList.indexOf(to.path) !== -1) { + next() + } else { + next('/login') + NProgress.done() + } + } +}) + +router.afterEach(() => { + NProgress.done() // 结束Progress +}) diff --git a/src/router/_import_development.js b/src/router/_import_development.js index dfa4bb9..84bf7a9 100644 --- a/src/router/_import_development.js +++ b/src/router/_import_development.js @@ -1 +1 @@ -module.exports = file => require('@/views/' + file + '.vue') +module.exports = file => require('@/views/' + file + '.vue').default diff --git a/src/router/index.js b/src/router/index.js index 9a3455e..82ad39b 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,25 +1,25 @@ -import Vue from 'vue'; -import Router from 'vue-router'; -const _import = require('./_import_' + process.env.NODE_ENV); -// in development env not use Lazy Loading,because Lazy Loading large page will cause webpack hot update too slow.so only in production use Lazy Loading +import Vue from 'vue' +import Router from 'vue-router' +const _import = require('./_import_' + process.env.NODE_ENV) +// in development env not use Lazy Loading,because Lazy Loading too many pages will cause webpack hot update too slow.so only in production use Lazy Loading /* layout */ -import Layout from '../views/layout/Layout'; +import Layout from '../views/layout/Layout' /* login */ -const Login = _import('login/index'); +const Login = _import('login/index') /* dashboard */ -const dashboard = _import('dashboard/index'); +const dashboard = _import('dashboard/index') /* error page */ -const Err404 = _import('404'); +const Err404 = _import('404') /* demo page */ -const Form = _import('page/form'); -const Table = _import('table/index'); +const Form = _import('page/form') +const Table = _import('table/index') -Vue.use(Router); +Vue.use(Router) /** * icon : the icon show in the sidebar @@ -45,7 +45,7 @@ export default new Router({ // mode: 'history', //后端支持可开 scrollBehavior: () => ({ y: 0 }), routes: constantRouterMap -}); +}) export const asyncRouterMap = [ { @@ -63,10 +63,10 @@ export const asyncRouterMap = [ path: '/table', component: Layout, redirect: '/table/index', - icon: 'tubiaoleixingzhengchang', + icon: 'tubiao', noDropdown: true, - children: [{ path: 'index', component: Table, name: 'Table', meta: { role: ['admin'] } }] + children: [{ path: 'index', component: Table, name: 'Table', meta: { role: ['admin'] }}] }, { path: '*', redirect: '/404', hidden: true } -]; +] diff --git a/src/store/getters.js b/src/store/getters.js index 8553cd8..61adedb 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -6,5 +6,5 @@ const getters = { roles: state => state.user.roles, permission_routers: state => state.permission.routers, addRouters: state => state.permission.addRouters -}; +} export default getters diff --git a/src/store/index.js b/src/store/index.js index ee7d313..9bfa6a7 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,11 +1,11 @@ -import Vue from 'vue'; -import Vuex from 'vuex'; -import app from './modules/app'; -import user from './modules/user'; -import permission from './modules/permission'; -import getters from './getters'; +import Vue from 'vue' +import Vuex from 'vuex' +import app from './modules/app' +import user from './modules/user' +import permission from './modules/permission' +import getters from './getters' -Vue.use(Vuex); +Vue.use(Vuex) const store = new Vuex.Store({ modules: { @@ -14,6 +14,6 @@ const store = new Vuex.Store({ permission }, getters -}); +}) export default store diff --git a/src/store/modules/app.js b/src/store/modules/app.js index 0087174..e49b16a 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,4 +1,4 @@ -import Cookies from 'js-cookie'; +import Cookies from 'js-cookie' const app = { state: { @@ -9,11 +9,11 @@ const app = { mutations: { TOGGLE_SIDEBAR: state => { if (state.sidebar.opened) { - Cookies.set('sidebarStatus', 1); + Cookies.set('sidebarStatus', 1) } else { - Cookies.set('sidebarStatus', 0); + Cookies.set('sidebarStatus', 0) } - state.sidebar.opened = !state.sidebar.opened; + state.sidebar.opened = !state.sidebar.opened } }, actions: { @@ -21,6 +21,6 @@ const app = { commit('TOGGLE_SIDEBAR') } } -}; +} -export default app; +export default app diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index ef2b347..a62f96b 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -1,4 +1,4 @@ -import { asyncRouterMap, constantRouterMap } from '@/router/index'; +import { asyncRouterMap, constantRouterMap } from '@/router/index' /** * 通过meta.role判断是否与当前用户权限匹配 @@ -38,8 +38,8 @@ const permission = { }, mutations: { SET_ROUTERS: (state, routers) => { - state.addRouters = routers; - state.routers = constantRouterMap.concat(routers); + state.addRouters = routers + state.routers = constantRouterMap.concat(routers) } }, actions: { @@ -52,11 +52,11 @@ const permission = { } else { accessedRouters = filterAsyncRouter(asyncRouterMap, roles) } - commit('SET_ROUTERS', accessedRouters); - resolve(); + commit('SET_ROUTERS', accessedRouters) + resolve() }) } } -}; +} -export default permission; +export default permission diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 9fc332c..5a204b3 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -1,5 +1,5 @@ -import { login, logout, getInfo } from '@/api/login'; -import { getToken, setToken, removeToken } from '@/utils/auth'; +import { login, logout, getInfo } from '@/api/login' +import { getToken, setToken, removeToken } from '@/utils/auth' const user = { state: { @@ -11,74 +11,73 @@ const user = { mutations: { SET_TOKEN: (state, token) => { - state.token = token; + state.token = token }, SET_NAME: (state, name) => { - state.name = name; + state.name = name }, SET_AVATAR: (state, avatar) => { - state.avatar = avatar; + state.avatar = avatar }, SET_ROLES: (state, roles) => { - state.roles = roles; + state.roles = roles } }, actions: { // 登录 Login({ commit }, userInfo) { - const email = userInfo.email.trim(); + const email = userInfo.email.trim() return new Promise((resolve, reject) => { login(email, userInfo.password).then(response => { - const data = response.data; - setToken(data.token); - commit('SET_TOKEN', data.token); - resolve(); + const data = response.data + setToken(data.token) + commit('SET_TOKEN', data.token) + resolve() }).catch(error => { - reject(error); - }); - }); + reject(error) + }) + }) }, - // 获取用户信息 GetInfo({ commit, state }) { return new Promise((resolve, reject) => { getInfo(state.token).then(response => { - const data = response.data; - commit('SET_ROLES', data.role); - commit('SET_NAME', data.name); - commit('SET_AVATAR', data.avatar); - resolve(response); + const data = response.data + commit('SET_ROLES', data.role) + commit('SET_NAME', data.name) + commit('SET_AVATAR', data.avatar) + resolve(response) }).catch(error => { - reject(error); - }); - }); + reject(error) + }) + }) }, // 登出 LogOut({ commit, state }) { return new Promise((resolve, reject) => { logout(state.token).then(() => { - commit('SET_TOKEN', ''); - commit('SET_ROLES', []); - removeToken(); - resolve(); + commit('SET_TOKEN', '') + commit('SET_ROLES', []) + removeToken() + resolve() }).catch(error => { - reject(error); - }); - }); + reject(error) + }) + }) }, // 前端 登出 FedLogOut({ commit }) { return new Promise(resolve => { - commit('SET_TOKEN', ''); - removeToken(); - resolve(); - }); + commit('SET_TOKEN', '') + removeToken() + resolve() + }) } } -}; +} -export default user; +export default user diff --git a/src/utils/fetch.js b/src/utils/fetch.js index d0f7c54..476523a 100644 --- a/src/utils/fetch.js +++ b/src/utils/fetch.js @@ -1,25 +1,24 @@ -import axios from 'axios'; -import { Message } from 'element-ui'; -import store from '../store'; -import { getToken } from '@/utils/auth'; - +import axios from 'axios' +import { Message } from 'element-ui' +import store from '../store' +import { getToken } from '@/utils/auth' // 创建axios实例 const service = axios.create({ baseURL: process.env.BASE_API, // api的base_url timeout: 15000 // 请求超时时间 -}); +}) // request拦截器 service.interceptors.request.use(config => { if (store.getters.token) { - config.headers['X-Token'] = getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改 + config.headers['X-Token'] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改 } - return config; + return config }, error => { // Do something with request error - console.log(error); // for debug - Promise.reject(error); + console.log(error) // for debug + Promise.reject(error) }) // respone拦截器 @@ -28,13 +27,13 @@ service.interceptors.response.use( /** * code为非20000是抛错 可结合自己业务进行修改 */ - const res = response.data; + const res = response.data if (res.code !== 20000) { Message({ message: res.data, type: 'error', duration: 5 * 1000 - }); + }) // 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了; if (res.code === 50008 || res.code === 50012 || res.code === 50014) { @@ -44,24 +43,24 @@ service.interceptors.response.use( type: 'warning' }).then(() => { store.dispatch('FedLogOut').then(() => { - location.reload();// 为了重新实例化vue-router对象 避免bug - }); + location.reload()// 为了重新实例化vue-router对象 避免bug + }) }) } - return Promise.reject('error'); + return Promise.reject('error') } else { - return response.data; + return response.data } }, error => { - console.log('err' + error);// for debug + console.log('err' + error)// for debug Message({ message: error.message, type: 'error', duration: 5 * 1000 - }); - return Promise.reject(error); + }) + return Promise.reject(error) } ) -export default service; +export default service diff --git a/src/utils/index.js b/src/utils/index.js index f13c7f3..c233580 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -4,15 +4,15 @@ export function parseTime(time, cFormat) { if (arguments.length === 0) { - return null; + return null } - const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'; - let date; - if (typeof time == 'object') { - date = time; + const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}' + let date + if (typeof time === 'object') { + date = time } else { - if (('' + time).length === 10) time = parseInt(time) * 1000; - date = new Date(time); + if (('' + time).length === 10) time = parseInt(time) * 1000 + date = new Date(time) } const formatObj = { y: date.getFullYear(), @@ -22,24 +22,24 @@ i: date.getMinutes(), s: date.getSeconds(), a: date.getDay() - }; + } const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { - let value = formatObj[key]; - if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]; + let value = formatObj[key] + if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1] if (result.length > 0 && value < 10) { - value = '0' + value; + value = '0' + value } - return value || 0; - }); - return time_str; + return value || 0 + }) + return time_str } export function formatTime(time, option) { - time = +time * 1000; - const d = new Date(time); - const now = Date.now(); + time = +time * 1000 + const d = new Date(time) + const now = Date.now() - const diff = (now - d) / 1000; + const diff = (now - d) / 1000 if (diff < 30) { return '刚刚' diff --git a/src/utils/validate.js b/src/utils/validate.js index 6051c04..41339a2 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -4,32 +4,31 @@ /* 是否是公司邮箱*/ export function isWscnEmail(str) { - const reg = /^[a-z0-9](?:[-_.+]?[a-z0-9]+)*@wallstreetcn\.com$/i; - return reg.test(str.trim()); + const reg = /^[a-z0-9](?:[-_.+]?[a-z0-9]+)*@wallstreetcn\.com$/i + return reg.test(str.trim()) } /* 合法uri*/ export function validateURL(textval) { - const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/; - return urlregex.test(textval); + const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/ + return urlregex.test(textval) } /* 小写字母*/ export function validateLowerCase(str) { - const reg = /^[a-z]+$/; - return reg.test(str); + const reg = /^[a-z]+$/ + return reg.test(str) } /* 大写字母*/ export function validateUpperCase(str) { - const reg = /^[A-Z]+$/; - return reg.test(str); + const reg = /^[A-Z]+$/ + return reg.test(str) } /* 大小写字母*/ export function validatAlphabets(str) { - const reg = /^[A-Za-z]+$/; - return reg.test(str); + const reg = /^[A-Za-z]+$/ + return reg.test(str) } - diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index 52cc61c..cef3a04 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -6,19 +6,19 @@ - diff --git a/src/views/layout/Navbar.vue b/src/views/layout/Navbar.vue index 9afafa7..4541d43 100644 --- a/src/views/layout/Navbar.vue +++ b/src/views/layout/Navbar.vue @@ -1,51 +1,51 @@ - - diff --git a/src/views/layout/Sidebar.vue b/src/views/layout/Sidebar.vue index 57ee036..2ba4fdf 100644 --- a/src/views/layout/Sidebar.vue +++ b/src/views/layout/Sidebar.vue @@ -1,25 +1,24 @@ diff --git a/src/views/layout/SidebarItem.vue b/src/views/layout/SidebarItem.vue index e635f22..0789c0b 100644 --- a/src/views/layout/SidebarItem.vue +++ b/src/views/layout/SidebarItem.vue @@ -1,46 +1,46 @@