diff --git a/src/hooks/events.hook.ts b/src/hooks/events.hook.ts new file mode 100644 index 00000000..669f5668 --- /dev/null +++ b/src/hooks/events.hook.ts @@ -0,0 +1,23 @@ +import { computed, toRefs } from 'vue' +import { CreateComponentType } from '@/packages/index.d' +import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' + +// 获取类型 +type ChartEditStoreType = typeof useChartEditStore + +// Params 参数修改触发api更新图表请求 +export const eventsCreate = (chartConfig: CreateComponentType, useChartEditStore: ChartEditStoreType, param: { [name: string]: string }, onEvevnt: string) => { + const chartEditStore = useChartEditStore() + const { eventsFn } = chartConfig.events + const fnOnEvevnt = eventsFn.filter((item) => { + return item.on === onEvevnt + }) || [] + if (fnOnEvevnt.length === 0) return + fnOnEvevnt.forEach((item) => { + const index = chartEditStore.fetchTargetIndex(item.components) + const { Params } = toRefs(chartEditStore.componentList[index].request.requestParams) + Object.keys(item.fn).forEach((key) => { + Params.value[key] = param[item.fn[key]] + }) + }) +} \ No newline at end of file diff --git a/src/hooks/index.ts b/src/hooks/index.ts index b5ab7ef8..902d76ef 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -4,4 +4,5 @@ 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 +export * from '@/hooks/useLang.hook' +export * from '@/hooks/events.hook' \ No newline at end of file diff --git a/src/hooks/useChartDataFetch.hook.ts b/src/hooks/useChartDataFetch.hook.ts index ed82edf5..6cbbdee4 100644 --- a/src/hooks/useChartDataFetch.hook.ts +++ b/src/hooks/useChartDataFetch.hook.ts @@ -1,4 +1,4 @@ -import { ref, toRefs, toRaw } from 'vue' +import { ref, toRefs, toRaw, watch } from 'vue' import type VChart from 'vue-echarts' import { customizeHttp } from '@/api/http' import { useChartDataPondFetch } from '@/hooks/' @@ -89,6 +89,13 @@ export const useChartDataFetch = ( // 立即调用 fetchFn() + + + watch(() => targetComponent.request, () => { + fetchFn() + }, { + deep: true + }) // 定时时间 const time = targetInterval && targetInterval.value ? targetInterval.value : globalRequestInterval.value // 单位 diff --git a/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEvebtInteraction/index.ts b/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEvebtInteraction/index.ts new file mode 100644 index 00000000..d4c2031d --- /dev/null +++ b/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEvebtInteraction/index.ts @@ -0,0 +1,3 @@ +import ChartEvebtInteraction from './index.vue' + +export { ChartEvebtInteraction } \ No newline at end of file diff --git a/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEvebtInteraction/index.vue b/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEvebtInteraction/index.vue new file mode 100644 index 00000000..0526f50d --- /dev/null +++ b/src/views/chart/ContentConfigurations/components/ChartEvent/components/ChartEvebtInteraction/index.vue @@ -0,0 +1,159 @@ + + + + +