<template>
  <view>
    <u-loading-page :loading="loading"></u-loading-page>
  </view>
</template>

<script>
import { getWxLoginCode } from '@/api/login';
export default {
  data(){
    return{
      loading:false
    }
  },
  async onLoad(){
    try {
      this.loading = true;
      const wxCode = await getWxLoginCode();
      await this.$store.dispatch('LoginByWxCode', {
        client_id: 'chelvc_client',
        client_secret: 'qWBe6jD%GCuPPTkP',
        grant_type: 'wechat',
        token: wxCode,
      });
      // TODO: 获取用户信息
      // await this.$store.dispatch('GetUserInfo');
      this.$Router.pushTab('/pages/tabbar/home/index')
      this.loading = false
    } catch (error) {
      this.loading = false
      this.$Router.push('/pages/login/index')
      console.log("初始化登录异常",error)
    }
  }
}
</script>
