<script>
import { go2 } from '@/utils/hook.js'
import { isString } from '@/utils/is.js'
import store from '@/store/index.js'
import handlePushMsg from '@/utils/handlePushMsg.js'
export default {
  onLaunch: function () {
    const token = store.state.qnToken
    let flag = uni.getStorageSync('hasLaunch')
    if (flag && !token) {
      go2('login')
    }
    if (flag && token) {
      go2('client')
    }
    // #ifdef APP-PLUS

    let client = uni.getSystemInfoSync().platform
    setTimeout(() => {
      plus.push.addEventListener(
        'click',
        function (msg) {
          handlePushMsg(msg)
        },
        false
      )
      // 监听在线消息事件
      plus.push.addEventListener(
        'receive',
        function (msg) {
          if (isString(msg.payload)) {
            msg.payload = JSON.parse(msg.payload)
          }
          if (client === 'ios') {
            if (msg.aps == null && msg.type == 'receive') {
              let content = msg.content
              let title = msg.title
              let payload = JSON.stringify(msg.payload)
              plus.push.createMessage(content, payload, {
                title: title,
              })
            }
          }
          if (client === 'android') {
            let title = msg.title
            let content = msg.content
            plus.push.createMessage(content, JSON.stringify(msg.payload), {
              title: title,
            })
          }
        },
        false
      )
    }, 1000)
    // #endif
  },
  onShow: function () {
    // 先默认进入应用就清除所有消息
    plus.runtime.setBadgeNumber(0)
  },
  onHide: function () {},
}
</script>

<style>
/*每个页面公共css */
@import url('./common/css/reset.scss');
@import '@/static/icon/iconfont.css';
page {
  height: 100%;
}
/* uni-dialog标题样式 */
.uni-dialog-title-text {
  font-size: 32rpx !important;
  color: #323233 !important;
  font-weight: 500 !important;
}
</style>
