liming 3 settimane fa
parent
commit
96587ba444

+ 5 - 1
.env

@@ -5,4 +5,8 @@
 VITE_DEV_PATH='https://wallet.angeltokens.io' 
 
 # production path
-VITE_PRO_PATH='https://wallet.angeltokens.io'
+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'

+ 2 - 1
src/api/axios.js

@@ -9,8 +9,9 @@ const requestMap = new Map();
 const requestCountMap = new Map(); // 用于记录请求的次数
 
 const isNativeApp = Capacitor.isNativePlatform();
-
+ 
 const axiosInstance = axios.create({
+  // baseURL: import.meta.env.BASE_URL + "/api",
   baseURL: (isNativeApp ? import.meta.env.VITE_PRO_PATH : import.meta.env.VITE_DEV_PATH) + "/api", // 设置 API 基础 URL
   timeout: 300000, // 设置请求超时时间
 });

+ 84 - 0
src/api/axiosImConfig.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_IM_PATH : import.meta.env.VITE_DEV_IM_PATH) + "/api/v1", // 设置 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) => {
+    console.log(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;

+ 7 - 0
src/api/path/im.api.js

@@ -0,0 +1,7 @@
+import service from '../axiosImConfig'
+
+
+// 登录获取用户信息
+export function imLogin(param) {
+  return service.post('user/login', param);
+}

+ 22 - 6
src/common/login.js

@@ -1,4 +1,6 @@
 import { login } from "@/api/path/login.api";
+
+import { imLogin } from "@/api/path/im.api";
 import { userInfo } from '@/api/path/jdfh.api'
 import { useSystemStore } from "@/stores/modules/systemStore";
 
@@ -6,17 +8,31 @@ import { useSystemStore } from "@/stores/modules/systemStore";
 
 const systemStore = useSystemStore();
 export async function sysLogin(address) {
+  
+  const results = await Promise.allSettled([
+    login({ wallet_address: address }),
+    imLogin({ uuid: address })
+  ]);
 
-  const { data, code } = await login({ wallet_address:address }); 
-  if(code !== 1){
-    $msg($t("form.LoginFailed"));
-    return
-  }
+  const loginResult = results[0].value;
+  const imLoginResult = results[1].value;
+
+ 
   systemStore.setStateValue({
     key: "token",
-    value: data.access_token,
+    value: loginResult.data.access_token,
     localStorage: true,
   }) 
+ 
+  systemStore.setStateValue({
+    key: "user_login_information",
+    value: JSON.stringify({
+      nickname: imLoginResult.data.nickname,
+      avatar: imLoginResult.data.avatar,
+    }),
+    localStorage: true,
+  })
+
   // 节点分红---获取用户是否为管理员以及是否加入了白名单
   const res = await userInfo({ address });
   if (res.ret) {

+ 2 - 2
src/views/me/personalInformation/index.vue

@@ -5,10 +5,10 @@
                 round 
                 width="60" 
                 height="60" 
-                src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
+                :src="systemStore.getUserInfo?.avatar"
             />
         </div>
-        <div class="username">{{ systemStore.getUserInfo?.name || "Angel Token"}}</div>
+        <div class="username">{{ systemStore.getUserInfo?.nickname || "Angel Token"}}</div>
         <div class="useraddress">
             <span>0xF3fefE…EcaB</span>
             <svg-icon style="width: 18px; height: 18px;" name="copy" />

+ 9 - 4
vite.config.js

@@ -7,13 +7,12 @@ import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
 import { codeInspectorPlugin } from "code-inspector-plugin";
 import AutoImport from "unplugin-auto-import/vite";
 
-
-
 import { resolve } from "path";
 
 // https://vite.dev/config/
 export default defineConfig(({ mode }) => {
   const env = loadEnv(mode, process.cwd());
+  console.log(env.VITE_PRO_IM_PATH)
   return {
     base: "./",
     plugins: [
@@ -71,11 +70,17 @@ export default defineConfig(({ mode }) => {
       cors: true,
       hmr: true,
       proxy: {
-        "^/api": {
+        "/api/v1": {
+          target: env.VITE_PRO_IM_PATH,
+          changeOrigin: true,
+          secure: true,
+        },
+        "/api": {
           target: env.VITE_PRO_PATH,
           changeOrigin: true,
-          // secure: false,
+          secure: true,
         },
+       
       },
     },
   };