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">
@@ -177,7 +178,8 @@
               <view class="flex">
                  <text>中草药</text>
                  <text>丨</text>
                  <text @click="showLongName(showValue(item.herbName))" class="text-cut flex-twice">{{showValue(item.herbName)}}</text>
                  <text @click="showLongName(showValue(item.herbName))"
                     class="text-cut flex-twice">{{showValue(item.herbName)}}</text>
                  <!-- <view class="margin-lr-sm">
                     <u-tag text="报警一次" plain size="mini" type="warning"></u-tag>
                  </view> -->
@@ -231,7 +233,7 @@
            </view>
            <u-line color="#f1f1f1" margin="15rpx 0 15rpx 0"></u-line>
         </view>
      </view>
      <!-- 
      <view class="page-box" v-show="false">
@@ -276,11 +278,15 @@
            </view>
         </view>
      </view> -->
   </view>
</template>
<script>
   export default {
      data() {
         return {
            list: [{
@@ -352,24 +358,122 @@
      },
      onShow() {
         console.info('onShow')
         uni.showTabBarRedDot({
             index: 2 // 显示第2个tabbar项(索引从0开始)的红点
         });
      },
      mounted() {
      },
      onReady() {
         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();
         let month = uni.$u.timeFormat(new Date(), 'yyyy-mm')
         this.getMonth(month)
         let day = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd')
         this.getOrderList(day, day)
         this.getOrderList(day, day);
      },
      methods: {
         showLongName(longName){
               this.$refs.uToast.show({
                  type: 'default',
                  message: longName
               })
      onLoad() {
      },
      methods: {
         /* 连接MQTT */
         async startConnect() {
            var _this = this
            const account = uni.getStorageSync('account');
            const deviceid = uni.getStorageSync(this.$constant.DEVICE_ID);
            if (!account) {
               return false
            }
            let opts = {
               // #ifdef H5
               url: 'ws://' + this.$api.mqttBaseUrl + ':8083/mqtt',
               // #endif
               // #ifdef APP-PLUS
               url: 'wx://' + this.$api.mqttBaseUrl + ':8083/mqtt',
               // #endif
               clientId: deviceid,
               username: account.username,
               password: account.password
            }
            if (!this.$mqttTool.client) {
               var client = await this.$mqttTool.connect(opts);
            }
            //订阅查询设备状态返回数据
            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)
            })
            //订阅发送指令返回结果
            // this.$mqttTool.subscribe({
            //    topic: this.$constant.SERVICE_RES_EQU_CMD,
            //    qos: 0
            // }).then(res => {
            //    console.error(res)
            // })
            // if (!client) {
            //    return false
            // }
            client.on('connect', function(res) {
               console.error('连接成功')
            })
            client.on('reconnect', function(res) {
               console.error('重新连接')
            })
            client.on('error', function(res) {
               console.info('连接错误')
            })
            client.on('close', function(res) {
               console.error('关闭成功')
            })
            client.on('message', function(topic, message, buffer) {
               //console.info(message)
            })
         },
         showLongName(longName) {
            this.$refs.uToast.show({
               type: 'default',
               message: longName
            })
         },
         dayChange(dayInfo) { // 点击日期
            this.model.date = dayInfo.date
@@ -492,6 +596,14 @@
      },
      computed:{
         tenantId(){
            const userinfo = uni.getStorageSync('userinfo');
            const tenantid = userinfo.loginTenantId
            return   tenantid;
         }
      }
   }