Browse Source

wanda-adm:feat >优化打包类型申明文件

shaun-sheep 4 years ago
parent
commit
0ad5d9e9ca
3 changed files with 70 additions and 66 deletions
  1. 1 0
      src/@type/gif/index.d.ts
  2. 27 29
      src/utils/request.ts
  3. 42 37
      tsconfig.json

+ 1 - 0
src/@type/gif/index.d.ts

@@ -0,0 +1 @@
+declare module "*.gif"

+ 27 - 29
src/utils/request.ts

@@ -4,29 +4,27 @@ import { Message, MessageBox } from "element-ui";
 import { UserModule } from "@/store/modules/user";
 
 const service = axios.create({
-  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
+  baseURL: process.env.VUE_APP_BASE_API,
   timeout: 5000
-});
+})
 
 // Request interceptors
-// @ts-ignore
-
 service.interceptors.request.use(
-  (config: { headers: { [x: string]: string } }) => {
+  (config) => {
     // Add X-Access-Token header to every request, you can add other custom headers here
     if (UserModule.token) {
-      config.headers["X-Access-Token"] = UserModule.token;
+      config.headers['X-Access-Token'] = UserModule.token
     }
-    return config;
+    return config
   },
-  (error: any) => {
-    Promise.reject(error);
+  (error) => {
+    Promise.reject(error)
   }
-);
+)
 
 // Response interceptors
 service.interceptors.response.use(
-  (response: { data: any }) => {
+  (response) => {
     // Some example codes here:
     // code == 20000: success
     // code == 50001: invalid access token
@@ -35,40 +33,40 @@ service.interceptors.response.use(
     // code == 50004: invalid user (user not exist)
     // code == 50005: username or password is incorrect
     // You can change this part for your own usage.
-    const res = response.data;
+    const res = response.data
     if (res.code !== 20000) {
       Message({
-        message: res.message || "Error",
-        type: "error",
+        message: res.message || 'Error',
+        type: 'error',
         duration: 5 * 1000
-      });
+      })
       if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
         MessageBox.confirm(
           "你已被登出,可以取消继续留在该页面,或者重新登录",
           "确定登出",
           {
-            confirmButtonText: "重新登录",
-            cancelButtonText: "取消",
-            type: "warning"
+            confirmButtonText: 'Relogin',
+            cancelButtonText: 'Cancel',
+            type: 'warning'
           }
         ).then(() => {
-          UserModule.ResetToken();
-          location.reload(); // To prevent bugs from vue-router
-        });
+          UserModule.ResetToken()
+          location.reload() // To prevent bugs from vue-router
+        })
       }
-      return Promise.reject(new Error(res.message || "Error"));
+      return Promise.reject(new Error(res.message || 'Error'))
     } else {
-      return response.data;
+      return response.data
     }
   },
-  (error: { message: any }) => {
+  (error) => {
     Message({
       message: error.message,
-      type: "error",
+      type: 'error',
       duration: 5 * 1000
-    });
-    return Promise.reject(error);
+    })
+    return Promise.reject(error)
   }
-);
+)
 
-export default service;
+export default service

+ 42 - 37
tsconfig.json

@@ -1,41 +1,46 @@
 {
-  "compilerOptions": {
-    "target": "esnext",
-    "module": "esnext",
-    "strict": true,
-    "jsx": "preserve",
-    "importHelpers": true,
-    "moduleResolution": "node",
-    "experimentalDecorators": true,
-    "esModuleInterop": true,
-    "allowSyntheticDefaultImports": true,
-    "sourceMap": true,
-    "baseUrl": ".",
-    "types": [
-      "node",
-      "jest",
-      "webpack-env"
-    ],
-    "paths": {
-      "@/*": [
-        "src/*"
-      ]
+    "compilerOptions": {
+        "target": "esnext",
+        "module": "esnext",
+        "strict": true,
+        "jsx": "preserve",
+        "importHelpers": true,
+        "moduleResolution": "node",
+        "experimentalDecorators": true,
+        "esModuleInterop": true,
+        "allowSyntheticDefaultImports": true,
+        "sourceMap": true,
+        "baseUrl": ".",
+        "types": [
+            "node",
+            "jest",
+            "webpack-env"
+        ],
+        "typeRoots":  [
+            "node_modules",
+            "src/@types/**/*"
+        ],
+        "paths": {
+            "@/*": [
+                "src/*"
+            ]
+        },
+        "lib": [
+            "esnext",
+            "dom",
+            "dom.iterable",
+            "scripthost"
+        ]
     },
-    "lib": [
-      "esnext",
-      "dom",
-      "dom.iterable",
-      "scripthost"
+    "include": [
+        "src/**/*.ts",
+        "src/**/*.tsx",
+        "src/**/*.vue",
+        "tests/**/*.ts",
+        "tests/**/*.tsx"
+    ],
+    "exclude": [
+        "node_modules",
+        "src/@types/**/*"
     ]
-  },
-  "include": [
-    "src/**/*.ts",
-    "src/**/*.tsx",
-    "src/**/*.vue",
-    "tests/**/*.ts",
-    "tests/**/*.tsx"
-  ],
-  "exclude": [
-    "node_modules"
-  ]
 }