Browse Source

公告弹窗

xiaodai2017 1 year ago
parent
commit
d0b0a33e02

+ 4 - 2
.env.development

@@ -16,9 +16,11 @@ VITE_APP_ID = "ww6076e6fd4268ee31"
 # 微信开发环境基础重定向url
 REDIRECT_BASE_URL = "http://cxinv.api.caixiao365.com"
 # 开发环境后端用户地址
-VITE_PROXY_USER_REAL = "http://cxinv.api.caixiao365.com"
+VITE_PROXY_USER_REAL1 = "http://user.test241.wanyuhengtong.com"
+# 开发环境后端用户地址
+VITE_PROXY_USER_REAL = "http://stockinv.test241.wanyuhengtong.com"
 # 开发环境后端业务地址
-VITE_PROXY_DOMAIN_REAL = "http://cxinv.api.caixiao365.com"
+VITE_PROXY_DOMAIN_REAL = "http://stockinv.test241.wanyuhengtong.com"
 
 VITE_IS_PROD = true
 

+ 1 - 0
package.json

@@ -61,6 +61,7 @@
     "lodash": "^4.17.21",
     "lodash-es": "^4.17.21",
     "lodash-unified": "^1.0.2",
+    "md5": "^2.3.0",
     "mitt": "^3.0.0",
     "nprogress": "^0.2.0",
     "path": "^0.12.7",

+ 44 - 5
pnpm-lock.yaml

@@ -1,9 +1,5 @@
 lockfileVersion: '6.0'
 
-settings:
-  autoInstallPeers: true
-  excludeLinksFromLockfile: false
-
 dependencies:
   '@amap/amap-jsapi-loader':
     specifier: ^1.0.1
@@ -95,6 +91,9 @@ dependencies:
   lodash-unified:
     specifier: ^1.0.2
     version: 1.0.3(@types/lodash-es@4.17.7)(lodash-es@4.17.21)(lodash@4.17.21)
+  md5:
+    specifier: ^2.3.0
+    version: 2.3.0
   mitt:
     specifier: ^3.0.0
     version: 3.0.0
@@ -267,7 +266,7 @@ devDependencies:
     version: 8.36.0
   eslint-plugin-prettier:
     specifier: ^4.0.0
-    version: 4.2.1(eslint-config-prettier@8.8.0)(eslint@8.36.0)(prettier@2.8.7)
+    version: 4.2.1(eslint@8.36.0)(prettier@2.8.7)
   eslint-plugin-vue:
     specifier: ^8.4.1
     version: 8.7.1(eslint@8.36.0)
@@ -2398,6 +2397,10 @@ packages:
       supports-color: 7.2.0
     dev: true
 
+  /charenc@0.0.2:
+    resolution: {integrity: sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==}
+    dev: false
+
   /china-area-data@5.0.1:
     resolution: {integrity: sha512-BQDPpiv5Nn+018ekcJK2oSD9PAD+E1bvXB0wgabc//dFVS/KvRqCgg0QOEUt3vBkx9XzB5a9BmkJCEZDBxVjVw==}
     dev: false
@@ -2643,6 +2646,10 @@ packages:
       which: 2.0.2
     dev: true
 
+  /crypt@0.0.2:
+    resolution: {integrity: sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==}
+    dev: false
+
   /crypto-js@4.1.1:
     resolution: {integrity: sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==}
     dev: false
@@ -3350,6 +3357,22 @@ packages:
       prettier-linter-helpers: 1.0.0
     dev: true
 
+  /eslint-plugin-prettier@4.2.1(eslint@8.36.0)(prettier@2.8.7):
+    resolution: {integrity: sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==}
+    engines: {node: '>=12.0.0'}
+    peerDependencies:
+      eslint: '>=7.28.0'
+      eslint-config-prettier: '*'
+      prettier: '>=2.0.0'
+    peerDependenciesMeta:
+      eslint-config-prettier:
+        optional: true
+    dependencies:
+      eslint: 8.36.0
+      prettier: 2.8.7
+      prettier-linter-helpers: 1.0.0
+    dev: true
+
   /eslint-plugin-vue@8.7.1(eslint@8.36.0):
     resolution: {integrity: sha512-28sbtm4l4cOzoO1LtzQPxfxhQABararUb1JtqusQqObJpWX2e/gmVyeYVfepizPFne0Q5cILkYGiBoV36L12Wg==}
     engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@@ -4004,6 +4027,10 @@ packages:
       binary-extensions: 2.2.0
     dev: true
 
+  /is-buffer@1.1.6:
+    resolution: {integrity: sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==}
+    dev: false
+
   /is-core-module@2.11.0:
     resolution: {integrity: sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==}
     dependencies:
@@ -4412,6 +4439,14 @@ packages:
     resolution: {integrity: sha512-APMBEanjybaPzUrfqU0IMU5I0AswKMH7k8OTLs0vvV4KZpExkTkY87nR/zpbuTPj+gARop7aGUbl11pnDfW6xg==}
     dev: true
 
+  /md5@2.3.0:
+    resolution: {integrity: sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==}
+    dependencies:
+      charenc: 0.0.2
+      crypt: 0.0.2
+      is-buffer: 1.1.6
+    dev: false
+
   /mdn-data@2.0.14:
     resolution: {integrity: sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==}
     dev: true
@@ -6658,3 +6693,7 @@ packages:
     dependencies:
       tslib: 2.3.0
     dev: false
+
+settings:
+  autoInstallPeers: true
+  excludeLinksFromLockfile: false

+ 2 - 2
src/api/user.ts

@@ -97,6 +97,6 @@ export const httpGetBusiness = (_data: object) => {
   });
 };
 
-export const httpSystemLast = (data: object): any => {
-  return http.request("post", `${yewuApi}systemlast`, { data });
+export const httpSystemList = (data: object): any => {
+  return http.request("post", `${yewuApi}systemlist`, { data });
 };

+ 9 - 0
src/api/user2.ts

@@ -0,0 +1,9 @@
+import { http } from "../utils/http2";
+import { loadEnv } from "@build/index";
+const { VITE_PROXY_USER_REAL1 } = loadEnv();
+const user = VITE_PROXY_USER_REAL1;
+
+// 设置是否查看版本信息
+export const setSystemVer = (data: object) => {
+  return http.request("post", `${user}/setSystemVer`, { data });
+};

+ 123 - 8
src/layout/components/system-notify.vue

@@ -1,14 +1,79 @@
 <script setup lang="ts">
-import { ref, computed, watch } from "vue";
+import { ref, computed, onMounted, watch } from "vue";
+import { httpSystemList } from "/@/api/user";
+import { setSystemVer } from "/@/api/user2";
 import { useUserStoreHook } from "/@/store/modules/user";
+import { resType } from "/@/store/modules/types";
 import dayjs from "dayjs";
-
+const { updateUserVersion } = useUserStoreHook();
 const visible = ref(false);
+const num = ref(0);
+const timer = ref(null);
+const versionList = ref([]);
+const systemInfo = ref({});
+const hasSet = ref(true);
 
-const systemInfo = computed(() => useUserStoreHook().systemInfo);
+async function requsetSystemInfo() {
+  versionList.value = useUserStoreHook().system_version;
+  const { data, code } = await httpSystemList({
+    page: 1,
+    size: 2
+  });
+  if (Number(code) === 0) {
+    const { list } = data;
+    if (list.length === 1) {
+      systemInfo.value = list[0];
+    } else if (list.length === 2) {
+      if (
+        list[0].sys_type === "VER" &&
+        new Date(list[0].addtime).valueOf() > new Date().valueOf()
+      ) {
+        systemInfo.value = list[1];
+      } else {
+        systemInfo.value = list[0];
+      }
+    }
+    if (list.length === 0) {
+      hasSet.value = false;
+    } else {
+      const index = versionList.value.findIndex(
+        si => si === systemInfo.value.version
+      );
+      hasSet.value = index === -1;
+    }
+  } else {
+    throw new Error();
+  }
+}
+onMounted(async () => {
+  await requsetSystemInfo();
+  const { sys_type } = systemInfo.value;
+  if (sys_type === "MSG") return systemMsg();
+  if (sys_type === "VER") return systemVer();
+});
 
 const UPDATE_KEY = "update";
 
+async function dialogClose() {
+  if (num.value !== 0) {
+    return;
+  }
+  if (hasSet.value) {
+    const { version } = systemInfo.value;
+    const { id } = useUserStoreHook().info;
+    setSystemVer({
+      account_id: id,
+      plat_code: "st",
+      system_version: version
+    }).then(async (res: resType) => {
+      const { code, message, data } = res;
+      if (code === 0) {
+        updateUserVersion();
+      }
+    });
+  }
+  visible.value = false;
+}
 function setUpdateCache(updateTime: string) {
   let _update = localStorage.getItem(UPDATE_KEY);
   const update: any = JSON.parse(_update || "[]");
@@ -45,17 +110,59 @@ function systemMsg() {
   }
 }
 
+// watch(
+//   () => systemInfo.value,
+//   ({ sys_type }) => {
+//     if (sys_type === "MSG") return systemMsg();
+//     if (sys_type === "VER") return systemVer();
+//   },
+//   { immediate: true }
+// );
 watch(
-  () => systemInfo.value,
-  ({ sys_type }) => {
-    if (sys_type === "MSG") return systemMsg();
-    if (sys_type === "VER") return systemVer();
+  () => visible.value,
+  async () => {
+    if (visible.value === true) {
+      await requsetSystemInfo();
+      if (hasSet.value) {
+        num.value = 10;
+        timer.value = setInterval(() => {
+          if (num.value > 0) {
+            num.value--;
+          } else {
+            if (timer.value) {
+              clearInterval(timer.value);
+            }
+            // num.value = 10;
+          }
+        }, 1000);
+      }
+      console.log(systemInfo.value);
+    }
   },
   { immediate: true }
 );
+// watch(
+//   () => versionList.value,
+//   () => {
+//     if (versionList.value.length > 0) {
+//       num.value = 10;
+//       timer.value = setInterval(() => {
+//         if (num.value > 0) {
+//           num.value--;
+//         } else {
+//           timer.value = null;
+//           num.value = 10;
+//         }
+//       }, 1000);
+//     }
+//   },
+//   { immediate: true }
+// );
 
 defineExpose({
-  onDisplay: () => (visible.value = true)
+  onDisplay: () => {
+    visible.value = true;
+  }
 });
 </script>
 
@@ -65,7 +172,9 @@ defineExpose({
     title="系统公告"
     center
     width="700px"
+    :before-close="dialogClose"
     :close-on-click-modal="false"
+    :close-on-press-escape="false"
   >
     <ElAlert type="success" center :closable="false">
       <h1 class="font-bold text-center w-full" style="font-size: 16px">
@@ -98,6 +207,12 @@ defineExpose({
         :checked="isCacheUpdate(systemInfo.addtime)"
         @click="() => setUpdateCache(systemInfo.addtime)"
       />
+      <div
+        style="width: 200px; text-align: right; height: 33px; line-height: 33px"
+        v-if="num !== 0"
+      >
+        {{ num }}秒后,可关闭
+      </div>
     </ElRow>
   </ElDialog>
 </template>

+ 1 - 0
src/store/modules/types.ts

@@ -49,6 +49,7 @@ export type userType = {
   companyList: Record<string, string>[];
   currentCompany: Record<string, string> | null;
   isSuperUser: boolean;
+  system_version: string[];
   swithingCompany: boolean;
   info: null | Record<string, string>;
   disabledCompany: boolean;

+ 68 - 6
src/store/modules/user.ts

@@ -20,7 +20,8 @@ import {
   refreshToken,
   httpCompany,
   httpUserInfo,
-  httpSystemLast
+  httpSystemList
+  // setSystemVer
 } from "/@/api/user";
 
 import {
@@ -44,6 +45,7 @@ export const useUserStore = defineStore({
     name: "admin",
     // 前端生成的验证码(按实际需求替换)
     verifyCode: "",
+    system_version: [],
     // 登录显示组件判断 0:登录 1:手机登录 2:二维码登录 3:注册 4:忘记密码,默认0:登录
     currentPage: 0,
     menuActions: getAction(),
@@ -62,7 +64,9 @@ export const useUserStore = defineStore({
     SET_NAME(name) {
       this.name = name;
     },
-
+    SET_VERSION(version) {
+      this.system_version = version;
+    },
     SET_LEVEL(level) {
       this.level = level;
     },
@@ -100,6 +104,27 @@ export const useUserStore = defineStore({
           });
       });
     },
+
+    // async setUserVersion(VERSION) {
+    //   return new Promise((resolve, reject) => {
+    //     setSystemVer({
+    //       account_id: this.info.id,
+    //       plat_code: "cx",
+    //       system_version: VERSION
+    //     })
+    //       .then((res: resType) => {
+    //         const { code, data } = res;
+    //         if (code === 0) {
+    //           resolve(res);
+    //         } else {
+    //           resolve(res);
+    //         }
+    //       })
+    //       .catch(error => {
+    //         reject(error);
+    //       });
+    //   });
+    // },
     async loginByToken(token) {
       setToken(token);
       await this.postMenuList();
@@ -124,6 +149,20 @@ export const useUserStore = defineStore({
           });
       });
     },
+    async updateUserVersion() {
+      const { code, data, message } = await httpUserInfo({
+        noRela: true
+      });
+      this.info = data;
+      if (Number(code) === 0) {
+        const { system_version } = data;
+
+        this.system_version =
+          system_version && system_version.st
+            ? system_version.st.split(",")
+            : [];
+      }
+    },
     async requesetUserInfo() {
       const { code, data, message } = await httpUserInfo({
         noRela: true
@@ -131,12 +170,16 @@ export const useUserStore = defineStore({
 
       this.info = data;
       if (Number(code) === 0) {
-        const { role_level, level } = data;
+        const { role_level, level, system_version } = data;
 
         /** 没有设置过level  */
         if (this.level === "0" || !this.level) {
           this.level = level;
         }
+        this.system_version =
+          system_version && system_version.st
+            ? system_version.st.split(",")
+            : [];
 
         this.isSuperUser = role_level === "1";
 
@@ -180,9 +223,25 @@ export const useUserStore = defineStore({
     },
 
     async requsetSystemInfo() {
-      const { data, code } = await httpSystemLast({});
+      const { data, code } = await httpSystemList({
+        page: 1,
+        size: 2
+      });
       if (Number(code) === 0) {
-        this.systemInfo = data;
+        const { list } = data;
+        console.log(list);
+        if (list.length === 1) {
+          this.systemInfo = list[0];
+        } else if (list.length === 2) {
+          if (
+            list[0].sys_type === "VER" &&
+            new Date(list[0].addtime).valueOf() > new Date().valueOf()
+          ) {
+            this.systemInfo = list[1];
+          } else {
+            this.systemInfo = list[0];
+          }
+        }
       } else {
         throw new Error();
       }
@@ -212,7 +271,10 @@ export const useUserStore = defineStore({
 
               if (!systemList.includes(id)) {
                 res.data = res.data.filter(
-                  ({ menu_name }) => menu_name !== "系统设置" && menu_name !== "业务公司账号权限" && menu_name !== "供应商账号权限"
+                  ({ menu_name }) =>
+                    menu_name !== "系统设置" &&
+                    menu_name !== "业务公司账号权限" &&
+                    menu_name !== "供应商账号权限"
                 );
               }
 

+ 25 - 0
src/utils/http2/README.md

@@ -0,0 +1,25 @@
+## 用法
+
+### Get 请求
+
+```
+import { http } from "/@/utils/http";
+
+// params传参
+http.request('get', '/xxx', { params: param });
+
+// url拼接传参
+http.request('get', '/xxx?message=' + msg);
+```
+
+### Post 请求
+
+```
+import { http } from "/@/utils/http";
+
+// params传参
+http.request('post', '/xxx', { params: param });
+
+// data传参
+http.request('post', '/xxx', { data: param });
+```

+ 232 - 0
src/utils/http2/index.ts

@@ -0,0 +1,232 @@
+import Axios, { AxiosInstance, AxiosRequestConfig } from "axios";
+import qs from "qs";
+import NProgress from "../progress";
+import { getToken, getRelaComNo } from "/@/utils/auth";
+import md5 from "md5";
+import { store } from "/@/store";
+import { trigger } from "/@/plugins/errorHooks/trigger";
+
+import {
+  PureHttpError,
+  RequestMethods,
+  PureHttpResponse,
+  PureHttpRequestConfig
+} from "./types.d";
+import { func } from "vue-types";
+
+function generateRandomString(length) {
+  const str = Math.random()
+    .toString(36)
+    .substring(2, length + 2);
+  return str;
+}
+function aa(): AxiosRequestConfig {
+  const noce = generateRandomString(10);
+  const origin = window.location.origin;
+  const timestamp = new Date().valueOf() + "";
+  const sign = md5(origin + noce + timestamp);
+  const defaultConfig: AxiosRequestConfig = {
+    baseURL: "",
+    timeout: 10000,
+    headers: {
+      Accept: "application/json, text/plain, */*",
+      "Content-Type": "application/json",
+      "X-Requested-With": "XMLHttpRequest",
+      "Web-Auth": "1",
+      Noce: noce,
+      Sign: sign,
+      Timestamp: timestamp
+    },
+    // 数组格式参数序列化
+    paramsSerializer: params => qs.stringify(params, { indices: false })
+  };
+  return defaultConfig;
+}
+// // 相关配置请参考:www.axios-js.com/zh-cn/docs/#axios-request-config-1
+// const defaultConfig: AxiosRequestConfig = {
+//   baseURL: "",
+//   timeout: 10000,
+//   headers: {
+//     Accept: "application/json, text/plain, */*",
+//     "Content-Type": "application/json",
+//     "X-Requested-With": "XMLHttpRequest",
+//     "Web-Auth": "1"
+//   },
+//   // 数组格式参数序列化
+//   paramsSerializer: params => qs.stringify(params, { indices: false })
+// };
+
+class PureHttp {
+  constructor() {
+    this.httpInterceptorsRequest();
+    this.httpInterceptorsResponse();
+  }
+  // 初始化配置对象
+  private static initConfig: PureHttpRequestConfig = {};
+
+  // 保存当前Axios实例对象
+  private static axiosInstance: AxiosInstance = Axios.create(aa());
+
+  // 请求拦截
+  private httpInterceptorsRequest(): void {
+    PureHttp.axiosInstance.interceptors.response.use(response => {
+      const { data } = response;
+      // 在发送请求之前做些什么
+      //  let token = window.vm.$getStorage("token"); // 令牌
+      //  let tid = window.vm.$getStorage("tid"); // 租户id
+      //  let envName = window.vm.$getStorage("envName"); // 环境变量
+      //  let currentOrgId = window.vm.$getStorage("currentOrgId"); // 区域id
+      //  let data = { token, tid, envName, currentOrgId };
+      //  if (!config.data || JSON.stringify(config.data) === "{}") {
+      //    config.data = data;
+      //  } else if (!config.data.hasOwnProperty("currentOrgId")) {
+      //    Object.assign(config.data, data);
+      //  }
+      // config.headers.appId = window.vm.$encrypt(
+      //   "520f066da8e7c4736abb20afdd29289a",
+      //   "TFEUyxO9PDJlyyg7"
+      // );
+      // // 加密
+      // config.headers.Authentication = window.vm.$encrypt(
+      //   "520f066da8e7c4736abb20afdd29289a#nU-#q1PwD!1573801531190",
+      //   "TFEUyxO9PDJlyyg7"
+      // );
+      // 解密
+      // config.headers.Authentication = window.vm.$decrypt(this.parmValue, "TFEUyxO9PDJlyyg7");
+      // console.log(config);
+      // response.headers["web-auth"] = "1";
+
+      console.log(response);
+      const { code, message } = data;
+      //响应code 检查登出
+      if (
+        Number(code) >= 101 &&
+        Number(code) <= 140 &&
+        message !== "账户已禁用"
+      ) {
+        trigger("userLogout");
+      }
+
+      return response;
+    });
+
+    PureHttp.axiosInstance.interceptors.request.use(
+      (config: PureHttpRequestConfig) => {
+        const $config = config;
+        // console.log($config);
+        // 开启进度条动画
+        NProgress.start();
+        // 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
+        if (typeof config.beforeRequestCallback === "function") {
+          config.beforeRequestCallback($config);
+          return $config;
+        }
+        if (PureHttp.initConfig.beforeRequestCallback) {
+          PureHttp.initConfig.beforeRequestCallback($config);
+          return $config;
+        }
+        const token = getToken();
+        const relaComNo = getRelaComNo();
+
+        const isSuper = store.state.value["pure-user"].isSuperUser;
+
+        if (token && config && config.data) {
+          config.data["token"] = token;
+
+          config.data["relaComNo"] = config.data["relaComNo"]
+            ? config.data["relaComNo"]
+            : relaComNo;
+
+          if (config.data["noRela"] || isSuper) {
+            config.data["relaComNo"] = "";
+            delete config.data["noRela"];
+          }
+
+          return $config;
+        } else {
+          return $config;
+        }
+      },
+      error => {
+        return Promise.reject(error);
+      }
+    );
+  }
+
+  // 响应拦截
+  private httpInterceptorsResponse(): void {
+    const instance = PureHttp.axiosInstance;
+    instance.interceptors.response.use(
+      (response: PureHttpResponse) => {
+        const $config = response.config;
+        // 关闭进度条动画
+        NProgress.done();
+        // 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
+        if (typeof $config.beforeResponseCallback === "function") {
+          $config.beforeResponseCallback(response);
+          return response.data;
+        }
+        if (PureHttp.initConfig.beforeResponseCallback) {
+          PureHttp.initConfig.beforeResponseCallback(response);
+          return response.data;
+        }
+        return response.data;
+      },
+      (error: PureHttpError) => {
+        const $error = error;
+        $error.isCancelRequest = Axios.isCancel($error);
+        // 关闭进度条动画
+        NProgress.done();
+        // 所有的响应异常 区分来源为取消请求/非取消请求
+        return Promise.reject($error);
+      }
+    );
+  }
+
+  // 通用请求工具函数
+  public request<T>(
+    method: RequestMethods,
+    url: string,
+    param?: AxiosRequestConfig,
+    axiosConfig?: PureHttpRequestConfig
+  ): Promise<T> {
+    const config = {
+      method,
+      url,
+      ...param,
+      ...axiosConfig
+    } as PureHttpRequestConfig;
+
+    // 单独处理自定义请求/响应回掉
+    return new Promise((resolve, reject) => {
+      PureHttp.axiosInstance
+        .request(config)
+        .then((response: undefined) => {
+          resolve(response);
+        })
+        .catch(error => {
+          reject(error);
+        });
+    });
+  }
+
+  // 单独抽离的post工具函数
+  public post<T, P>(
+    url: string,
+    params?: T,
+    config?: PureHttpRequestConfig
+  ): Promise<P> {
+    return this.request<P>("post", url, params, config);
+  }
+
+  // 单独抽离的get工具函数
+  public get<T, P>(
+    url: string,
+    params?: T,
+    config?: PureHttpRequestConfig
+  ): Promise<P> {
+    return this.request<P>("get", url, params, config);
+  }
+}
+
+export const http = new PureHttp();

+ 47 - 0
src/utils/http2/types.d.ts

@@ -0,0 +1,47 @@
+import Axios, {
+  Method,
+  AxiosError,
+  AxiosResponse,
+  AxiosRequestConfig
+} from "axios";
+
+export type resultType = {
+  accessToken?: string;
+};
+
+export type RequestMethods = Extract<
+  Method,
+  "get" | "post" | "put" | "delete" | "patch" | "option" | "head"
+>;
+
+export interface PureHttpError extends AxiosError {
+  isCancelRequest?: boolean;
+}
+
+export interface PureHttpResponse extends AxiosResponse {
+  config: PureHttpRequestConfig;
+}
+
+export interface PureHttpRequestConfig extends AxiosRequestConfig {
+  beforeRequestCallback?: (request: PureHttpRequestConfig) => void;
+  beforeResponseCallback?: (response: PureHttpResponse) => void;
+}
+
+export default class PureHttp {
+  request<T>(
+    method: RequestMethods,
+    url: string,
+    param?: AxiosRequestConfig,
+    axiosConfig?: PureHttpRequestConfig
+  ): Promise<T>;
+  post<T, P>(
+    url: string,
+    params?: T,
+    config?: PureHttpRequestConfig
+  ): Promise<P>;
+  get<T, P>(
+    url: string,
+    params?: T,
+    config?: PureHttpRequestConfig
+  ): Promise<P>;
+}