| | |
| | | const flag = ref(false); |
| | | // 定义一个变量来存储定时器ID |
| | | let positionInterval; |
| | | // 控制 toast 是否已经显示的标志 |
| | | let toastShown = false; |
| | | |
| | | |
| | | // 生命周期钩子 - 相当于 Vue 2 的 onLoad |
| | | onMounted(async () => { |
| | |
| | | console.error('Failed to fetch device info:', error); |
| | | } |
| | | }, ); |
| | | |
| | | const startGetPosition = () => { |
| | | uni.showLoading({ |
| | | title: "正在操作设备", |
| | | mask: true |
| | | }) |
| | | // 如果定时器已经存在,则先清除它 |
| | | 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来清除定时器 |
| | | uni.hideLoading(); // 隐藏加载框 |
| | | } |
| | | }).catch((error) => { |
| | | console.error('Error fetching control info:', error); // 错误处理 |