Browse Source

feat: eslint修复

lanjianrong 5 years atrás
parent
commit
eccca2ddd0
4 changed files with 26 additions and 16 deletions
  1. 7 7
      .eslintrc.js
  2. 7 7
      .prettierrc.js
  3. 11 1
      src/utils/request.js
  4. 1 1
      src/utils/utils.js

+ 7 - 7
.eslintrc.js

@@ -1,17 +1,17 @@
 module.exports = {
-  extends: [require.resolve('@umijs/fabric/dist/eslint')],
+  extends: [ require.resolve('@umijs/fabric/dist/eslint') ],
   globals: {
     ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true,
     page: true,
     REACT_APP_ENV: true
   },
   rules: {
-    'semi': ['error', 'never'],
-    'no-multiple-empty-lines': [1, { max: 2 }], // 空行最多不能超过2行
-    'comma-dangle': [2, 'never'],
+    'semi': [ 'error', 'never' ],
+    'no-multiple-empty-lines': [ 1, { max: 2 } ],
+    'comma-dangle': [ 2, 'never' ],
     'react/prop-types': 0,
-    'spaced-comment': 'error', // 注释前面必须有空格
-    'array-bracket-spacing': ['error', 'always'],
-    'object-curly-spacing': ['error', 'always']
+    'spaced-comment': 'error',
+    'array-bracket-spacing': [ 'error', 'always' ],
+    'object-curly-spacing': [ 'error', 'always' ]
   }
 }

+ 7 - 7
.prettierrc.js

@@ -1,14 +1,14 @@
-const fabric = require("@umijs/fabric")
+const fabric = require('@umijs/fabric')
 
 module.exports = {
   ...fabric.prettier,
-  eslintIntegration: true,
-  stylelintIntegration: true,
+  eslintIntegration: false,
+  stylelintIntegration: false,
   semi: false,
-  quoteProps: "consistent",
-  htmlWhitespaceSensitivity: "ignore",
+  quoteProps: 'consistent',
+  htmlWhitespaceSensitivity: 'ignore',
   jsxBracketSameLine: true,
-  trailingComma: "none",
+  trailingComma: 'none',
   bracketSpacing: true,
-  arrowParens: "avoid"
+  arrowParens: 'avoid'
 }

+ 11 - 1
src/utils/request.js

@@ -26,7 +26,7 @@ const codeMessage = {
  * 异常处理程序
  */
 
-const errorHandler = (error) => {
+const errorHandler = error => {
   const { response } = error
 
   if (response && response.status) {
@@ -50,8 +50,18 @@ const errorHandler = (error) => {
  */
 
 const request = extend({
+  prefix: '/api',
   errorHandler,
   // 默认错误处理
   credentials: 'include' // 默认请求是否带上cookie
 })
+// 请求前拦截器
+request.interceptors.request.use((url, options) => {
+  console.log(url, options)
+})
+
+request.interceptors.response.use((response, options) => {
+  console.log(response, options)
+})
+
 export default request

+ 1 - 1
src/utils/utils.js

@@ -2,7 +2,7 @@ import { parse } from 'querystring'
 /* eslint no-useless-escape:0 import/prefer-default-export:0 */
 
 const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/
-export const isUrl = (path) => reg.test(path)
+export const isUrl = path => reg.test(path)
 export const isAntDesignPro = () => {
   if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
     return true