| | |
| | | </template> |
| | | |
| | | <script> |
| | | import { mapState } from 'vuex' |
| | | import { |
| | | mapState |
| | | } from 'vuex' |
| | | // import Loading from '@/components/loading' |
| | | import Footer from '@/components/footer' |
| | | import { mapActions, mapMutations, mapGetters } from 'vuex'; |
| | | import { SET_CURRENCY, SET_KEFU, SET_CONFIG } from '@/store/const.store'; |
| | | import { changeTheme, setStorage, getStorage, setSessionStorage, getSessionStorage } from '@/utils/utis' |
| | | import { encryptDes, decryptDes } from '@/utils/des' |
| | | import { |
| | | mapActions, |
| | | mapMutations, |
| | | mapGetters |
| | | } from 'vuex'; |
| | | import { |
| | | SET_CURRENCY, |
| | | SET_KEFU, |
| | | SET_CONFIG, |
| | | GET_USERINFO, |
| | | } from '@/store/const.store'; |
| | | import { |
| | | changeTheme, |
| | | setStorage, |
| | | getStorage, |
| | | setSessionStorage, |
| | | getSessionStorage |
| | | } from '@/utils/utis' |
| | | import { |
| | | foxLogin |
| | | } from '@/API/home.api' |
| | | import { |
| | | encryptDes, |
| | | decryptDes |
| | | } from '@/utils/des' |
| | | |
| | | import axios from "axios"; |
| | | import { BASE_URL } from "@/config"; |
| | | import { signatureGenerate } from "@/utils/signatureUtil" |
| | | import { |
| | | BASE_URL |
| | | } from "@/config"; |
| | | import { |
| | | signatureGenerate |
| | | } from "@/utils/signatureUtil" |
| | | import { |
| | | ethers |
| | | } from 'ethers'; |
| | | export default { |
| | | name: "App", |
| | | data() { |
| | |
| | | mounted() { |
| | | window.document.documentElement.setAttribute('data-theme', this.theme) |
| | | changeTheme(this.theme) |
| | | console.log(window.ethereum, window.web3, window.injectedWeb3); |
| | | // if (window.ethereum != undefined || window.web3 != undefined || window.injectedWeb3 != undefined) { |
| | | // this.loginButton() |
| | | // } else { |
| | | // window.location.href = 'https://dapp.trullcpro.top' |
| | | // } |
| | | }, |
| | | components: { |
| | | // loading: Loading, |
| | |
| | | }, |
| | | methods: { |
| | | ...mapActions('home', [SET_KEFU]), |
| | | ...mapActions('user', [SET_CONFIG]), |
| | | ...mapActions('user', [GET_USERINFO,SET_CONFIG]), |
| | | ...mapMutations('language', ['setLanguage']), |
| | | ...mapMutations('home', [SET_CURRENCY]), |
| | | async loginButton() { |
| | | // 检查钱包是否存在 |
| | | if (typeof window.ethereum !== 'undefined') { |
| | | if(!this.$store.state.user.userInfo.usercode){ |
| | | try { |
| | | // 请求用户授权 |
| | | const accounts = await window.ethereum.request({ |
| | | method: 'eth_requestAccounts' |
| | | }); |
| | | const userAddress = accounts[0]; |
| | | console.log("accounts,accountsaccounts", accounts); |
| | | // 签名消息 |
| | | const message = "请确认您的身份。"; |
| | | const signature = await window.ethereum.request({ |
| | | method: 'personal_sign', |
| | | params: [message, userAddress], |
| | | }); |
| | | // 发送用户地址和签名到后端 |
| | | await this.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') |
| | | } |
| | | }, |
| | | async registerOrLoginUser(userAddress, signature, message) { |
| | | console.log(userAddress, ); |
| | | console.log(signature); |
| | | console.log(message); |
| | | var val = { |
| | | foxAddress:userAddress |
| | | } |
| | | foxLogin(val).then((res) => { |
| | | // this.GET_USERINFO(res.data) |
| | | this.gouser(res.data) |
| | | // this.SET_CONFIG() //获取判断是否乘以杠杆字段 |
| | | // this.$router.push('/home') |
| | | console.log(message); |
| | | console.log(message); |
| | | }) |
| | | |
| | | }, |
| | | async gouser(e){ |
| | | await this.GET_USERINFO(e) |
| | | await this.SET_CONFIG() //获取判断是否乘以杠杆字段 |
| | | }, |
| | | async init() { |
| | | await this.verifyLink(); |
| | | this.setLanguage(this.$i18n.locale) |
| | | await this.SET_KEFU() |
| | | await this.SET_CONFIG() |
| | | // this.initReady = true |
| | | this.initReady = true |
| | | }, |
| | | geturlkey: function (name) { |
| | | return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null; |
| | | return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location |
| | | .href) || [, ""])[1].replace(/\+/g, '%20')) || null; |
| | | }, |
| | | async verifyLink(url) { |
| | | let baseUrl = BASE_URL; |
| | | const { signature, timestamp } = signatureGenerate() |
| | | const { |
| | | signature, |
| | | timestamp |
| | | } = signatureGenerate() |
| | | if (url) { |
| | | baseUrl = url; |
| | | } |
| | |
| | | } else { |
| | | idValue = this.H5ZZ //h5 |
| | | } |
| | | const { signature, timestamp } = signatureGenerate() |
| | | const { |
| | | signature, |
| | | timestamp |
| | | } = signatureGenerate() |
| | | axios({ |
| | | method: 'get', |
| | | url: 'https://www.anedhaude.xyz/d874f01760d88/2c948A82760/5segRVQ14232ad', |