feat: 支持对公共api进行交互

This commit is contained in:
Ming 2023-06-07 15:06:51 +08:00
parent 9485931f5d
commit 47636ee680

View File

@ -1,4 +1,5 @@
import { toRefs } from 'vue' import { toRefs } from 'vue'
import { isPreview } from '@/utils'
import { CreateComponentType } from '@/packages/index.d' import { CreateComponentType } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
@ -12,6 +13,7 @@ export const useChartInteract = (
param: { [T: string]: any }, param: { [T: string]: any },
interactEventOn: string interactEventOn: string
) => { ) => {
if (!isPreview()) return
const chartEditStore = useChartEditStore() const chartEditStore = useChartEditStore()
const { interactEvents } = chartConfig.events const { interactEvents } = chartConfig.events
const fnOnEvent = interactEvents.filter(item => { const fnOnEvent = interactEvents.filter(item => {
@ -20,20 +22,37 @@ export const useChartInteract = (
if (fnOnEvent.length === 0) return if (fnOnEvent.length === 0) return
fnOnEvent.forEach(item => { fnOnEvent.forEach(item => {
const index = chartEditStore.fetchTargetIndex(item.interactComponentId)
if (index === -1) return const globalConfigPindAprndex = chartEditStore.requestGlobalConfig.requestDataPond.findIndex(cItem =>
const { Params, Header } = toRefs(chartEditStore.componentList[index].request.requestParams) cItem.dataPondId === item.interactComponentId
Object.keys(item.interactFn).forEach(key => { )
if (Params.value[key]) { if (globalConfigPindAprndex !== -1) {
Params.value[key] = param[item.interactFn[key]] const { Params, Header } = toRefs(chartEditStore.requestGlobalConfig.requestDataPond[globalConfigPindAprndex].dataPondRequestConfig.requestParams)
}
if (Header.value[key]) { Object.keys(item.interactFn).forEach(key => {
Header.value[key] = param[item.interactFn[key]] if (Params.value[key]) {
} Params.value[key] = param[item.interactFn[key]]
}) }
if (Header.value[key]) {
Header.value[key] = param[item.interactFn[key]]
}
})
} else {
const index = chartEditStore.fetchTargetIndex(item.interactComponentId)
if (index === -1) return
const { Params, Header } = toRefs(chartEditStore.componentList[index].request.requestParams)
Object.keys(item.interactFn).forEach(key => {
if (Params.value[key]) {
Params.value[key] = param[item.interactFn[key]]
}
if (Header.value[key]) {
Header.value[key] = param[item.interactFn[key]]
}
})
}
}) })
} }
// 联动事件触发的 type 变更时,清除当前绑定内容 // 联动事件触发的 type 变更时,清除当前绑定内容
export const clearInteractEvent = (chartConfig: CreateComponentType) => { export const clearInteractEvent = (chartConfig: CreateComponentType) => {