<script>
  //#ifdef APP-PLUS
  const jpushModule = uni.requireNativePlugin("JG-JPush");
  // #endif
  import { loginShopAccount, userInfo } from "@/api/oaUser.js"
  export default {
    onLaunch: async function(info) {
      // let noticeArr = []
      // jpushModule.addNotificationListener(res => {
      // 	if (!noticeArr.includes(res.messageID)) {
      // 		const audioContext = uni.createInnerAudioContext()
      // 		// 设置音频文件地址
      // 		audioContext.src = `/static/audio/order.mp3`;
      // 		// console.log(res.messageID)
      // 		audioContext.play()
      // 		noticeArr.push(res.messageID)
      // 		console.log("app的监听")
      // 	}
      // })

      // uni.showModal({
      //   content: info.referrerInfo.extraData
      // })
      
      if (info.referrerInfo?.extraData?.uniMP) {
        uni.setStorageSync('uniMP', info.referrerInfo?.extraData?.uniMP);
        uni.setStorageSync('APP_token', info.referrerInfo?.extraData?.token);
        try{
          let res = await loginShopAccount({
            shop_token: info.referrerInfo?.extraData?.token
          });
          this.$store.commit('SET_USERINFO', {
            user: data,
            token: res.data.token
          })
          this.$store.dispatch('initConfig');
          let {
            data
          } = await userInfo();
          this.$store.commit('setUserInfo', data);
          this.$isResolve()
          // uni.$emit('home_initUserInfo', data);
          return ;
        }catch(e){
          console.log(e);
        }
      }
      console.log('App Launch')
      this.$store.dispatch('initConfig');
      try {
        if (!this.$store.state.app.token) uni.reLaunch({
          url: '/pages/oaLogin/oaLogin'
        })
      } catch (e) {
        uni.reLaunch({
          url: '/pages/oaLogin/oaLogin'
        })
      }
    },
    onShow: function() {
      const audioContext = uni.createInnerAudioContext()
      // 设置音频文件地址
      audioContext.src = '/static/mp3/order.mp3'
      // 播放音频
      //#ifdef APP-PLUS
      jpushModule.addNotificationListener(res => {
        if (res.notificationEventType == 'notificationOpened') return
        audioContext.play()
        uni.vibrateLong();
        console.log("app的监听")
      })
      // #endif
      console.log('App Show')
    },
    onHide: function() {
      console.log('App Hide')
    }
  }
</script>

<style>
  /*每个页面公共css */
  @import "static/css/base.css";
  @import "static/css/style.scss";

  view {
    box-sizing: border-box;
  }
</style>