From d13e470cf0256e3ffbc3b0ad34df27ce0b0b5e5f Mon Sep 17 00:00:00 2001
From: Novecane <2322740715@qq.com>
Date: 星期六, 15 二月 2025 15:08:36 +0800
Subject: [PATCH] second commit

---
 pages/router/deviceInfo/index.vue |   53 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/pages/router/deviceInfo/index.vue b/pages/router/deviceInfo/index.vue
index 519a961..ec08cd8 100644
--- a/pages/router/deviceInfo/index.vue
+++ b/pages/router/deviceInfo/index.vue
@@ -1,7 +1,7 @@
 <template>
 	<view class="container">
 		<view class="info-section">
-			<image src="/assets/test.png" mode="aspectFit" class="device-image"></image>
+			<image src="/assets/device.png" mode="aspectFit" class="device-image"></image>
 			<view class="device-info">
 				<text class="title">{{state.facilityName}}</text>
 				<text class="sn">SN: {{state.facilityCode}}</text>
@@ -24,7 +24,7 @@
 			<slider @change="handleControlChange" min="100" max="200" step="25" active-color="#007aff"
 				:value="controlValue" style="width: 650rpx;
 				 margin-left: 0rpx;
-				 " />
+				 " :disabled="flag" />
 			<view class="scale-labels">
 				<text style="color: #38b231;">开</text>
 				<text>125</text>
@@ -68,6 +68,10 @@
 	const logEntry = ref([]);
 	const temp = ref({});
 	const controInfo = ref({});
+	// 看是否禁止使用滑动条
+	const flag = ref(false);
+	// 定义一个变量来存储定时器ID
+	let positionInterval;
 
 	// 生命周期钩子 - 相当于 Vue 2 的 onLoad
 	onMounted(async () => {
@@ -89,7 +93,35 @@
 		}
 	}, );
 
-	// 方法
+	const startGetPosition = () => {
+		// 如果定时器已经存在,则先清除它
+		if (positionInterval) {
+			clearInterval(positionInterval);
+		}
+		uni.showToast({
+			title:"操作设备中",
+			icon:"loading",
+			mask:true,
+			duration:3500
+		})
+		// 设置定时器
+		positionInterval = setInterval(() => {
+			getControlInfo(state.value.facilityCode).then((res) => {
+				if (res.data.position >= 100) {
+					flag.value = false;
+					clearInterval(positionInterval); // 使用存储的定时器ID来清除定时器
+				}
+			}).catch((error) => {
+				console.error('Error fetching control info:', error); // 错误处理
+				clearInterval(positionInterval); // 如果请求失败,清除定时器
+			});
+		}, 2000);
+	}
+
+
+	/**
+	 * 方法
+	 */
 	const removeSharedDevice = async () => {
 		temp.value = {
 			facilityCode: state.value.facilityCode
@@ -119,11 +151,19 @@
 			destinationPosition: e.detail.value
 		};
 		deviceControlInfo(controInfo.value).then((res) => {
-			//console.log(res);
+			if (res.code === 200) {
+				//  禁止使用滑动条
+				flag.value = true;
+				// 启动定时器
+				startGetPosition();
+			}
 		}).catch((error) => {
 			console.error('Failed to control device:', error);
 		});
+
 	};
+
+
 	//操作记录
 	const getOpeHistory = () => {
 		getOpeInfo(state.value.facilityCode).then((res) => {
@@ -136,9 +176,8 @@
 		})
 	}
 	// 获取上一次设备的实时控制信息
-	const getControlData = ()=>{
-		getControlInfo(state.value.facilityCode).then((res)=>{
-			// console.log(res.data);
+	const getControlData = () => {
+		getControlInfo(state.value.facilityCode).then((res) => {
 			controlValue.value = res.data.position;
 		})
 	}

--
Gitblit v1.9.3