import {login,getUserInfo} from '/api/user';
App({
  onLaunch() {
    // 登录
    wx.login({
      success: async ret => {
        const res = await login({code:ret.code});
        wx.setStorageSync('token', res.data.token_type + ' ' + res.data.access_token);
        const userRes = await getUserInfo();
        this.globalData.userInfo = {
          ...userRes.data,
          avatar:userRes.data.avatar?userRes.data.avatar:'https://img.yzcdn.cn/vant/cat.jpeg',
          nickname:userRes.data.nickname || userRes.data.username.substring(0,6)
        };
      }
    })
  },
  globalData: {
    userInfo: null,
    programConfig:null
  }
})
