<template>
  <div class=""></div>
</template>


<script>
import config from "@/config"
export default {
  name:'login',
  async mounted () {
      const redirect = encodeURIComponent(config.redirect)
      var state = 'wx_' + Math.random().toString(36).substr(2, 15);
      const scope = 'snsapi_userinfo'
      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${config.appId}&redirect_uri=${redirect}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`
      window.location.href = url
  },
  methods:{
    async initWechatSdk(){
      try{
        const result = await asyncRequest.signature({url:'/login'})
        switch(Number(result.code)){
          case 0:
            wx.config({
               debug: true,
               appId: result.data.appId,
               timestamp: result.data.timestamp,
               nonceStr: result.data.nonceStr,
               signature: result.data.signature,
               jsApiList: ['checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage']
            })

            wx.ready(function(){
              alert('111')
            })
          
            wx.error(function () {
              alert('222')
            })
            break
          default:
            break
        }
      }catch(error){
        console.log(error)
      }
    },
  }
}
</script>
