qingyiay
2023-04-19 3fd84886a15713ece1ba34954f49fd1e075ef7be
pages/tabbar-page/index-tabbar/index-tabbar.vue
@@ -13,7 +13,9 @@
      <driver-index v-if="roleType == 3" ref="driverIndexRef" :indexdriverBillOfLoadingData="indexdriverBillOfLoadingData"></driver-index>
      <tab-bar :current="0"></tab-bar>
      <!-- 推送消息弹窗 -->
      <u-modal :show="messagePushShow" :title="messageList.title" :content="messageList.content" @confirm="messageconfirm"></u-modal>
      <u-modal :show="messagePushShow" :title="messageList.title" @confirm="messageconfirm">
         <view class="slot-content"><rich-text :nodes="messageList.content"></rich-text></view>
      </u-modal>
   </view>
</template>
@@ -122,6 +124,17 @@
      }
      this.userAuthorization();
   },
   onHide() {
      console.log('页面隐藏');
      if (!this.isconnect) {
         this.initWebsocket();
      }
   },
   onUnload() {
      console.log('页面卸载');
      socket.close();
      clearInterval(this.intervalId);
   },
   methods: {
      ...mapMutations(['pushMessage', 'changeWeigh', 'changeinfraredStatus']),
      messagePage() {
@@ -208,10 +221,19 @@
         });
         socket.onOpen(() => {
            console.log('onOpen');
            this.intervalId = setInterval(() => {
               socket.send({
                  data: JSON.stringify({ type: 'ping' }),
                  success(e) {
                     console.log(e, '发送心跳成功');
                  }
         });
            }, 30000);
         });
         // 获取服务器传来的数据,做相应处理
         socket.onMessage(res => {
            console.log('socketWeigh', res);
            console.log('message', res);
            if (res.data.startsWith('weigh')) {
               let nowWeighObj = JSON.parse(res.data.slice(7));
               if (this.globalweighHouseCode && nowWeighObj.eqCode == this.globalweighHouseCode) {
@@ -223,13 +245,16 @@
                     this.changeWeigh(nowWeighObj.weigh);
                  }
               }
            } else {
            } else if (res.data.startsWith('msg')) {
               this.messageList = JSON.parse(res.data.slice(5));
               this.messagePushShow = true;
            } else {
               console.log('websocket还在活着');
            }
         });
         socket.onClose(() => {
            console.log('webSocketClose');
         socket.onClose(e => {
            console.log('webSocketClose', e);
            this.$u.toast('连接已断开,请重新进入该页面,重试!!');
            this.isconnect = false;
         });
         socket.onError(err => {