From 456d6ed3fb5412575cb7541d3a0a601466d97038 Mon Sep 17 00:00:00 2001
From: songshankun <songshankun@foxmail.com>
Date: 星期一, 13 十一月 2023 16:56:11 +0800
Subject: [PATCH] feat: step组件适配工序过多情况;修复任务少于3条时展示收起按钮的问题
---
src/stores/devices.ts | 49 +++++++++++++++++++++++++++++++++----------------
1 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/src/stores/devices.ts b/src/stores/devices.ts
index a961994..e0f81ef 100644
--- a/src/stores/devices.ts
+++ b/src/stores/devices.ts
@@ -1,23 +1,40 @@
-import { ref, computed } from 'vue'
+import { computed } from 'vue'
import { defineStore } from 'pinia'
-import type { Devices } from '@/api/device'
import { getDeviceList } from '@/api'
+import { useRequest } from 'vue-hooks-plus'
+import type { Devices } from '@/api/device'
+import { DEVICE_INFO_POLLING_DURATION } from '@/common/constants'
-export const useDevicesStore = defineStore('counter', () => {
- const devices = ref<Devices>()
- const deviceIDList = computed(() => devices?.value?.deviceIDList ?? [])
+export const useDevicesStore = defineStore('device', () => {
+ const deviceInfo = computed(() => {
+ return deviceRes?.value?.data as Devices
+ })
- function getDevicesInfo() {
- getDeviceList().then(
- (res) => {
- devices.value = res?.data
- },
- (err) => {
- console.error(err)
- devices.value = undefined
- }
- )
+ // 褰撳墠璁惧鍦ㄧ己灏戝伐鑹哄弬鏁扮殑鏃跺�欐槸鍚﹀厑璁镐笅鍙戠敓浜�
+ const currentDeviceAllowNoParams = computed(() => {
+ const currentDeviceInfo = deviceInfo.value.deviceList?.find((ele) => {
+ return ele.deviceID === deviceInfo.value.currentDeviceID
+ })
+ return !currentDeviceInfo?.needSetProcessParams
+ })
+
+ /**
+ * 濡傛灉浠诲姟鐘舵�佹槸杩涜涓�, 鍒欒疆璇� plc 鍙栬繘搴�
+ */
+ const {
+ data: deviceRes,
+ run: startDevicePolling,
+ cancel: cancelDevicePolling
+ } = useRequest(getDeviceList, {
+ manual: true,
+ pollingInterval: DEVICE_INFO_POLLING_DURATION,
+ pollingWhenHidden: false
+ })
+
+ function startPollingDevice() {
+ cancelDevicePolling()
+ startDevicePolling()
}
- return { devices, deviceIDList, getDevicesInfo }
+ return { deviceInfo, startPollingDevice, currentDeviceAllowNoParams }
})
--
Gitblit v1.8.0