<style>
  page {
    font-family: 'PingFangSC-Regular';
    width:100%;
    height:100%;
    background-color:#F1F1F1;
  }
</style>
<script>
import wepy from '@wepy/core';
import vuex from '@wepy/x';
import promisify from '@wepy/use-promisify';

import { login } from './common/api';

wepy.use(promisify);
wepy.use(vuex);

wepy.app({
  hooks: {
    // App 级别 hook，对整个 App 生效
    // 同时存在 Page hook 和 App hook 时，优先执行 Page hook，返回值再交由 App hook 处
  },
  globalData: {
    statusBarHeight: ''
  },
  async onLaunch() {
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.$options.globalData.statusBarHeight = res.statusBarHeight;
      }
    });
    wx.setStorageSync('onNetworkStatusChange', true);
    if (!wx.getStorageSync('openId')) {
      const { code } = await wepy.wx.login();
      const userInfo = await login(code);
      wx.setStorageSync('openId', userInfo.openid);
      wx.setStorageSync('isRegister', userInfo.register);
    }
    // wx.checkSession({
    //   success () {
    //     console.log('已登录');
    //     // session_key 未过期，并且在本生命周期一直有效
    //   },
    //   fail () {
    //     // session_key 已经失效，需要重新执行登录流程
    //     wx.login({
    //       success (res) {
    //         if (res.code) {
    //           // 发起网络请求，告诉后端
    //           wx.setStorageSync('wxCode', res.code);
    //         } else {
    //           console.log('登录失败！' + res.errMsg);
    //         }
    //       }
    //     });
    //   }
    // });
    wx.onNetworkStatusChange((res) => {
      console.log('onNetworkStatusChange', res.isConnected);
      wx.setStorageSync('onNetworkStatusChange', res.isConnected);
    });
  },
  onError(e) {
    console.log('onError', e);
  },
  methods: {}
});
</script>
<config>
{
    pages: [
      'pages/index',
      'pages/raffle',
      'pages/prize',
      'pages/myraffles',
      'pages/help',
      'pages/morehelp',
    ],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#f1f1f1',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black'
    }
}
</config>
