| | |
| | | <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> |
| | |
| | | <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> |
| | |
| | | const logEntry = ref([]); |
| | | const temp = ref({}); |
| | | const controInfo = ref({}); |
| | | // 看是否禁止使用滑动条 |
| | | const flag = ref(false); |
| | | // 定义一个变量来存储定时器ID |
| | | let positionInterval; |
| | | |
| | | // 生命周期钩子 - 相当于 Vue 2 的 onLoad |
| | | onMounted(async () => { |
| | |
| | | } |
| | | }, ); |
| | | |
| | | // 方法 |
| | | 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 |
| | |
| | | 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) => { |
| | |
| | | }) |
| | | } |
| | | // 获取上一次设备的实时控制信息 |
| | | 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; |
| | | }) |
| | | } |