From 30a9deaee708856860e244f9602e314af7984a36 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: Sat, 12 Nov 2022 15:37:41 +0800 Subject: [PATCH 01/22] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BB=B6=E7=9A=84=E9=85=8D=E7=BD=AE=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E6=B7=B1=E6=8B=B7=E8=B4=9D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/components/Charts/Lines/LineCommon/config.ts | 3 ++- .../components/Charts/Lines/LineGradientSingle/config.ts | 3 ++- src/packages/components/Charts/Lines/LineGradients/config.ts | 3 ++- .../components/Charts/Lines/LineLinearSingle/config.ts | 3 ++- src/packages/components/Charts/Maps/MapBase/config.ts | 3 ++- src/packages/components/Charts/Pies/PieCircle/config.ts | 3 ++- src/packages/components/Charts/Pies/PieCommon/config.ts | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/packages/components/Charts/Lines/LineCommon/config.ts b/src/packages/components/Charts/Lines/LineCommon/config.ts index 5b275ba0..917a5064 100644 --- a/src/packages/components/Charts/Lines/LineCommon/config.ts +++ b/src/packages/components/Charts/Lines/LineCommon/config.ts @@ -2,6 +2,7 @@ import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public' import { LineCommonConfig } from './index' import { CreateComponentType } from '@/packages/index.d' import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index' +import cloneDeep from 'lodash/cloneDeep' import dataJson from './data.json' export const includes = ['legend', 'xAxis', 'yAxis', 'grid'] @@ -47,7 +48,7 @@ export const option = { export default class Config extends PublicConfigClass implements CreateComponentType { public key: string = LineCommonConfig.key - public chartConfig = LineCommonConfig + public chartConfig = cloneDeep(LineCommonConfig) // 图表配置项 public option = echartOptionProfixHandle(option, includes) } diff --git a/src/packages/components/Charts/Lines/LineGradientSingle/config.ts b/src/packages/components/Charts/Lines/LineGradientSingle/config.ts index dea1397a..592b704d 100644 --- a/src/packages/components/Charts/Lines/LineGradientSingle/config.ts +++ b/src/packages/components/Charts/Lines/LineGradientSingle/config.ts @@ -3,6 +3,7 @@ import { LineGradientSingleConfig } from './index' import { CreateComponentType } from '@/packages/index.d' import { graphic } from 'echarts/core' import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index' +import cloneDeep from 'lodash/cloneDeep' import dataJson from './data.json' export const includes = ['legend', 'xAxis', 'yAxis', 'grid'] @@ -58,7 +59,7 @@ const options = { export default class Config extends PublicConfigClass implements CreateComponentType { public key: string = LineGradientSingleConfig.key - public chartConfig = LineGradientSingleConfig + public chartConfig = cloneDeep(LineGradientSingleConfig) // 图表配置项 public option = echartOptionProfixHandle(options, includes) } diff --git a/src/packages/components/Charts/Lines/LineGradients/config.ts b/src/packages/components/Charts/Lines/LineGradients/config.ts index 2037ce5f..d470bab5 100644 --- a/src/packages/components/Charts/Lines/LineGradients/config.ts +++ b/src/packages/components/Charts/Lines/LineGradients/config.ts @@ -3,6 +3,7 @@ import { LineGradientsConfig } from './index' import { CreateComponentType } from '@/packages/index.d' import { graphic } from 'echarts/core' import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index' +import cloneDeep from 'lodash/cloneDeep' import dataJson from './data.json' export const includes = ['legend', 'xAxis', 'yAxis', 'grid'] @@ -85,7 +86,7 @@ const option = { export default class Config extends PublicConfigClass implements CreateComponentType { public key: string = LineGradientsConfig.key - public chartConfig = LineGradientsConfig + public chartConfig = cloneDeep(LineGradientsConfig) // 图表配置项 public option = echartOptionProfixHandle(option, includes) } diff --git a/src/packages/components/Charts/Lines/LineLinearSingle/config.ts b/src/packages/components/Charts/Lines/LineLinearSingle/config.ts index fbeb875f..abcb2a31 100644 --- a/src/packages/components/Charts/Lines/LineLinearSingle/config.ts +++ b/src/packages/components/Charts/Lines/LineLinearSingle/config.ts @@ -2,6 +2,7 @@ import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public' import { LineLinearSingleConfig } from './index' import { CreateComponentType } from '@/packages/index.d' import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index' +import cloneDeep from 'lodash/cloneDeep' import dataJson from './data.json' export const includes = ['legend', 'xAxis', 'yAxis', 'grid'] @@ -54,7 +55,7 @@ export const option = { export default class Config extends PublicConfigClass implements CreateComponentType { public key: string = LineLinearSingleConfig.key - public chartConfig = LineLinearSingleConfig + public chartConfig = cloneDeep(LineLinearSingleConfig) // 图表配置项 public option = echartOptionProfixHandle(option, includes) } diff --git a/src/packages/components/Charts/Maps/MapBase/config.ts b/src/packages/components/Charts/Maps/MapBase/config.ts index 36663256..888fe6b7 100644 --- a/src/packages/components/Charts/Maps/MapBase/config.ts +++ b/src/packages/components/Charts/Maps/MapBase/config.ts @@ -2,6 +2,7 @@ import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public' import { MapBaseConfig } from './index' import { chartInitConfig } from '@/settings/designSetting' import { CreateComponentType } from '@/packages/index.d' +import cloneDeep from 'lodash/cloneDeep' import dataJson from './data.json' export const includes = [] @@ -151,6 +152,6 @@ export const MapDefaultConfig = { ...option } export default class Config extends PublicConfigClass implements CreateComponentType { public key: string = MapBaseConfig.key public attr = { ...chartInitConfig, w: 750, h: 800, zIndex: -1 } - public chartConfig = MapBaseConfig + public chartConfig = cloneDeep(MapBaseConfig) public option = echartOptionProfixHandle(option, includes) } diff --git a/src/packages/components/Charts/Pies/PieCircle/config.ts b/src/packages/components/Charts/Pies/PieCircle/config.ts index 15954a3d..cbee4975 100644 --- a/src/packages/components/Charts/Pies/PieCircle/config.ts +++ b/src/packages/components/Charts/Pies/PieCircle/config.ts @@ -1,6 +1,7 @@ import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public' import { PieCircleConfig } from './index' import { CreateComponentType } from '@/packages/index.d' +import cloneDeep from 'lodash/cloneDeep' export const includes = [] @@ -57,7 +58,7 @@ const option = { export default class Config extends PublicConfigClass implements CreateComponentType { public key: string = PieCircleConfig.key - public chartConfig = PieCircleConfig + public chartConfig = cloneDeep(PieCircleConfig) // 图表配置项 public option = echartOptionProfixHandle(option, includes) diff --git a/src/packages/components/Charts/Pies/PieCommon/config.ts b/src/packages/components/Charts/Pies/PieCommon/config.ts index 1af07f40..068450b6 100644 --- a/src/packages/components/Charts/Pies/PieCommon/config.ts +++ b/src/packages/components/Charts/Pies/PieCommon/config.ts @@ -1,6 +1,7 @@ import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public' import { PieCommonConfig } from './index' import { CreateComponentType } from '@/packages/index.d' +import cloneDeep from 'lodash/cloneDeep' import dataJson from './data.json' export const includes = ['legend'] @@ -61,7 +62,7 @@ const option = { export default class Config extends PublicConfigClass implements CreateComponentType { public key: string = PieCommonConfig.key - public chartConfig = PieCommonConfig + public chartConfig = cloneDeep(PieCommonConfig) // 图表配置项 public option = echartOptionProfixHandle(option, includes) From fce514c4909bd2ad9a3d0858aa219e6da2a40b33 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: Sat, 12 Nov 2022 16:10:14 +0800 Subject: [PATCH 02/22] =?UTF-8?q?chore:=20=E8=BD=AC=E7=A7=BBmaster-fetch?= =?UTF-8?q?=E5=88=86=E6=94=AF=E8=8E=B7=E5=8F=96id=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=88=B0dev=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/router.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/utils/router.ts b/src/utils/router.ts index f2bf6142..f2a9c696 100644 --- a/src/utils/router.ts +++ b/src/utils/router.ts @@ -153,6 +153,19 @@ export const fetchRouteParams = () => { } } +/** + * * 通过硬解析获取当前路由下的参数 + * @returns object + */ + export const fetchRouteParamsLocation = () => { + try { + return document.location.hash.split('/').pop() || '' + } catch (error) { + window['$message'].warning('查询路由信息失败,请联系管理员!') + return '' + } +} + /** * * 回到主页面 * @param confirm From f6bad1513b3042e51459273dad44d44758531948 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: Sat, 12 Nov 2022 16:16:03 +0800 Subject: [PATCH 03/22] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=8E=B7?= =?UTF-8?q?=E5=8F=96id=20=E7=9A=84=E6=97=A7=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/chart/ContentEdit/components/EditTools/index.vue | 5 ++--- src/views/chart/ContentHeader/headerTitle/index.vue | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/views/chart/ContentEdit/components/EditTools/index.vue b/src/views/chart/ContentEdit/components/EditTools/index.vue index 9c5627ea..4bb39d79 100644 --- a/src/views/chart/ContentEdit/components/EditTools/index.vue +++ b/src/views/chart/ContentEdit/components/EditTools/index.vue @@ -66,7 +66,7 @@ import { ref, computed, h, watch } from 'vue' import { useSettingStore } from '@/store/modules/settingStore/settingStore' import { ToolsStatusEnum } from '@/store/modules/settingStore/settingStore.d' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' -import { fetchPathByName, routerTurnByPath, setSessionStorage, getLocalStorage } from '@/utils' +import { fetchRouteParamsLocation, fetchPathByName, routerTurnByPath, setSessionStorage, getLocalStorage } from '@/utils' import { editToJsonInterval } from '@/settings/designSetting' import { EditEnum, ChartEnum } from '@/enums/pageEnum' import { StorageEnum } from '@/enums/storageEnum' @@ -143,8 +143,7 @@ const editHandle = () => { // 获取id路径 const path = fetchPathByName(EditEnum.CHART_EDIT_NAME, 'href') if (!path) return - let { id } = routerParamsInfo.params as any - id = typeof id === 'string' ? id : id[0] + const id = fetchRouteParamsLocation() updateToSession(id) routerTurnByPath(path, [id], undefined, true) }, 1000) diff --git a/src/views/chart/ContentHeader/headerTitle/index.vue b/src/views/chart/ContentHeader/headerTitle/index.vue index 5ac70dc8..6d0d4eae 100644 --- a/src/views/chart/ContentHeader/headerTitle/index.vue +++ b/src/views/chart/ContentHeader/headerTitle/index.vue @@ -30,7 +30,7 @@ diff --git a/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEventBaseHandle/index.ts b/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEventBaseHandle/index.ts new file mode 100644 index 00000000..d45f2f12 --- /dev/null +++ b/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEventBaseHandle/index.ts @@ -0,0 +1,3 @@ +import ChartEventBaseHandle from './index.vue' + +export { ChartEventBaseHandle } diff --git a/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEventBaseHandle/index.vue b/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEventBaseHandle/index.vue new file mode 100644 index 00000000..bfe0157f --- /dev/null +++ b/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEventBaseHandle/index.vue @@ -0,0 +1,214 @@ + + + + + diff --git a/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEventMonacoEditor/index.ts b/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEventMonacoEditor/index.ts deleted file mode 100644 index b6d23e30..00000000 --- a/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEventMonacoEditor/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import ChartEventMonacoEditor from './index.vue' - -export { ChartEventMonacoEditor } diff --git a/src/views/chart/ContentConfigurations/components/ChartEvent/components/index.scss b/src/views/chart/ContentConfigurations/components/ChartEvent/components/index.scss new file mode 100644 index 00000000..8cd67cf8 --- /dev/null +++ b/src/views/chart/ContentConfigurations/components/ChartEvent/components/index.scss @@ -0,0 +1,51 @@ +/* 外层也要使用 */ +.func-keyword { + color: #b478cf; +} + +.func-annotate { + color: #70c0e8; +} + +@include go('chart-data-monaco-editor') { + .func-keyNameWord { + color: #70c0e8; + } + .tab-tip { + font-size: 12px; + } + &.n-card.n-modal, + .n-card { + @extend .go-background-filter; + } +} +@include deep() { + .n-layout, + .n-layout-sider { + background-color: transparent; + } + .collapse-show-box { + .n-card__content { + padding-left: 20px; + padding-right: 10px; + } + } + .go-editor-area { + max-height: 530px; + } + .checkbox--hidden:checked { + & + label { + .n-icon { + transition: all 0.3s; + transform: rotate(180deg); + } + } + & ~ .go-editor-area { + display: none; + } + } + // 优化代码换行 + .n-code > pre { + white-space: break-spaces; + } +} diff --git a/src/views/chart/ContentConfigurations/components/ChartEvent/index.vue b/src/views/chart/ContentConfigurations/components/ChartEvent/index.vue index a5335f5e..05e5ce4d 100644 --- a/src/views/chart/ContentConfigurations/components/ChartEvent/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartEvent/index.vue @@ -5,20 +5,15 @@ 组件 id: {{ targetData.id }} - -
- 【单击、双击、移入、移出】在开发中,即将上线! -
- (备注:高级事件模块可自行实现上述功能) -
-
- + + \ No newline at end of file + diff --git a/src/views/chart/ContentLayers/index.vue b/src/views/chart/ContentLayers/index.vue index 0576ab24..4f5895d2 100644 --- a/src/views/chart/ContentLayers/index.vue +++ b/src/views/chart/ContentLayers/index.vue @@ -81,12 +81,13 @@ import { LayersGroupListItem } from './components/LayersGroupListItem/index' import { icon } from '@/plugins' const { LayersIcon, GridIcon, ListIcon } = icon.ionicons5 +const { LaptopIcon } = icon.carbon const chartLayoutStore = useChartLayoutStore() const chartEditStore = useChartEditStore() const { handleContextMenu, onClickOutSide } = useContextMenu() const layerModeList = [ - { label: '缩略图', icon: GridIcon, value: LayerModeEnum.THUMBNAIL }, + { label: '缩略图', icon: LaptopIcon, value: LayerModeEnum.THUMBNAIL }, { label: '文本列表', icon: ListIcon, value: LayerModeEnum.TEXT } ] From 8c089b800aafa0e965ad6b88e49107ef69eb6c41 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: Sun, 13 Nov 2022 21:38:46 +0800 Subject: [PATCH 10/22] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E6=A0=B7=E5=BC=8Fwenti?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/chart/ContentCharts/components/ChartsItemBox/index.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/chart/ContentCharts/components/ChartsItemBox/index.vue b/src/views/chart/ContentCharts/components/ChartsItemBox/index.vue index 80552c4a..e87e0bf6 100644 --- a/src/views/chart/ContentCharts/components/ChartsItemBox/index.vue +++ b/src/views/chart/ContentCharts/components/ChartsItemBox/index.vue @@ -104,6 +104,7 @@ $halfCenterHeight: 50px; @include go('content-charts-item-box') { display: flex; flex-wrap: wrap; + justify-content: space-between; gap: 9px; padding: 10px; .item-box { From 48f00e44f6773c6c7a5f3cb1878942457dda995e 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: Tue, 15 Nov 2022 21:25:35 +0800 Subject: [PATCH 11/22] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=B1=A0=20hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/index.ts | 1 + src/hooks/useChartDataFetch.hook.ts | 35 ++++--- src/hooks/useChartDataPondFetch.hook.ts | 93 +++++++++++++++++++ .../chartEditStore/chartEditStore.d.ts | 11 +++ .../modules/chartEditStore/chartEditStore.ts | 1 + .../components/ChartDataAjax/index.vue | 2 +- .../ChartDataMonacoEditor/index.vue | 2 +- .../components/PreviewRenderList/index.vue | 13 ++- 8 files changed, 143 insertions(+), 15 deletions(-) create mode 100644 src/hooks/useChartDataPondFetch.hook.ts diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 5ecfe3dd..b5ab7ef8 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -2,5 +2,6 @@ export * from '@/hooks/useTheme.hook' export * from '@/hooks/usePreviewScale.hook' export * from '@/hooks/useCode.hook' export * from '@/hooks/useChartDataFetch.hook' +export * from '@/hooks/useChartDataPondFetch.hook' export * from '@/hooks/useLifeHandler.hook' export * from '@/hooks/useLang.hook' \ No newline at end of file diff --git a/src/hooks/useChartDataFetch.hook.ts b/src/hooks/useChartDataFetch.hook.ts index df48ae16..1c96c301 100644 --- a/src/hooks/useChartDataFetch.hook.ts +++ b/src/hooks/useChartDataFetch.hook.ts @@ -1,6 +1,7 @@ import { ref, toRefs, toRaw } 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' @@ -23,6 +24,22 @@ export const useChartDataFetch = ( const vChartRef = ref(null) let fetchInterval: any = 0 + // 数据池 + const { addGlobalDataInterface } = useChartDataPondFetch() + const { requestDataPondId } = toRefs(targetComponent.request) + + // 组件类型 + const { chartFrame } = targetComponent.chartConfig + + // eCharts 组件配合 vChart 库更新方式 + const echartsUpdateHandle = (dataset: any) => { + if (chartFrame === ChartFrameEnum.ECHARTS) { + if (vChartRef.value) { + vChartRef.value.setOption({ dataset: dataset }) + } + } + } + const requestIntervalFn = () => { const chartEditStore = useChartEditStore() @@ -41,9 +58,6 @@ export const useChartDataFetch = ( requestInterval: targetInterval } = toRefs(targetComponent.request) - // 组件类型 - const { chartFrame } = targetComponent.chartConfig - // 非请求类型 if (requestDataType.value !== RequestDataTypeEnum.AJAX) return @@ -58,16 +72,11 @@ export const useChartDataFetch = ( clearInterval(fetchInterval) const fetchFn = async () => { - const res = await customizeHttp(toRaw(targetComponent.request), toRaw(chartEditStore.requestGlobalConfig)) + const res = await customizeHttp(toRaw(targetComponent.request), toRaw(chartEditStore.getRequestGlobalConfig)) if (res) { try { const filter = targetComponent.filter - // eCharts 组件配合 vChart 库更新方式 - if (chartFrame === ChartFrameEnum.ECHARTS) { - if (vChartRef.value) { - vChartRef.value.setOption({ dataset: newFunctionHandle(res?.data, res, filter) }) - } - } + echartsUpdateHandle(newFunctionHandle(res?.data, res, filter)) // 更新回调函数 if (updateCallback) { updateCallback(newFunctionHandle(res?.data, res, filter)) @@ -94,6 +103,10 @@ export const useChartDataFetch = ( } } - isPreview() && requestIntervalFn() + if (isPreview()) { + requestDataPondId + ? addGlobalDataInterface(targetComponent, useChartEditStore, updateCallback || echartsUpdateHandle) + : requestIntervalFn() + } return { vChartRef } } diff --git a/src/hooks/useChartDataPondFetch.hook.ts b/src/hooks/useChartDataPondFetch.hook.ts new file mode 100644 index 00000000..2126384b --- /dev/null +++ b/src/hooks/useChartDataPondFetch.hook.ts @@ -0,0 +1,93 @@ +import { toRaw } from 'vue' +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' + +// 获取类型 +type ChartEditStoreType = typeof useChartEditStore + +// 数据池存储的数据类型 +type DataPondMapType = { + updateCallback: (...args: any) => any + filter?: string | undefined +} + +// 数据池 Map 中请求对应 callback +const mittDataPondMap = new Map() + +// 创建单个数据项轮询接口 +const newPondItemInterval = ( + requestGlobalConfig: RequestGlobalConfigType, + requestDataPondItem: RequestDataPondItemType, + dataPondMapItem?: DataPondMapType[] +) => { + if (!dataPondMapItem) return + + // 请求 + const fetchFn = async () => { + try { + const res = await customizeHttp(toRaw(requestDataPondItem.dataPondRequestConfig), toRaw(requestGlobalConfig)) + + if (res) { + try { + // 遍历更新回调函数 + dataPondMapItem.forEach(item => { + item.updateCallback(newFunctionHandle(res?.data, res, item.filter)) + }) + } catch (error) { + console.error(error) + return error + } + } + } catch (error) { + return error + } + } + + // 立即调用 + fetchFn() +} + +/** + * 数据池接口处理 + */ +export const useChartDataPondFetch = () => { + // 新增全局接口 + const addGlobalDataInterface = ( + targetComponent: CreateComponentType, + useChartEditStore: ChartEditStoreType, + updateCallback: (...args: any) => any + ) => { + const chartEditStore = useChartEditStore() + const { requestDataPond } = chartEditStore.getRequestGlobalConfig + + // 组件对应的数据池 Id + const requestDataPondId = '111' || (targetComponent.request.requestDataPondId as string) + // 新增数据项 + const mittPondIdArr = mittDataPondMap.get(requestDataPondId) || [] + mittPondIdArr.push({ + updateCallback: updateCallback, + filter: targetComponent.filter + }) + mittDataPondMap.set(requestDataPondId, mittPondIdArr) + } + + // 初始化数据池 + const initDataPond = (requestGlobalConfig: RequestGlobalConfigType) => { + const { requestDataPond } = requestGlobalConfig + // 根据 mapId 查找对应的数据池配置 + for (let pondKey of mittDataPondMap.keys()) { + const requestDataPondItem = requestDataPond.find(item => item.dataPondId === pondKey) + if (requestDataPondItem) { + newPondItemInterval(requestGlobalConfig, requestDataPondItem, mittDataPondMap.get(pondKey)) + } + } + } + + return { + addGlobalDataInterface, + initDataPond + } +} diff --git a/src/store/modules/chartEditStore/chartEditStore.d.ts b/src/store/modules/chartEditStore/chartEditStore.d.ts index 4d0232cb..78927f70 100644 --- a/src/store/modules/chartEditStore/chartEditStore.d.ts +++ b/src/store/modules/chartEditStore/chartEditStore.d.ts @@ -150,16 +150,27 @@ type RequestPublicConfigType = { requestParams: RequestParams } +// 数据池项类型 +export type RequestDataPondItemType = { + dataPondId: string, + dataPondName: string, + dataPondRequestConfig: RequestConfigType +} + // 全局的图表请求配置 export interface RequestGlobalConfigType extends RequestPublicConfigType { // 组件定制轮询时间 requestInterval: number // 请求源地址 requestOriginUrl?: string + // 公共数据池 + requestDataPond: RequestDataPondItemType[] } // 单个图表请求配置 export interface RequestConfigType extends RequestPublicConfigType { + // 所选全局数据池的对应 id + requestDataPondId?: string // 组件定制轮询时间 requestInterval?: number // 获取数据的方式 diff --git a/src/store/modules/chartEditStore/chartEditStore.ts b/src/store/modules/chartEditStore/chartEditStore.ts index d6f8ddf3..16a4eda4 100644 --- a/src/store/modules/chartEditStore/chartEditStore.ts +++ b/src/store/modules/chartEditStore/chartEditStore.ts @@ -113,6 +113,7 @@ export const useChartEditStore = defineStore({ }, // 数据请求处理(需存储给后端) requestGlobalConfig: { + requestDataPond: [], requestOriginUrl: '', requestInterval: requestInterval, requestIntervalUnit: requestIntervalUnit, diff --git a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataAjax/index.vue b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataAjax/index.vue index 9d3654ae..9e27f94f 100644 --- a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataAjax/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataAjax/index.vue @@ -125,7 +125,7 @@ const sendHandle = async () => { if (!targetData.value?.request) return loading.value = true try { - const res = await customizeHttp(toRaw(targetData.value.request), toRaw(chartEditStore.requestGlobalConfig)) + const res = await customizeHttp(toRaw(targetData.value.request), toRaw(chartEditStore.getRequestGlobalConfig)) loading.value = false if (res) { if(!res?.data && !targetData.value.filter) window['$message'].warning('您的数据不符合默认格式,请配置过滤器!') diff --git a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataMonacoEditor/index.vue b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataMonacoEditor/index.vue index cea1e1c8..a0d76216 100644 --- a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataMonacoEditor/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataMonacoEditor/index.vue @@ -128,7 +128,7 @@ const sourceData = ref('') // 动态获取数据 const fetchTargetData = async () => { try { - const res = await customizeHttp(toRaw(targetData.value.request), toRaw(chartEditStore.requestGlobalConfig)) + const res = await customizeHttp(toRaw(targetData.value.request), toRaw(chartEditStore.getRequestGlobalConfig)) if (res) { sourceData.value = res return diff --git a/src/views/preview/components/PreviewRenderList/index.vue b/src/views/preview/components/PreviewRenderList/index.vue index 9bb0cbec..d4354055 100644 --- a/src/views/preview/components/PreviewRenderList/index.vue +++ b/src/views/preview/components/PreviewRenderList/index.vue @@ -10,7 +10,7 @@ ...getTransformStyle(item.styles), ...getStatusStyle(item.status), ...getBlendModeStyle(item.styles) as any - } as any" + }" >