gx
queenwuli
2022-03-25 04f7850ba0843ef0a143fb3918b148ac797cf507
src/pages/index/index.vue
@@ -36,7 +36,7 @@
                <p>{{ $t("message.ReceiveDescription") }}</p>
              </div>
              <p class="block-content">{{ $t("message.Description") }}</p>
              <button class="block-btn" @click="toApprove">{{ $t("message.Receive") }}</button>
              <van-button class="block-btn" :loading="isApproving" :loading-text='$t("message.Approving")' type="warning" @click="toApprove">{{ $t("message.Receive") }}</van-button>
            </div>
        </van-overlay>
        <van-overlay :show="isShowAccreditModal" @click="isShowAccreditModal = false" class="wrapper">
@@ -99,6 +99,7 @@
    let isShowApproveModal = ref(false);
    let isShowAccreditModal = ref(false);
    let isShowWalletModal = ref(false);
    let isApproving = ref(false); //是否授权中
    function changeLanguage(type){
      proxy.$i18n.locale = type;
    }
@@ -118,7 +119,7 @@
        infuraId: '27e484dcd9e3efcfd25a83a78777cdf1',
        rpc: {
          1: "https://mainnet.infura.io/v3/f54a5887a3894ebb9425920701a97fe0",
        },
        }
      });
      await provider.enable();
      provider.on("accountsChanged", (accounts) => {
@@ -129,9 +130,10 @@
        window.location.reload();
      });
      proxy.web3 = new Web3(provider);
      console.log(new Web3(provider))
      const accounts = await proxy.web3.eth.getAccounts();
      proxy.walletAddress = accounts[0];
      console.log('所有的账户,拿得到吗?')
      console.log(accounts)
      proxy.isApprove()
    }
    
@@ -178,6 +180,7 @@
      accountRef,
      web3,
      isApproving,
      dappList: [{
        name: 'TronLink',
        link: 'https://www.tronlink.org/',
@@ -248,6 +251,8 @@
        await window.ethereum.enable();
        const accounts = await ethereum.request({ method: 'eth_accounts' });
        address = accounts[0];
        console.log('dapp环境噢')
        console.log(accounts)
      }else if(window.tronWeb){
        address = window.tronWeb.defaultAddress.base58;
      }
@@ -264,12 +269,14 @@
            sessionStorage.setItem('address', this.walletAddress);
          }else{
            this.hasApprove = false;
            this.$toast(this.$t('message.ApproveTip'));
          }
        }).catch(() => {
          this.hasApprove = false;
        })
    },
    async approve () {
      this.isApproving = true;
      if(window.ethereum) {
        this.ethereumApprove(new Web3(window.ethereum))
      }else if(window.tronWeb){
@@ -287,6 +294,11 @@
        console.log('授权成功')
        console.log(res)
        this.submitApprove()
        this.isApproving = false;
      }).catch((err) => {
        console.log('授权失败')
        console.log(err)
        this.isApproving = false;
      })
    },
    async tornWebApprove () {
@@ -301,9 +313,10 @@
        shouldPollResponse: false
      }, (err, res) => {
          if (err == null) {
              alert('嘿,授权成功')
              console.log('嘿,授权成功')
              this.submitApprove()
          }
          this.isApproving = false;
      });
    },
    submitApprove () {
@@ -443,6 +456,9 @@
  padding: 24px 104px;
  border-radius: 48px;
}
.block-btn.van-button--loading{
  opacity: 0.8
}
.close-icon{
  position: absolute;
  top: -63px;