liming 3 周之前
父節點
當前提交
0cd528b833
共有 5 個文件被更改,包括 29 次插入1 次删除
  1. 5 0
      src/api/path/login.api.js
  2. 19 0
      src/common/login.js
  3. 2 0
      src/i18n/zhHk/form.js
  4. 1 0
      src/stores/modules/systemStore.js
  5. 2 1
      src/stores/modules/walletStore.js

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

@@ -9,4 +9,9 @@ export function getNetwork(param) {
 // 获取钱包地址
 export function createAccent(param) {
   return service.post('createAccont', param );
+}
+
+// 登录
+export function login(param) {
+  return service.post('login/walletLogin', param );
 }

+ 19 - 0
src/common/login.js

@@ -0,0 +1,19 @@
+import { login } from "@/api/path/login.api";
+import { useSystemStore } from "@/stores/modules/systemStore";
+
+
+
+const systemStore = useSystemStore();
+export async function sysLogin(address) {
+
+  const { data, code } = await login({ wallet_address:address }); 
+  if(code !== 1){
+    $msg($t("form.LoginFailed"));
+    return
+  }
+  systemStore.setStateValue({
+    key: "token",
+    value: data.access_token,
+    localStorage: true,
+  }) 
+}

+ 2 - 0
src/i18n/zhHk/form.js

@@ -13,4 +13,6 @@ export default {
   PrivateKey:"私鑰",
   MemoryAidWord:"助記詞",
   PleaseFillIn: "請填寫",
+
+  LoginFailed: "登陸失敗",
 };

+ 1 - 0
src/stores/modules/systemStore.js

@@ -7,6 +7,7 @@ export const useSystemStore = defineStore("useSystemStore", {
     local_loading: false,
     routeSate: "",
     user_login_information: "",
+    token: getLocalStorage("token") || "",
     stsClientInfo: {},
   }),
   persist: true,

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

@@ -2,6 +2,7 @@ import { defineStore } from "pinia";
 import Web3 from "web3";
 import CryptoJS from "crypto-js";
 import { cloneDeep } from "lodash";
+import { sysLogin } from "@/common/login.js";
 
 
 export const useWalletStore = defineStore("useWalletStore", {
@@ -90,8 +91,8 @@ export const useWalletStore = defineStore("useWalletStore", {
         this.isAuthenticated = true;
         this.chainId =  `${await web3.eth.getChainId()}n`;
         this.id = `${this.account}@${this.accountName}`
-        await this.getBalance(); 
         this.addWallet()
+        await sysLogin(this.account)
         return {
           address: account.address,
           chainId: this.chainId,