From 9e5f4f6acdca2ac91d7ef399527fecfb28ab42e8 Mon Sep 17 00:00:00 2001 From: xy <455640711@qq.com> Date: Wed, 14 Oct 2026 10:41:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=81=A2=E5=A4=8D=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=20CRLF=20=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?=E7=AC=A6=EF=BC=8C=E4=BB=85=E4=BF=9D=E7=95=99=20console.log=20?= =?UTF-8?q?=E5=88=B0=20console.error=20=E7=9A=84=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useChartDataFetch.hook.ts | 260 ++++----- .../components/Charts/Maps/MapBase/index.vue | 536 +++++++++--------- .../components/Charts/Mores/Heatmap/index.vue | 206 +++---- .../Charts/Pies/PieCommon/index.vue | 306 +++++----- src/views/preview/wrapper.vue | 60 +- 5 files changed, 684 insertions(+), 684 deletions(-) diff --git a/src/hooks/useChartDataFetch.hook.ts b/src/hooks/useChartDataFetch.hook.ts index c91895f4..2db9f5fc 100644 --- a/src/hooks/useChartDataFetch.hook.ts +++ b/src/hooks/useChartDataFetch.hook.ts @@ -1,130 +1,130 @@ -import { ref, toRefs, toRaw, watch } from 'vue' -import type VChart from 'vue-echarts' -import { customizeHttp } from '@/api/http' -import { useChartDataPondFetch } from '@/hooks/' -import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' -import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' -import { RequestDataTypeEnum } from '@/enums/httpEnum' -import { isPreview, newFunctionHandle, intervalUnitHandle } from '@/utils' -import { setOption } from '@/packages/public/chart' -import { isNil } from 'lodash' - -// 获取类型 -type ChartEditStoreType = typeof useChartEditStore - -/** - * setdata 数据监听与更改 - * @param targetComponent - * @param useChartEditStore 若直接引会报错,只能动态传递 - * @param updateCallback 自定义更新函数 - */ -export const useChartDataFetch = ( - targetComponent: CreateComponentType, - useChartEditStore: ChartEditStoreType, - updateCallback?: (...args: any) => any -) => { - const vChartRef = ref(null) - let fetchInterval: any = 0 - - // 数据池 - const { addGlobalDataInterface } = useChartDataPondFetch() - - // 组件类型 - const { chartFrame } = targetComponent.chartConfig - - // eCharts 组件配合 vChart 库更新方式 - const echartsUpdateHandle = (dataset: any) => { - if (chartFrame === ChartFrameEnum.ECHARTS) { - if (vChartRef.value) { - setOption(vChartRef.value, { dataset: dataset }, false) - } - } - } - - const requestIntervalFn = () => { - const chartEditStore = useChartEditStore() - - // 全局数据 - const { - requestOriginUrl, - requestIntervalUnit: globalUnit, - requestInterval: globalRequestInterval - } = toRefs(chartEditStore.getRequestGlobalConfig) - - // 目标组件 - const { - requestDataType, - requestUrl, - requestIntervalUnit: targetUnit, - requestInterval: targetInterval - } = toRefs(targetComponent.request) - - // 非请求类型 - if (requestDataType.value !== RequestDataTypeEnum.AJAX) return - - try { - // 处理地址 - // @ts-ignore - if (requestUrl?.value) { - // requestOriginUrl 允许为空 - const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl.value - if (!completePath) return - - clearInterval(fetchInterval) - - const fetchFn = async () => { - const res = await customizeHttp(toRaw(targetComponent.request), toRaw(chartEditStore.getRequestGlobalConfig)) - if (res) { - try { - const filter = targetComponent.filter - const { data } = res - echartsUpdateHandle(newFunctionHandle(data, res, filter)) - // 更新回调函数 - if (updateCallback) { - updateCallback(newFunctionHandle(data, res, filter)) - } - } catch (error) { - console.error(error) - } - } - } - - // 普通初始化与组件交互处理监听 - watch( - () => targetComponent.request.requestParams, - () => { - fetchFn() - }, - { - immediate: true, - deep: true - } - ) - - // 定时时间 - 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)) - } - } - // eslint-disable-next-line no-empty - } catch (error) { - console.error(error) - } - } - - if (isPreview()) { - targetComponent.request.requestDataType === RequestDataTypeEnum.Pond - ? addGlobalDataInterface(targetComponent, useChartEditStore, (newData: any) => { - echartsUpdateHandle(newData) - if (updateCallback) updateCallback(newData) - }) - : requestIntervalFn() - } else { - requestIntervalFn() - } - return { vChartRef } -} +import { ref, toRefs, toRaw, watch } from 'vue' +import type VChart from 'vue-echarts' +import { customizeHttp } from '@/api/http' +import { useChartDataPondFetch } from '@/hooks/' +import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' +import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' +import { RequestDataTypeEnum } from '@/enums/httpEnum' +import { isPreview, newFunctionHandle, intervalUnitHandle } from '@/utils' +import { setOption } from '@/packages/public/chart' +import { isNil } from 'lodash' + +// 获取类型 +type ChartEditStoreType = typeof useChartEditStore + +/** + * setdata 数据监听与更改 + * @param targetComponent + * @param useChartEditStore 若直接引会报错,只能动态传递 + * @param updateCallback 自定义更新函数 + */ +export const useChartDataFetch = ( + targetComponent: CreateComponentType, + useChartEditStore: ChartEditStoreType, + updateCallback?: (...args: any) => any +) => { + const vChartRef = ref(null) + let fetchInterval: any = 0 + + // 数据池 + const { addGlobalDataInterface } = useChartDataPondFetch() + + // 组件类型 + const { chartFrame } = targetComponent.chartConfig + + // eCharts 组件配合 vChart 库更新方式 + const echartsUpdateHandle = (dataset: any) => { + if (chartFrame === ChartFrameEnum.ECHARTS) { + if (vChartRef.value) { + setOption(vChartRef.value, { dataset: dataset }, false) + } + } + } + + const requestIntervalFn = () => { + const chartEditStore = useChartEditStore() + + // 全局数据 + const { + requestOriginUrl, + requestIntervalUnit: globalUnit, + requestInterval: globalRequestInterval + } = toRefs(chartEditStore.getRequestGlobalConfig) + + // 目标组件 + const { + requestDataType, + requestUrl, + requestIntervalUnit: targetUnit, + requestInterval: targetInterval + } = toRefs(targetComponent.request) + + // 非请求类型 + if (requestDataType.value !== RequestDataTypeEnum.AJAX) return + + try { + // 处理地址 + // @ts-ignore + if (requestUrl?.value) { + // requestOriginUrl 允许为空 + const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl.value + if (!completePath) return + + clearInterval(fetchInterval) + + const fetchFn = async () => { + const res = await customizeHttp(toRaw(targetComponent.request), toRaw(chartEditStore.getRequestGlobalConfig)) + if (res) { + try { + const filter = targetComponent.filter + const { data } = res + echartsUpdateHandle(newFunctionHandle(data, res, filter)) + // 更新回调函数 + if (updateCallback) { + updateCallback(newFunctionHandle(data, res, filter)) + } + } catch (error) { + console.error(error) + } + } + } + + // 普通初始化与组件交互处理监听 + watch( + () => targetComponent.request.requestParams, + () => { + fetchFn() + }, + { + immediate: true, + deep: true + } + ) + + // 定时时间 + 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)) + } + } + // eslint-disable-next-line no-empty + } catch (error) { + console.error(error) + } + } + + if (isPreview()) { + targetComponent.request.requestDataType === RequestDataTypeEnum.Pond + ? addGlobalDataInterface(targetComponent, useChartEditStore, (newData: any) => { + echartsUpdateHandle(newData) + if (updateCallback) updateCallback(newData) + }) + : requestIntervalFn() + } else { + requestIntervalFn() + } + return { vChartRef } +} diff --git a/src/packages/components/Charts/Maps/MapBase/index.vue b/src/packages/components/Charts/Maps/MapBase/index.vue index 4dc5367b..d9a337a5 100644 --- a/src/packages/components/Charts/Maps/MapBase/index.vue +++ b/src/packages/components/Charts/Maps/MapBase/index.vue @@ -1,268 +1,268 @@ - - - - - + + + + + diff --git a/src/packages/components/Charts/Mores/Heatmap/index.vue b/src/packages/components/Charts/Mores/Heatmap/index.vue index eb31e49d..77f86192 100644 --- a/src/packages/components/Charts/Mores/Heatmap/index.vue +++ b/src/packages/components/Charts/Mores/Heatmap/index.vue @@ -1,103 +1,103 @@ - - - + + + diff --git a/src/packages/components/Charts/Pies/PieCommon/index.vue b/src/packages/components/Charts/Pies/PieCommon/index.vue index b8149a57..7d79589e 100644 --- a/src/packages/components/Charts/Pies/PieCommon/index.vue +++ b/src/packages/components/Charts/Pies/PieCommon/index.vue @@ -1,153 +1,153 @@ - - - + + + diff --git a/src/views/preview/wrapper.vue b/src/views/preview/wrapper.vue index 48f8e008..5910e520 100644 --- a/src/views/preview/wrapper.vue +++ b/src/views/preview/wrapper.vue @@ -1,30 +1,30 @@ - - - + + +