From 99cd66c835e5befb7ee0f4b95cbeea89f7d423d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E8=B7=91=E7=9A=84=E9=9D=A2=E6=9D=A1?= <1262327911@qq.com> Date: Thu, 15 Dec 2022 20:53:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=AE=9A=E6=97=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/http.ts | 1 - src/hooks/useChartDataFetch.hook.ts | 8 +++---- src/hooks/useChartDataPondFetch.hook.ts | 24 ++++++++++++++++++- .../components/PreviewRenderList/index.vue | 3 ++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/api/http.ts b/src/api/http.ts index 16307d15..a7d8a130 100644 --- a/src/api/http.ts +++ b/src/api/http.ts @@ -116,7 +116,6 @@ export const customizeHttp = (targetParams: RequestConfigType, globalParams: Req if (!targetParams || !globalParams) { return } - // 全局 const { // 全局请求源地址 diff --git a/src/hooks/useChartDataFetch.hook.ts b/src/hooks/useChartDataFetch.hook.ts index 50792971..0138d1b7 100644 --- a/src/hooks/useChartDataFetch.hook.ts +++ b/src/hooks/useChartDataFetch.hook.ts @@ -26,11 +26,10 @@ export const useChartDataFetch = ( // 数据池 const { addGlobalDataInterface } = useChartDataPondFetch() - const { requestDataPondId } = toRefs(targetComponent.request) // 组件类型 const { chartFrame } = targetComponent.chartConfig - + // eCharts 组件配合 vChart 库更新方式 const echartsUpdateHandle = (dataset: any) => { if (chartFrame === ChartFrameEnum.ECHARTS) { @@ -89,7 +88,6 @@ export const useChartDataFetch = ( // 立即调用 fetchFn() - // 定时时间 const time = targetInterval && targetInterval.value ? targetInterval.value : globalRequestInterval.value // 单位 @@ -104,8 +102,8 @@ export const useChartDataFetch = ( } if (isPreview()) { - // 判断是否有数据池对应 id - requestDataPondId + // 判断是否是数据池类型 + targetComponent.request.requestDataType === RequestDataTypeEnum.Pond ? addGlobalDataInterface(targetComponent, useChartEditStore, updateCallback || echartsUpdateHandle) : requestIntervalFn() } diff --git a/src/hooks/useChartDataPondFetch.hook.ts b/src/hooks/useChartDataPondFetch.hook.ts index 7508a161..24ac7660 100644 --- a/src/hooks/useChartDataPondFetch.hook.ts +++ b/src/hooks/useChartDataPondFetch.hook.ts @@ -3,7 +3,7 @@ import { customizeHttp } from '@/api/http' import { CreateComponentType } from '@/packages/index.d' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { RequestGlobalConfigType, RequestDataPondItemType } from '@/store/modules/chartEditStore/chartEditStore.d' -import { newFunctionHandle } from '@/utils' +import { newFunctionHandle, intervalUnitHandle } from '@/utils' // 获取类型 type ChartEditStoreType = typeof useChartEditStore @@ -24,6 +24,9 @@ const newPondItemInterval = ( dataPondMapItem?: DataPondMapType[] ) => { if (!dataPondMapItem) return + let fetchInterval: any = 0 + + clearInterval(fetchInterval) // 请求 const fetchFn = async () => { @@ -48,6 +51,19 @@ const newPondItemInterval = ( // 立即调用 fetchFn() + + const targetInterval = requestDataPondItem.dataPondRequestConfig.requestInterval + const targetUnit = requestDataPondItem.dataPondRequestConfig.requestIntervalUnit + + const globalRequestInterval = requestGlobalConfig.requestInterval + const globalUnit = requestGlobalConfig.requestIntervalUnit + + // 定时时间 + const time = targetInterval ? targetInterval : globalRequestInterval + // 单位 + const unit = targetInterval ? targetUnit : globalUnit + // 开启轮询 + if (time) fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit)) } /** @@ -74,6 +90,11 @@ export const useChartDataPondFetch = () => { mittDataPondMap.set(requestDataPondId, mittPondIdArr) } + // 清除旧数据 + const clearMittDataPondMap = () => { + mittDataPondMap.clear() + } + // 初始化数据池 const initDataPond = (requestGlobalConfig: RequestGlobalConfigType) => { const { requestDataPond } = requestGlobalConfig @@ -88,6 +109,7 @@ export const useChartDataPondFetch = () => { return { addGlobalDataInterface, + clearMittDataPondMap, initDataPond } } diff --git a/src/views/preview/components/PreviewRenderList/index.vue b/src/views/preview/components/PreviewRenderList/index.vue index d4354055..22913e9c 100644 --- a/src/views/preview/components/PreviewRenderList/index.vue +++ b/src/views/preview/components/PreviewRenderList/index.vue @@ -47,7 +47,7 @@ import { getSizeStyle, getComponentAttrStyle, getStatusStyle } from '../../utils import { useLifeHandler } from '@/hooks' // 初始化数据池 -const { initDataPond } = useChartDataPondFetch() +const { initDataPond, clearMittDataPondMap } = useChartDataPondFetch() const props = defineProps({ localStorageInfo: { @@ -69,6 +69,7 @@ const themeColor = computed(() => { }) // 组件渲染结束初始化数据池 +clearMittDataPondMap() onMounted(() => { initDataPond(props.localStorageInfo.requestGlobalConfig) })