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

wepy.app({
  hooks: {
    // App 级别 hook，对整个 App 生效
    // 同时存在 Page hook 和 App hook 时，优先执行 Page hook，返回值再交由 App hook 处
  },
  globalData: {
    statusBarHeight: ''
  },
  onLaunch() {
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.$options.globalData.statusBarHeight = res.statusBarHeight;
      }
    });
    if (!wx.getStorageSync('openId')) {
      wx.login({
        success (res) {
          if (res.code) {
            // 发起网络请求，告诉后端
            http.post('/');
            wx.setStorageSync('wxCode', res.code);
          } else {
            console.log('登录失败！' + res.errMsg);
          }
        }
      });
    }
    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.setStorageSync('onNetworkStatusChange', true);
    wx.onNetworkStatusChange((res) => {
      wx.setStorageSync('onNetworkStatusChange', res.isConnected);
    });
  },
  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>
