<script>
import tokenpocketBnb from "@/common/wallet/tokenpocket-wallet/tokenpocket-bnb";
import {login} from "@/api/member";
import tools from "@/common/js/tools";

export default {
  onLaunch: function () {
    console.log("App Launch");
    setTimeout(()=>{
      let bnbObj= tokenpocketBnb.getProvider()
      console.log(bnbObj)
      bnbObj.on('accountsChanged',(accounts)=>{
        console.log('监听成功')
        if(accounts.length<=0){
          uni.reLaunch({
            'url':'pages/index/error?errorType=2'
          })
        }else {
          uni.clearStorageSync()
          this.login(accounts[0])
        }

      })
      bnbObj.on('chainChanged',(chainId)=>{
        if(chainId!=='0x38'){
          uni.reLaunch({
            'url':'pages/index/error?errorType=5'
          })
        }else {
          uni.reLaunch({
            'url':'pages/index/index'
          })
        }
      })
    },5000)

    uni.$on('noBan',()=>{
      console.log(this.$Route)
      if(this.$Route.path!=='/pages/index/error'){
        uni.reLaunch({
          'url':'pages/index/error?errorType=5'
        })
      }

    })
  },
  onShow: function () {
    console.log("App Show");
    uni.reLaunch({
      url: '/pages/login/index'
    })
  },
  onHide: function () {
    uni.clearStorageSync()
    console.log("App Hide");
  },
  methods:{
    login(Address){
      // login({'address':Address}).then((res)=>{
      //   if(res.code===1){
      //     tools.setLoginInfo(res.data)
      //     setTimeout(()=>{
      //       uni.reLaunch({
      //         url: '/pages/index/index'
      //       })
      //     },50)
      //   }else {
      //     uni.reLaunch({
      //       url: 'pages/login/register?address='+Address
      //     })
      //   }
      // })
      uni.reLaunch({
        url: '/pages/login/index'
      })
    }
  }
};
</script>

<style>
/*每个页面公共css */
@import "./common/css/common";
/* icon */
@import "./common/font/iconfont";

checkbox .wx-checkbox-input {
  border-radius: 50% !important;
}
checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  background: linear-gradient(129deg, #f0695b 0%, #ed301d 100%);
  border: 1px solid rgb(239, 74, 57);
  box-shadow: 0px 2px 3px rgba(239, 74, 57, 0.16);
}
uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
  border-color: #d1d1d1;
}
</style>
