<script>
import { useUserStoreWithOut } from '@/store/modules/user'
// #ifdef APP-PLUS
// 实现，路由拦截。当应用无访问摄像头/相册权限，引导跳到设置界面 https://ext.dcloud.net.cn/plugin?id=5095
import interceptorChooseImage from '@/uni_modules/json-interceptor-chooseImage/js_sdk/main.js';
interceptorChooseImage()
// #endif
export default {
  onLaunch: function () {
    const userStore = useUserStoreWithOut()
    if (userStore.isLogin) {
      userStore.fetchUserInfo()
    }
    // #ifdef APP-PLUS
    plus.screen.lockOrientation('portrait-primary')
    if (userStore.isLogin) {
      plus.navigator.closeSplashscreen()
    } else {
      uni.reLaunch({
        url: '/pages/login/index',
        success: () => {
          plus.navigator.closeSplashscreen()
        },
      })
    }
    // #endif
  },
  onShow: function () {
    console.log('App Show')
    // this.isHaveNetwork()
  },
  onHide: function () {
    console.log('App Hide')
  },
  methods: {
    isHaveNetwork() {
      uni.getNetworkType({
        success: (res) => {
          if (res.networkType == 'none') {
            uni.showModal({
              title: '网络不给力~',
              content: '是否重新连接',
              showCancel: true,
              confirmText: '是',
              cancelText: '不了',
              success: (res) => {
                if (res.confirm) {
                  setTimeout(() => {
                    this.isHaveNetwork() //再次判断
                  }, 200)
                }
              },
            })
          }
        },
        fail: (err) => console.error('调用失败'),
        complete: () => {},
      })
    },
  },
}
</script>

<style lang="scss">
@import '@/static/css/index.scss';
@import '@climblee/uv-ui/index.scss';
</style>
