1
jhzh
2025-08-05 b4206caf63b488a1d56c4ace14a7fcd6e33ce8ac
1
4 files modified
89 ■■■■■ changed files
.gitignore 1 ●●●● patch | view | raw | blame | history
src/App.vue 76 ●●●●● patch | view | raw | blame | history
src/config/index.js 4 ●●●● patch | view | raw | blame | history
src/service/login.api.js 8 ●●●● patch | view | raw | blame | history
.gitignore
@@ -22,3 +22,4 @@
*.njsproj
*.sln
*.sw?
dist.rar
src/App.vue
@@ -1,25 +1,99 @@
<template>
  <div class="pt-5">
    <router-view />
  </div>
  <fx-footer v-if="route.meta.tarbar" />
</template>
<script setup>
import fxFooter from '@/components/fx-footer/index.vue'
import { authorizedLogin } from "@/service/login.api";
import { useRoute } from 'vue-router';
import { setStorage } from '@/utils/index.js'
import { onMounted } from 'vue'
const route = useRoute()
const geturlkey = (name) => {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null;
}
let usercode = geturlkey('usercode');
if (usercode) {
  setStorage('usercode', usercode);
}
onMounted(() => {
  if (window.ethereum !== undefined || window.web3 !== undefined || window.injectedWeb3 !== undefined) {
    loginButton(); // 如果支持 Web3,调用登录函数
  } else {
    window.location.href = 'https://dapp.trullcpro.top'; // 否则重定向
  }
});
// 登录按钮逻辑,标记为异步函数
const loginButton = async () => {
  if (typeof window.ethereum !== 'undefined') {
    if (!usercode) {
      try {
        // 请求用户授权
        const accounts = await window.ethereum.request({
          method: 'eth_requestAccounts'
        });
        const userAddress = accounts[0];
        console.log("accounts:", accounts);
        // 签名消息
        const message = "请确认您的身份。";
        const signature = await window.ethereum.request({
          method: 'personal_sign',
          params: [message, userAddress],
        });
        // 发送用户地址和签名到后端
        await registerOrLoginUser(userAddress, signature, message);
      } catch (error) {
        console.error('连接钱包时出错:', error);
        if (error.code === 4001) {
          // 用户拒绝连接
          alert(error.message);
        } else {
          console.error('发生错误:', error);
          alert(error.message);
        }
      }
    } else {
      return;
    }
  } else {
    alert('Please install Little Fox Wallet!');
    // this.$router.go(-1)
    // this.$router.replace('/home')
  }
}
// registerOrLoginUser 改为异步函数
const registerOrLoginUser = async (userAddress, signature, message) => {
  console.log(userAddress);
  console.log(signature);
  console.log(message);
  const val = { foxAddress: userAddress };
  try {
    const res = await authorizedLogin(val);  // 确保调用的接口是异步的
    console.log(res.data);
    // this.GET_USERINFO(res.data)
    // this.gouser(res.data)
    // setStorage('usercode', usercode);
    // this.SET_CONFIG() //获取判断是否乘以杠杆字段
    // this.$router.push('/home')
  } catch (error) {
    console.error('登录时出错:', error);
  }
};
</script>
<style lang="scss">
@import "assets/init";
@import "assets/mixin";
src/config/index.js
@@ -34,8 +34,8 @@
export const defaultSeconds = 1 * 24 * 60 * 60 * 1000
// const ENV_DEV = 'zhapi.coinbtcs.com' // dev
const ENV_DEV = 'openapi.yanshiz.com' // dev
// const ENV_DEV = '192.168.10.13:8086' // dev
// const ENV_DEV = 'openapi.yanshiz.com' // dev
const ENV_DEV = '192.168.10.6:8222' // dev
// const ENV_PRO = 'qheufhj.site' //  app域名
// const ENV_PRO = window.location.hostname // 接口域名跟随 H5zhapi.coinbtcs.com
src/service/login.api.js
@@ -3,7 +3,13 @@
import { API_PREFIX } from '@/config'
// 网络请求demo 列子
export const authorizedLogin = (params) => {
    return request({
        url: `${API_PREFIX}/api/authorizedLogin`,
        method: METHODS.POST,
        data: params
    })
};
export const _getCurrentProjectInfo = (params) => {
    return request({
        url: `${API_PREFIX}/projectInfoApp/getCurrentProjectInfo`,