guifei zhu
2024-11-27 6017f46b762663b9393cdae8422e0de1ed3db218
pages/tabBar/general.vue
@@ -11,9 +11,10 @@
       </view>
       
       -->
      <cu-custom bgColor="bg-gradual-blue" :isBack="false">
         <block slot="content">智能中草药干燥设备配套系统</block>
      <cu-custom  bgColor="bg-gradual-blue" :isBack="false">
         <block slot="content">智能中草药</block>
      </cu-custom>
      <mqtt-view  ref="mqttView"></mqtt-view>
      <u-toast ref="uToast"></u-toast>
      <!--       <view class="card-box dynamic shadow cu-list menu">
         <view class="title-box">
@@ -232,7 +233,7 @@
            </view>
            <u-line color="#f1f1f1" margin="15rpx 0 15rpx 0"></u-line>
         </view>
      </view>
      <!-- 
      <view class="page-box" v-show="false">
@@ -277,11 +278,15 @@
            </view>
         </view>
      </view> -->
   </view>
</template>
<script>
   export default {
      data() {
         return {
            list: [{
@@ -353,22 +358,30 @@
      },
      onShow() {
         console.info('onShow')
         uni.showTabBarRedDot({
             index: 2 // 显示第2个tabbar项(索引从0开始)的红点
         });
      },
      mounted() {
      },
      onReady() {
         const userinfo = uni.getStorageSync('userinfo');
         const tenantid = userinfo.loginTenantId
         uni.getSystemInfo({
            success: (res) => {
               let deviceId = res.deviceId
               if (!deviceId) {
                  deviceId = 'mobile-' + tenantid + '-' + Date.parse(new Date())
               }
               uni.setStorageSync(this.$constant.DEVICE_ID, 'mobile-' + tenantid + '-' + res.deviceId);
            }
         })
         this.startConnect();
         this.$refs.mqttView.initMqtt()
         // uni.getSystemInfo({
         //    success: (res) => {
         //       let deviceId = res.deviceId
         //       if (!deviceId) {
         //          deviceId = 'mobile-' + this.tenantId + '-' + Date.parse(new Date())
         //       }
         //       uni.setStorageSync(this.$constant.DEVICE_ID, 'mobile-' + this.tenantId + '-' + res.deviceId);
         //    }
         // })
         // this.startConnect();
@@ -380,7 +393,11 @@
      },
      onLoad() {
      },
      methods: {
         /* 连接MQTT */
         async startConnect() {
            var _this = this
@@ -408,6 +425,14 @@
            //订阅查询设备状态返回数据
            this.$mqttTool.subscribe({
               topic: this.$constant.SERVICE_DOWN + '/' + deviceid + '/#',
               qos: 0
            }).then(res => {
               console.error(res)
            })
            //订阅设备故障广播(广播不在乎客户端id,发送给租户下所有在线的设备)
            this.$mqttTool.subscribe({
               topic: this.$constant.SERVICE_BROADCAST_TENANT_REAL_FAULT.replace('%s', this.tenantId),
               qos: 0
            }).then(res => {
               console.error(res)
@@ -571,6 +596,14 @@
      },
      computed:{
         tenantId(){
            const userinfo = uni.getStorageSync('userinfo');
            const tenantid = userinfo.loginTenantId
            return   tenantid;
         }
      }
   }