App.vue 3.94 KB
<script>
  import config from './utils/ip-config';
  export default {
    onLaunch() {
      // #ifdef APP-PLUS
      this.initPush()
      uni.getPushClientId({
        success: (res) => {
          let push_clientid = res.cid
          uni.setStorageSync('clientId', push_clientid)
        },
        fail(err) {
          console.log(err)
        }
      })
      // #endif

      // #ifdef APP-PLUS
      const dom = uni.requireNativePlugin('dom');
      const domModule = uni.requireNativePlugin('dom')
      domModule.addRule('fontFace', {
        'fontFamily': "DingTalk_JinBuTi",
        // 'src': "url('https://store.keliuyun.com/download/app/wechat/DingTalk_JinBuTi.ttf')"
        'src':"url('./static/ttf/DingTalk_JinBuTi.ttf')"
      });
      dom.addRule('fontFace', {
        'fontFamily': "D-DIN-PRO-700-Bold", // 自定义字体名称
        'src':"url('./static/ttf/D-DIN-PRO-700-Bold.otf')"
        // 'src': "url('https://store.keliuyun.com/download/app/wechat/D-DIN-PRO-700-Bold.otf')"
      });
      // #endif

      // #ifdef APP
      // 等待跳转动画结束
      setTimeout(() => {
        // 最长10s关闭启动屏 主动关屏在i18n资源文件中
        plus.navigator.closeSplashscreen()
      }, 10000)
      // #endif
    },
    onShow: function() {
      // #ifdef APP-PLUS
      plus.runtime.setBadgeNumber(-1)
      // #endif
    },
    onHide: function() {
      console.log('App Hide')
    },
    methods: {
      initPush() {
        // 监听推送消息
        uni.onPushMessage((res) => {
          if (res.type === 'click') {
            // 清除app角标数字
            if(res.data.payload && res.data.payload.path){
              uni.navigateTo({
                url: res.data.payload.path
              })
            }
            plus.runtime.setBadgeNumber(0)
            return false
          }
          const pushData = res.data
          uni.createPushMessage({
            title: pushData.title || '',
            content: pushData.content || '',
            payload: pushData.payload || {},
            sound: 'system',
            cover: false,
            badge: 1,
            success: (res) => {
              console.log('本地通知创建成功:', res)
            },
            fail: (err) => {
              console.log('本地通知创建失败:', err)
              // 备用方案:使用 plus.push 创建通知
              if (plus.push) {
                const options = {
                  title: pushData.title || '新消息',
                  content: pushData.content || '您有一条新消息',
                  payload: pushData.payload || {}
                }

                plus.push.createMessage(options.content, options.payload, {
                  title: options.title,
                  cover: false
                })
              }
            }
          })
        })
      },
    }
  }
</script>

<style lang="scss">
  @import "./styles/variable.scss";
  /* #ifndef APP-NVUE */
  @import "./styles/ttf.scss";

  body,
  html {
    // font-family: 'PingFang_Medium';
		// font-family: Helvetica Neue, Helvetica, sans-serif;
    font-family: $font-family-base;
  }

  /* #endif */


  /* #ifndef APP-NVUE */
  view {
    box-sizing: border-box;
		// font-family: Helvetica Neue, Helvetica, sans-serif;
    font-family: $font-family-base;
  }

  /* #endif */
  view {
    // font-family: 'PingFang_Medium';
		// font-family: Helvetica Neue, Helvetica, sans-serif;
    font-family: $font-family-base;
  }

  //导航栏字体
  .uni-page-head .uni-page-head__title {
    font-weight: 700;
  }

  .p-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;

    .p-empty-img {
      width: 560rpx;
      height: 300rpx;
      margin: 0 auto;
    }

    .p-empty-text {
      margin-top: 54rpx;
      font-size: 28rpx;
      color: #90949D;
      text-align: center;
    }

    .chart-text {
      margin-top: 0;
      font-size: 24rpx;
    }
  }
</style>