From 6017f46b762663b9393cdae8422e0de1ed3db218 Mon Sep 17 00:00:00 2001
From: guifei zhu <guifeizhu@guifeideiMac.local>
Date: 星期三, 27 十一月 2024 13:30:06 +0800
Subject: [PATCH] 添加mqtt数据接口

---
 pages/tabBar/general.vue |  137 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 124 insertions(+), 13 deletions(-)

diff --git a/pages/tabBar/general.vue b/pages/tabBar/general.vue
index ec2c61e..4dd41df 100644
--- a/pages/tabBar/general.vue
+++ b/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,25 +358,122 @@
 		},
 		onShow() {
 			console.info('onShow')
+			uni.showTabBarRedDot({
+			    index: 2 // 鏄剧ず绗�2涓猼abbar椤癸紙绱㈠紩浠�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)
+				})
+ 
+				//璁㈤槄璁惧鏁呴殰骞挎挱锛堝箍鎾笉鍦ㄤ箮瀹㈡埛绔痠d锛屽彂閫佺粰绉熸埛涓嬫墍鏈夊湪绾跨殑璁惧锛�
+				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
@@ -493,6 +596,14 @@
 
 
 
+		},
+		computed:{
+			tenantId(){
+				const userinfo = uni.getStorageSync('userinfo');
+				const tenantid = userinfo.loginTenantId
+				return   tenantid;
+			}
+			
 		}
 
 	}

--
Gitblit v1.9.3