Browse Source

工程化

master
wally 4 years ago
parent
commit
56ba772544
  1. 8
      .editorconfig
  2. 9
      .eslintignore
  3. 50
      .eslintrc.js
  4. 1
      .gitignore
  5. 4
      .husky/pre-commit
  6. 13
      .prettierrc
  7. 1
      .vscode/settings.json
  8. 1
      commitlint.config.js
  9. 6393
      package-lock.json
  10. 46
      package.json
  11. 39
      src/utils/axios.js
  12. 2485
      yarn.lock

8
.editorconfig

@ -0,0 +1,8 @@
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 140
root = true

9
.eslintignore

@ -0,0 +1,9 @@
node_modules
dist/
test
build/
babel.config.js
package.json
postcss.config.js
.eslintrc.js
vue.config.js

50
.eslintrc.js

@ -0,0 +1,50 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: ['plugin:vue/essential', 'airbnb-base', 'plugin:prettier/recommended'],
parserOptions: {
ecmaVersion: 10,
sourceType: 'module',
},
plugins: ['vue'],
rules: {
'vue/html-self-closing': 'off',
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-param-reassign': 'off',
'max-len': ['error', { code: 140, tabWidth: 2 }],
'object-curly-newline': ['error', { multiline: true }],
'arrow-parens': ['error', 'as-needed'],
'linebreak-style': 'off',
'vue/attributes-order': 'off',
'vue/singleline-html-element-content-newline': 'off',
'vue/max-attributes-per-line': 'off',
'vue/multiline-html-element-content-newline': 'off',
'vue/html-indent': 'off',
'vue/html-closing-bracket-newline': [
'error',
{
singleline: 'never',
multiline: 'always',
},
],
},
overrides: [
{
files: ['**/__tests__/*.{j,t}s?(x)'],
env: { jest: true },
},
],
globals: {
Vue: true,
VueRouter: true,
Vuex: true,
axios: true,
_: true,
uni: true,
},
};

1
.gitignore

@ -3,3 +3,4 @@ node_modules
dist
dist-ssr
*.local
.eslintcache

4
.husky/pre-commit

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged

13
.prettierrc

@ -0,0 +1,13 @@
{
"printWidth": 140,
"singleQuote": true,
"semi": true,
"trailingComma": "all",
"arrowParens": "avoid",
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"jsxBracketSameLine": false,
"proseWrap": "always",
"endOfLine": "lf"
}

1
.vscode/settings.json

@ -1,5 +1,6 @@
{
"cSpell.words": [
"unplugin",
"windi",
"windicss"
]

1
commitlint.config.js

@ -0,0 +1 @@
module.exports = { extends: ['./node_modules/vue-cli-plugin-commitlint/lib/lint'] };

6393
package-lock.json

File diff suppressed because it is too large

46
package.json

@ -4,19 +4,57 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
"serve": "vite preview",
"prepare": "husky install"
},
"dependencies": {
"axios": "^0.23.0",
"element-plus": "^1.1.0-beta.21",
"unplugin-vue-components": "^0.15.6",
"vite-plugin-windicss": "^1.4.11",
"vue": "^3.2.16",
"vue-router": "^4.0.12",
"windicss": "^3.1.9"
},
"devDependencies": {
"@commitlint/cli": "^13.2.1",
"@commitlint/config-conventional": "^13.2.0",
"@vitejs/plugin-vue": "^1.9.3",
"babel-eslint": "^10.1.0",
"commitizen": "^4.2.4",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^7.19.1",
"husky": "^7.0.0",
"lint-staged": "^11.2.3",
"prettier": "^2.4.1",
"unplugin-vue-components": "^0.15.6",
"vite": "^2.6.4",
"vite-plugin-linter": "^1.0.1"
"vite-plugin-linter": "^1.0.1",
"vite-plugin-windicss": "^1.4.11"
},
"browserslist": [
"Android >= 4",
"ios >= 8"
],
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.{js,json,css,vue}": [
"eslint --fix",
"git add"
],
"*.js": "eslint --cache --fix"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

39
src/utils/axios.js

@ -0,0 +1,39 @@
import Axios from 'axios';
import { ElMessage } from 'element-plus';
const baseUrl = 'http://api.github.com';
const instance = Axios.create({
baseUrl,
timeout: 20000,
});
// request
instance.interceptors.request.use(
response => {
return response;
},
error => {
return Promise.reject(error);
},
);
// response
instance.interceptors.response.use(
response => {
return response;
},
error => {
if (error.response && error.response.data) {
const code = error.response.status;
const msg = error.response.data.message;
ElMessage.error(`Code: ${code}, Message: ${msg}`);
console.error(`[Axios Error]`, error.response);
} else {
ElMessage.error(`${error}`);
}
return Promise.reject(error);
},
);
export default instance;

2485
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save