liming vor 1 Monat
Ursprung
Commit
36d4dd9ba4

+ 1 - 2
src/api/axios.js

@@ -26,8 +26,7 @@ const requestState = {
 const pathArr = ["/api/admin/system/login", "/api/logout"];
 
 axiosInstance.interceptors.request.use(
-  (config) => {
-    console.log(config)
+  (config) => { 
     const systemStore = useSystemStore();
     systemStore.localLoading(true);
 

+ 2 - 2
src/api/axiosImConfig.js

@@ -25,8 +25,8 @@ const requestState = {
 const pathArr = ["/api/admin/system/login", "/api/logout"];
 
 axiosInstance.interceptors.request.use(
-  (config) => {
-    console.log(config)
+  (config) => { 
+   
     const systemStore = useSystemStore();
     systemStore.localLoading(true);
 

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

@@ -4,4 +4,9 @@ import service from '../axiosImConfig'
 // 登录获取用户信息
 export function imLogin(param) {
   return service.post('user/login', param);
+}
+
+// 上传文件
+export function uploadFile(param) {
+  return service.post('file', param);
 }

+ 23 - 29
src/common/login.js

@@ -1,51 +1,45 @@
 import { login } from "@/api/path/login.api";
 
 import { imLogin } from "@/api/path/im.api";
-import { userInfo } from '@/api/path/jdfh.api'
+import { userInfo } from "@/api/path/jdfh.api";
 import { useSystemStore } from "@/stores/modules/systemStore";
 
+const imgHost = import.meta.env.VITE_PRO_IM_PATH + "/api/v1/file/";
 
-
-const systemStore = useSystemStore();
 export async function sysLogin(address) {
-  
+  const systemStore = useSystemStore();
   const results = await Promise.allSettled([
     login({ wallet_address: address }),
-    imLogin({ uuid: address })
+    imLogin({ uuid: address }),
   ]);
 
   const loginResult = results[0].value;
   const imLoginResult = results[1].value;
 
- 
-  systemStore.setStateValue({
-    key: "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,
-  })
+  systemStore.token = loginResult.data.access_token;
+  systemStore.avatar = imgHost + imLoginResult.data.avatar;
+  systemStore.nickname = imLoginResult.data.nickname;
 
+  console.log(systemStore)
   // 节点分红---获取用户是否为管理员以及是否加入了白名单
   const res = await userInfo({ address });
   if (res.ret) {
     const { is_super, is_white, is_exclusive } = res.data;
     const data = {
-      is_super: typeof is_super === 'boolean' ? is_super : false,
-      is_white: typeof is_white === 'boolean' ? is_white : false,
-      is_exclusive: is_exclusive || false
+      is_super: typeof is_super === "boolean" ? is_super : false,
+      is_white: typeof is_white === "boolean" ? is_white : false,
+      is_exclusive: is_exclusive || false,
     };
-    systemStore.setStateValue({
-      key: "Administrator",
-      value: data,
-      localStorage: true,
-    });
+
+    systemStore.Administrator = data;
+ 
   }
-}
+}
+
+// 更新用户信息
+export async function updateUserInfo(address) {
+  const systemStore = useSystemStore();
+  const res = await imLogin({ uuid: address });
+  systemStore.avatar = imgHost + res.data.avatar;
+  systemStore.nickname = res.data.nickname;
+}

+ 4 - 5
src/i18n/index.js

@@ -1,20 +1,19 @@
 //语言
 import { lang } from "@/settings/designSetting";
-import { createI18n } from "vue-i18n"; //引入vue-i18n组件
-import { useLangStore } from "@/stores/modules/langStore";
+import { createI18n } from "vue-i18n"; //引入vue-i18n组件 
+import {  getLocalStorage } from '@/utils'
 
 
 // 系统语言包
 import zhHkSys from "./zhHk/index";
 import enUsSys  from "./enUs/index"; 
 
-const langStore = useLangStore();
-
+ 
 // 创建i18n实例
 export const i18n = createI18n({
   legacy: false,
   globalInjection: true,
-  locale: langStore?.lang || lang,
+  locale:  getLocalStorage("LANG") || lang,
   messages: {
     "zh-HK": zhHkSys,
     "en-US": enUsSys, 

+ 2 - 4
src/main.js

@@ -23,15 +23,13 @@ import { setup  } from './plugins/storage';
 
 import VConsole from 'vconsole';
 new VConsole();
-
-const app = createApp(App)
-
+ 
 async function appInit() {
   const app = createApp(App);
+  await setupStore(app);
    // 注入组件
   app.component("SvgIcon", SvgIcon); 
   // 挂载状态管理
-  setupStore(app);
   // UI
   app.use(Vant);
   app.use(Lazyload);

+ 2 - 4
src/router/index.js

@@ -1,12 +1,10 @@
-import { pinia } from '@/stores'
+ 
 import { createRouter, createWebHistory } from 'vue-router'
-import { useSystemStore } from '@/stores/modules/systemStore'
 import { systemRoutes } from './system'
 import { whitelistRoutes } from './whitelist'
 import { createRouterGuards } from './router.guards.js'
 
 
-const systemStore = useSystemStore(pinia)
 
 
 const router = createRouter({
@@ -21,7 +19,7 @@ const router = createRouter({
 export async function setupRouter(app) { 
   app.use(router)
   // 创建路由守卫
-  createRouterGuards(router, systemStore)
+  createRouterGuards(router)
 }
 
 export default router;

+ 3 - 0
src/router/router.guards.js

@@ -1,4 +1,7 @@
 
+// import { useSystemStore } from '@/stores/modules/systemStore'
+// const systemStore = useSystemStore()
+
 
 export function createRouterGuards(router, systemStore) {
 

+ 1 - 1
src/stores/index.js

@@ -3,7 +3,7 @@ import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
 
 const pinia = createPinia();
 
-export function setupStore(app) {
+export async function setupStore(app) {
   pinia.use(piniaPluginPersistedstate)
   app.use(pinia);
 }

+ 15 - 17
src/stores/modules/designStore.js

@@ -1,12 +1,10 @@
-import { defineStore } from 'pinia'
-import { theme } from '@/settings/designSetting'
-import { setLocalStorage, getLocalStorage } from '@/utils'
+import { defineStore } from "pinia";
+import { theme } from "@/settings/designSetting";
+import { setLocalStorage, getLocalStorage } from "@/utils";
 // import { useDarkThemeHook } from '@/hooks'
 
-const DESIGN_THEME = "DESIGN_THEME" 
-const storageDesign = getLocalStorage(DESIGN_THEME)
-
-
+const DESIGN_THEME = "DESIGN_THEME";
+const storageDesign = getLocalStorage(DESIGN_THEME);
 
 export const useDesignStore = defineStore("useDesignStore", {
   state: () =>
@@ -14,27 +12,27 @@ export const useDesignStore = defineStore("useDesignStore", {
       // 是否暗黑
       ...theme,
     },
-      persist: true,
+  persist: true,
   getters: {
     getDarkTheme() {
-      return this.darkTheme
+      return this.darkTheme;
     },
     getAppTheme() {
-      return this.appThemeDetail
-    }
+      return this.appThemeDetail;
+    },
   },
   actions: {
     // 切换主题
     changeTheme(e) {
-      this.darkTheme = e
-      setLocalStorage(DESIGN_THEME, this.$state)
+      this.darkTheme = e;
+      setLocalStorage(DESIGN_THEME, this.$state);
       // useDarkThemeHook()
     },
     // 设置主题色
     setStateValue(e) {
-      this.appThemeDetail = e
-      setLocalStorage(DESIGN_THEME, this.$state)
+      this.appThemeDetail = e;
+      setLocalStorage(DESIGN_THEME, this.$state);
       // useDarkThemeHook()
     },
-  }
-})
+  },
+});

+ 1 - 2
src/stores/modules/langStore.js

@@ -14,8 +14,7 @@ export const useLangStore = defineStore("useLangStore",{
     storageLang || {
       lang
     }
-  ),
-  persist: true,
+  ), 
   getters: {
     getLang() {
       return this.lang

+ 73 - 80
src/stores/modules/systemStore.js

@@ -1,17 +1,18 @@
 import { defineStore } from "pinia";
 import { getSTSInfo } from "@/api/path/system.api";
-import { setLocalStorage, getLocalStorage } from "@/utils";
 
 export const useSystemStore = defineStore("useSystemStore", {
   state: () => ({
     local_loading: false,
     routeSate: "",
-    user_login_information: "",
-    token: getLocalStorage("token") || "",
+    avatar: "",
+    nickname: "",
+    token: "",
+    ISCREATE: false,
     stsClientInfo: {},
-    Administrator:{}
+    Administrator: {},
   }),
-  persist: ["stsClientInfo"],
+  persist: true,
   getters: {
     getLocalLoading() {
       return this.local_loading;
@@ -21,91 +22,83 @@ export const useSystemStore = defineStore("useSystemStore", {
       this.token = window.localStorage?.token || "";
       return this.token;
     },
-    getRouteSate() {
-      return this.routeSate || getLocalStorage("routeSate");
-    },
-    getSTSClient() {
-      const stsFn = async () => {
-        const windowVar = window;
-        let longTime = 0;
-        if (
-          windowVar.stsOSSClient &&
-          windowVar.stsOSSClient.stsTokenFreshTime
-        ) {
-          const oldTime = windowVar.stsOSSClient.stsTokenFreshTime.getTime();
-          const newTime = new Date().getTime();
-          longTime = newTime - oldTime;
-        }
 
-        // STS信息
-        if (!windowVar.stsOSSClient || longTime > 10 * 60 * 1000) {
-          const res = await getSTSInfo({});
+    // getSTSClient() {
+    //   const stsFn = async () => {
+    //     const windowVar = window;
+    //     let longTime = 0;
+    //     if (
+    //       windowVar.stsOSSClient &&
+    //       windowVar.stsOSSClient.stsTokenFreshTime
+    //     ) {
+    //       const oldTime = windowVar.stsOSSClient.stsTokenFreshTime.getTime();
+    //       const newTime = new Date().getTime();
+    //       longTime = newTime - oldTime;
+    //     }
 
-          const info = res.data;
-          const systemStore = useSystemStore();
-          const getInfoData = (info) => {
-            const infoData = {
-              endpoint: "https://flexi.oss-cn-hongkong.aliyuncs.com",
-              region: "oss-cn-hongkong",
-              accessKeyId: info.AccessKeyId,
-              accessKeySecret: info.AccessKeySecret,
-              stsToken: info.SecurityToken,
-              bucket: "flexi",
-              cname: true,
-            };
-            this.stsClientInfo = infoData;
-            systemStore.setStateValue("stsClientInfo", infoData);
-            return infoData;
-          };
-          getInfoData(info);
+    //     // STS信息
+    //     if (!windowVar.stsOSSClient || longTime > 10 * 60 * 1000) {
+    //       const res = await getSTSInfo({});
 
-          const client = new windowVar.OSS({
-            ...this.stsClientInfo,
-            refreshSTSToken: async () => {
-              const res = await getSTSInfo({});
-              getInfoData(res.data);
-              return {
-                accessKeyId: info.AccessKeyId,
-                accessKeySecret: info.AccessKeySecret,
-                stsToken: info.SecurityToken,
-              };
-            },
-            refreshSTSTokenInterval: 30 * 60 * 1000,
-          });
+    //       const info = res.data;
+    //       const systemStore = useSystemStore();
+    //       const getInfoData = (info) => {
+    //         const infoData = {
+    //           endpoint: "https://flexi.oss-cn-hongkong.aliyuncs.com",
+    //           region: "oss-cn-hongkong",
+    //           accessKeyId: info.AccessKeyId,
+    //           accessKeySecret: info.AccessKeySecret,
+    //           stsToken: info.SecurityToken,
+    //           bucket: "flexi",
+    //           cname: true,
+    //         };
+    //         this.stsClientInfo = infoData;
+    //         systemStore.setStateValue("stsClientInfo", infoData);
+    //         return infoData;
+    //       };
+    //       getInfoData(info);
 
-          client.putObject = async (data) => {
-            const putRes = await client.put(data.key, data.body);
-            putRes.statusCode = 200;
-            return putRes;
-          };
-          windowVar.stsOSSClient = client;
+    //       const client = new windowVar.OSS({
+    //         ...this.stsClientInfo,
+    //         refreshSTSToken: async () => {
+    //           const res = await getSTSInfo({});
+    //           getInfoData(res.data);
+    //           return {
+    //             accessKeyId: info.AccessKeyId,
+    //             accessKeySecret: info.AccessKeySecret,
+    //             stsToken: info.SecurityToken,
+    //           };
+    //         },
+    //         refreshSTSTokenInterval: 30 * 60 * 1000,
+    //       });
 
-          return client;
-        }
-        return windowVar.stsOSSClient;
-      };
-      return stsFn;
-    },
-    getISCREATE() {
-      return this.ISCREATE || getLocalStorage("ISCREATE");
-    },
-    getUserInfo() {
-      return this.user_login_information || getLocalStorage("user_login_information");
-    },
+    //       client.putObject = async (data) => {
+    //         const putRes = await client.put(data.key, data.body);
+    //         putRes.statusCode = 200;
+    //         return putRes;
+    //       };
+    //       windowVar.stsOSSClient = client;
+
+    //       return client;
+    //     }
+    //     return windowVar.stsOSSClient;
+    //   };
+    //   return stsFn;
+    // },
   },
   actions: {
     localLoading(value = false) {
       this.local_loading = value;
     },
     // 储存
-    setStateValue(res) {
-      this[res.key] = res.value;
-      const value =
-        typeof res.value === "string" ? res.value : JSON.stringify(res.value);
-      if (res.localStorage) {
-        // 此方法只处理了简单数据类型 如字符串(token)、布尔之类的
-        window.localStorage.setItem(res.key, value);
-      }
-    },
+    // setStateValue(res) {
+    //   this[res.key] = res.value;
+    //   const value =
+    //     typeof res.value === "string" ? res.value : JSON.stringify(res.value);
+    //   if (res.localStorage) {
+    //     // 此方法只处理了简单数据类型 如字符串(token)、布尔之类的
+    //     window.localStorage.setItem(res.key, value);
+    //   }
+    // },
   },
 });

+ 2 - 0
src/stores/modules/walletStore.js

@@ -6,6 +6,8 @@ import { sysLogin } from "@/common/login.js";
 import { showNotify } from 'vant';
 import router from '@/router/index'
 import { hotTokens } from '@/api/path/login.api'
+
+
 export const useWalletStore = defineStore("useWalletStore", {
   state: () => ({
     id: "", // name + @ + account

+ 3 - 6
src/views/login/index.vue

@@ -72,12 +72,9 @@ const changeImport = () => {
 const evAgree = ()=>{
   goTo();
 }
-const goTo = () => {
-  systemStore.setStateValue({
-    key: "ISCREATE",
-    value: isCreate.value,
-    localStorage: true,
-  });
+const goTo = () => { 
+  systemStore.ISCREATE = isCreate.value; 
+  systemStore.$persist()
   // 如果是第一次登录,需要选择网络
   if(isFirst){
     router.push({

+ 1 - 1
src/views/login/selectNetwork/index.vue

@@ -53,7 +53,7 @@ const selectNetwork = (item) => {
   walletStore.accountIcon = item.icon
   walletStore.rpcUrl = item.url
   router.push({
-    path: systemStore.getISCREATE?'/createWallet':'/importMethod',
+    path: systemStore.ISCREATE?'/createWallet':'/importMethod',
   })
 }
 

+ 15 - 4
src/views/me/personalInformation/index.vue

@@ -5,10 +5,10 @@
                 round 
                 width="60" 
                 height="60" 
-                :src="systemStore.getUserInfo?.avatar"
+                :src="systemStore.avatar"
             />
         </div>
-        <div class="username">{{ systemStore.getUserInfo?.nickname || "Angel Token"}}</div>
+        <div class="username">{{ systemStore.nickname || "Angel Token"}}</div>
         <div class="useraddress">
             <span>0xF3fefE…EcaB</span>
             <svg-icon style="width: 18px; height: 18px;" name="copy" />
@@ -46,14 +46,25 @@
 import { userInfoEdit } from "@/api/path/user.api"
 import QrcodeVue from 'qrcode.vue'
 import { useSystemStore  } from "@/stores/modules/systemStore";
+import { useWalletStore  } from "@/stores/modules/walletStore"
+import { uploadFile } from "@/api/path/im.api"
+import { updateUserInfo } from "@/common/login"
 
 const systemStore = useSystemStore();
+const walletStore = useWalletStore()
 
 const show = ref(false);
 const nickname = ref('');
 const qrtext = ref('');
-const afterRead = () => {
-    console.log("afterRead")
+ 
+const afterRead = async (file) => {
+    const formData = new FormData();
+    formData.append('uuid', walletStore.account);
+    formData.append('file', file.file);
+    const { code, data} = await uploadFile(formData)
+    if (code === 200) {
+      await updateUserInfo(walletStore.account)
+    }
 }
 
 const updateUserName = async () => {