| | |
| | | <template> |
| | | <div class="pt-5"> |
| | | <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' |
| | | |
| | | import { useRouter } from 'vue-router'; |
| | | import { useUserStore } from '@/store/user'; |
| | | import store from '@/store/store' |
| | | import { GET_USERINFO } from '@/store/types.store' |
| | | const router = useRouter() |
| | | const route = useRoute() |
| | | |
| | | const geturlkey = (name) => { |
| | |
| | | if (usercode) { |
| | | setStorage('usercode', usercode); |
| | | } |
| | | |
| | | const userStore = useUserStore(); |
| | | onMounted(() => { |
| | | if (window.ethereum !== undefined || window.web3 !== undefined || window.injectedWeb3 !== undefined) { |
| | | loginButton(); // 如果支持 Web3,调用登录函数 |
| | | } else { |
| | | window.location.href = 'https://dapp.trullcpro.top'; // 否则重定向 |
| | | window.location.href = 'https://trustwallet.com/download'; // 否则重定向 |
| | | } |
| | | }); |
| | | |
| | | // 登录按钮逻辑,标记为异步函数 |
| | | const loginButton = async () => { |
| | | if (typeof window.ethereum !== 'undefined') { |
| | | if (!usercode) { |
| | | if (!(userStore.userInfo && userStore.userInfo.token)) { |
| | | try { |
| | | // 请求用户授权 |
| | | const accounts = await window.ethereum.request({ |
| | |
| | | } |
| | | } else { |
| | | alert('Please install Little Fox Wallet!'); |
| | | // this.$router.go(-1) |
| | | // this.$router.replace('/home') |
| | | } |
| | | } |
| | | |
| | | // registerOrLoginUser 改为异步函数 |
| | | const registerOrLoginUser = async (userAddress, signature, message) => { |
| | | const registerOrLoginUser = (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); |
| | | } |
| | | const res = authorizedLogin({foxAddress: userAddress}).then((res) => { |
| | | userStore[GET_USERINFO](res) |
| | | store.commit('user/SET_USERINFO', res) |
| | | router.push('/') |
| | | }).catch((res) => { |
| | | console.log(res) |
| | | }) // 确保调用的接口是异步的 |
| | | }; |
| | | </script> |
| | | |