<script>
import Vue from 'vue'
import { changeNetworkType } from 'common/utils/changeData.js'
import { NO_NETWORK_TEXT } from 'common/utils/systemConst.js'
export default {
  onLaunch: function () {
    // 这里是设置宽度高度的
    uni.getSystemInfo({
      success: function (e) {
        Vue.prototype.windowHeight = e.windowHeight
        Vue.prototype.windowWidth = e.windowWidth
        Vue.prototype.platform = e.platform
        // #ifndef MP
        Vue.prototype.StatusBar = e.statusBarHeight
        if (e.platform === 'android') {
          Vue.prototype.globalCustomBarHeight = e.statusBarHeight + 50
        } else {
          Vue.prototype.globalCustomBarHeight = e.statusBarHeight + 45
        }
        // #endif

        // #ifdef MP-WEIXIN
        Vue.prototype.StatusBar = e.statusBarHeight
        // eslint-disable-next-line no-undef
        const custom = wx.getMenuButtonBoundingClientRect()
        Vue.prototype.Custom = custom
        Vue.prototype.globalCustomBarHeight = custom.bottom + custom.top - e.statusBarHeight
        // #endif

        // #ifdef MP-ALIPAY
        Vue.prototype.StatusBar = e.statusBarHeight
        Vue.prototype.globalCustomBarHeight = e.statusBarHeight + e.titleBarHeight
        // #endif
      }
    })
    // app 初始化数据
    this.$store.dispatch('initAppData')
  },
  onShow: function () {
    // 监听网络 start
    if (!this.networkListenFlag || this.networkListenFlag === false) {
      uni.onNetworkStatusChange(res => {
        Vue.prototype.networkListenFlag = true // 监听网络变化注册成功，无需重复注册
        this.changeNetworkType(this.$store, res.networkType)
        if (res.networkType === 'none') {
          uni.showToast({
            title: NO_NETWORK_TEXT,
            icon: 'none'
          })
        }
      })
    }

    // 监听网络 end
    // 查看网络类型
    // wifi  wifi 网络
    // 2g  2g 网络
    // 3g  3g 网络
    // 4g  4g 网络
    // ethernet  有线网络  App
    // unknown  Android 下不常见的网络类型
    // none  无网络
    uni.getNetworkType({
      success: res => {
        this.changeNetworkType(this.$store, res.networkType)
        if (res.networkType === 'none') {
          uni.showToast({
            title: NO_NETWORK_TEXT,
            icon: 'none'
          })
        }
      }
    })
  },
  onHide: function () {
    console.log('App Hide')
  },
  methods: {
    changeNetworkType
  }
}
</script>

<style>
@import '/common/colorui/main.css';
@import '/common/colorui/icon.css';
/* @import "/common/colorui/animation.css"; */
@import '/common/css/common.css';
</style>
