liming vor 3 Wochen
Ursprung
Commit
cd108e56a9
6 geänderte Dateien mit 103 neuen und 6 gelöschten Zeilen
  1. 3 1
      .env
  2. 0 0
      src/api/axios.Im.js
  3. 84 0
      src/api/axios.backend.js
  4. 11 0
      src/api/path/backend.api.js
  5. 1 1
      src/api/path/im.api.js
  6. 4 4
      src/views/wallet/index.vue

+ 3 - 1
.env

@@ -9,4 +9,6 @@ VITE_PRO_PATH='https://wallet.angeltokens.io'
 
 
 VITE_PRO_IM_PATH='http://127.0.0.1:8888'
-VITE_DEV_IM_PATH='http://127.0.0.1:8888'
+VITE_DEV_IM_PATH='http://127.0.0.1:8888'
+
+VITE_PRO_BACKEND_PATH='https://backend.angeltoken.net'

+ 0 - 0
src/api/axiosImConfig.js → src/api/axios.Im.js


+ 84 - 0
src/api/axios.backend.js

@@ -0,0 +1,84 @@
+import axios from "axios";
+import { Capacitor } from '@capacitor/core';
+import { showNotify } from 'vant';
+import { useSystemStore } from "@/stores/modules/systemStore";
+import { fn_logout } from "@/utils";
+
+// 用于存储请求和对应的 AbortController
+const requestMap = new Map();
+const requestCountMap = new Map(); // 用于记录请求的次数
+
+const isNativeApp = Capacitor.isNativePlatform();
+ 
+const axiosInstance = axios.create({ 
+  baseURL: (isNativeApp ? import.meta.env.VITE_PRO_BACKEND_PATH : import.meta.env.VITE_PRO_BACKEND_PATH) + "/api/v2", // 设置 API 基础 URL
+  timeout: 300000, // 设置请求超时时间
+});
+
+const requestState = {
+  success: [200],
+  beOverdue: [886],
+  NotAccessRight: [500],
+  exception: [400],
+};
+
+const pathArr = ["/api/admin/system/login", "/api/logout"];
+
+axiosInstance.interceptors.request.use(
+  (config) => { 
+   
+    const systemStore = useSystemStore();
+    systemStore.localLoading(true);
+
+    if (!pathArr.includes(config.url)) {
+      const token = localStorage.getItem("token");
+      if (token && config.headers) {
+        config.headers["Authorization"] = token;
+      }
+    }
+
+    return config;
+  },
+  (err) => {
+    const systemStore = useSystemStore();
+    systemStore.localLoading();
+    return Promise.reject(err);
+  }
+);
+
+// 响应拦截器
+axiosInstance.interceptors.response.use(
+  (res) => {
+    const systemStore = useSystemStore();
+    systemStore.localLoading();
+    const { code, message: msg } = res.data;
+
+
+    if (requestState.NotAccessRight.includes(code)) {
+      showNotify({ type: 'warning', message: msg });
+
+      return Promise.reject(msg);
+    }
+
+    if (requestState.exception.includes(code)) {
+      showNotify({ type: 'warning', message: msg });
+      return Promise.reject(msg);
+    }
+
+    return res.data;
+  },
+  (err) => {
+    const systemStore = useSystemStore();
+    systemStore.localLoading(); 
+    const msg = err.response?.data ? err.response.data.message : "";
+    showNotify({ type: 'warning', message: msg });
+    if (requestState.beOverdue.includes( err.status)) { 
+      // 
+      fn_logout(); 
+      return undefined;
+    }
+    return Promise.reject(err);
+  }
+);
+
+export default axiosInstance;

+ 11 - 0
src/api/path/backend.api.js

@@ -0,0 +1,11 @@
+import service from "../axios.backend";
+
+// 获取交易列表
+export function transactions(account) {
+  return service.get(`addresses/${account}/transactions`);
+}
+
+// 获取代币列表
+export function tokenTransfers(account, param) {
+  return service.get(`addresses/${account}/token-transfers`, { params: param });
+}

+ 1 - 1
src/api/path/im.api.js

@@ -1,4 +1,4 @@
-import service from '../axiosImConfig'
+import service from '../axios.Im'
 
 
 // 登录获取用户信息

+ 4 - 4
src/views/wallet/index.vue

@@ -188,8 +188,8 @@
   import { getNetwork } from '@/api/path/login.api'
   import { useWalletStore } from "@/stores/modules/walletStore";
   import { useSystemStore } from "@/stores/modules/systemStore";
-  
-  import axios from 'axios'
+  import {  transactions, tokenTransfers } from "@/api/path/backend.api";
+
   const router = useRouter();
   const walletStore = useWalletStore();
   const systemStore = useSystemStore();
@@ -233,7 +233,7 @@
     showHistory.value = true;
   }
   const getList = async () => {
-    const res = await axios.get(`https://backend.angeltoken.net/api/v2/addresses/${walletStore.account}/transactions`)
+    const res = await transactions(walletStore.account) 
     if (res.status === 200) {
       const items = res.data.items || []
       if (items.length > 0) {
@@ -249,7 +249,7 @@
     }
   }
   const getDBList = async (DBaddress) => {
-    const res = await axios.get(`https://backend.angeltoken.net/api/v2/addresses/${walletStore.account}/token-transfers`, {
+    const res = await tokenTransfers(walletStore.account,{
       params: {
         type: 'ERC-20,ERC-721,ERC-1155',
         filter: 'to | from',