From bc1daf868fae39a05c7b05a114060ab3117cf1fd Mon Sep 17 00:00:00 2001 From: betaqi <3188864257@qq.com> Date: Thu, 18 Sep 2025 17:37:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20[=E6=95=B0=E6=8D=AE=E6=BA=90](=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90=E6=8C=87=E6=A0=87)=20=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useChartDataFetch.hook.ts | 54 +++++++++++-------- .../modules/chartEditStore/chartEditStore.ts | 1 - .../RequestDataSourceConfig/index.vue | 2 +- .../components/data-source-model.vue | 2 +- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/hooks/useChartDataFetch.hook.ts b/src/hooks/useChartDataFetch.hook.ts index b0d2583..9450926 100644 --- a/src/hooks/useChartDataFetch.hook.ts +++ b/src/hooks/useChartDataFetch.hook.ts @@ -2,6 +2,10 @@ import { ref, toRefs, toRaw, watch } from 'vue' import type VChart from 'vue-echarts' import { customizeHttp } from '@/api/http' import { useChartDataPondFetch } from '@/hooks/' +import { + RequestConfigType, + RequestDataSourceConfig +} from '@/store/modules/chartEditStore/chartEditStore.d' import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { RequestAJAXTypes, RequestDataTypeEnum } from '@/enums/httpEnum' @@ -110,21 +114,7 @@ export const useChartDataFetch = ( } } - // 普通初始化与组件交互处理监听 - // 定义一个防抖的函数 - const debouncedFetch = debounce(() => { - clearInterval(fetchInterval) - // 定时时间 - const time = targetInterval && !isNil(targetInterval.value) ? targetInterval.value : globalRequestInterval.value - // 单位 - const unit = targetInterval && !isNil(targetInterval.value) ? targetUnit.value : globalUnit.value - // 开启轮询 - if (time) { - fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit)) - } - fetchFn() - }, 500) // 500ms 后触发,可以按需调整 - + const debouncedFetch = createDebouncedFetch(fetchFn, targetComponent.requestSource) watch( () => targetComponent.request.requestParams, () => { @@ -151,31 +141,51 @@ export const useChartDataFetch = ( requestIntervalUnit: targetUnit, requestInterval: targetInterval } = toRefs(targetComponent.requestSource) - - try { function fetchFn() { - clearInterval(fetchInterval) - console.log(station, devices, points, targetUnit, targetInterval) + console.log(station.value) } - + const debouncedFetch = createDebouncedFetch(fetchFn, targetComponent.requestSource) watch( () => targetComponent.requestSource, () => { - fetchFn() + debouncedFetch() }, { immediate: true, deep: true } ) - } catch (error) { console.log('SourceRequestIntervalFn Error:', error) } + } + function createDebouncedFetch(fetchFn: () => void, targetComponentRequest: RequestConfigType | RequestDataSourceConfig) { + const chartEditStore = useChartEditStore() + const { + requestIntervalUnit: targetUnit, + requestInterval: targetInterval + } = toRefs(targetComponentRequest) + + // 全局数据 + const { + requestOriginUrl, + requestIntervalUnit: globalUnit, + requestInterval: globalRequestInterval + } = toRefs(chartEditStore.getRequestGlobalConfig) + return debounce(() => { + const time = targetInterval && !isNil(targetInterval.value) ? targetInterval.value : globalRequestInterval.value + // // 单位 + const unit = targetInterval && !isNil(targetInterval.value) ? targetUnit.value : globalUnit.value + // // 开启轮询 + if (time) { + fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit)) + } + fetchFn() + }, 500) } if (isPreview()) { diff --git a/src/store/modules/chartEditStore/chartEditStore.ts b/src/store/modules/chartEditStore/chartEditStore.ts index 5507534..1cf322e 100644 --- a/src/store/modules/chartEditStore/chartEditStore.ts +++ b/src/store/modules/chartEditStore/chartEditStore.ts @@ -290,7 +290,6 @@ export const useChartEditStore = defineStore({ loadingFinish() return -1 } - console.log(this) const targetIndex = this.componentList.findIndex(e => e.id === targetId) console.log("测试查找当前ID:",targetIndex) console.log("componentList1:",this.getComponentList) diff --git a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue index c08b33d..614bf7c 100644 --- a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue @@ -57,7 +57,7 @@ 点位: - + diff --git a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/components/data-source-model.vue b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/components/data-source-model.vue index 211fabd..767ef77 100644 --- a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/components/data-source-model.vue +++ b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/components/data-source-model.vue @@ -13,7 +13,7 @@
- +