<script>
// import { checkUpdate } from '@/utils/check-update';
import { strToParams } from '@/utils/tools';
import { wxMnpLogin } from '@/utils/login'
export default {
  data() {
    return {
      clientid: null,
    };
  },
  onLaunch() {
    this.$store.dispatch('app/getConfit');

    this.$store.dispatch('app/getSys');
    this.$store.dispatch('app/getArticle');

    /* #ifdef MP-WEIXIN */
    // wxMnpLogin()
    /* #endif */

    // #ifdef APP-PLUS
    // const clientInfo = plus.push.getClientInfo()
    // console.log(clientInfo);
    // 锁定竖屏
    plus.screen.lockOrientation('portrait-primary');
    this.Network();
    this.uniPush();
    // checkUpdate();
    // #endif
  },
 onShow(option) {
    console.log(option);
    let invite_code = option.query.invite_code || strToParams(decodeURIComponent(option.query.scene)).invite_code
     uni.setStorageSync('INVITE_CODE',invite_code)
     /* #ifdef MP-WEIXIN */
     wxMnpLogin()
     /* #endif */
  },
  onHide: function () {
    console.log('App Hide');
    // this.bindCode
  },

  methods: {
    // 监听网络变化
    Network() {
      uni.onNetworkStatusChange((res) => {
        if (!res.isConnected) {
          // uni.showToast({
          //   title: '网络已断开，请重新连接',
          //   icon: 'none',
          // });
        }
      });
    },
    uniPush() {
      //监听push推送通知
      plus.push.addEventListener('receive', ({ type, title, content, payload }) => {
        console.log('======receive=====');
        console.log(payload);
        plus.push.setAutoNotification(true);
        if (type == 'receive' || uni.getSystemInfoSync().platform != 'ios') {
          //如果type!='receive'是自己本地插件的push消息栏，“拦截”避免死循环'，安卓系统没有这个问题
          if (typeof payload != 'object') {
            payload = JSON.parse(payload);
          } //判断是否为object，不是的话手动转一下。hbuilderx 3.0以上版本已经修复此问题可省略
          plus.push.createMessage(content, JSON.stringify(payload), {
            title: payload.title,
            subtitle: payload.content,
          });
        }
      });

      //监听点击通知栏
      plus.push.addEventListener('click', ({ payload }) => {
        console.log('======push-click=====');
        console.log(payload);
        if (typeof payload != 'object') {
          payload = JSON.parse(payload);
        }
        if (!!payload.jump_link) {
          let pages = getCurrentPages();
          let currentWebview = pages[pages.length - 1].$getAppWebview();
          const currentRouterPath = `/${currentWebview.__uniapp_route}`;
          if (payload.jump_type == 1) {
            if (currentRouterPath != payload.jump_link) {
              this.$u.route(payload.jump_link);
            }
          } else if (payload.jump_type == 2) {
            this.$u.route(`/pages/web_view/index?url=${payload.jump_link}`);
          }
        }
      });
    },
  },
};
</script>

<style>
@windicss;
</style>
<style lang="scss">
@import 'uview-ui/index.scss';
@import '@/style/index.scss';
</style>
