goview_vue/src/hooks/useChartInteract.hook.ts

60 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-03-11 16:58:32 +08:00
import { toRefs } from 'vue'
2023-06-07 15:06:51 +08:00
import { isPreview } from '@/utils'
2023-03-11 16:58:32 +08:00
import { CreateComponentType } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
// 获取类型
type ChartEditStoreType = typeof useChartEditStore
// Params 参数修改触发 api 更新图表请求
export const useChartInteract = (
chartConfig: CreateComponentType,
useChartEditStore: ChartEditStoreType,
param: { [T: string]: any },
interactEventOn: string
2023-03-11 16:58:32 +08:00
) => {
2023-06-07 15:06:51 +08:00
if (!isPreview()) return
2023-03-11 16:58:32 +08:00
const chartEditStore = useChartEditStore()
const { interactEvents } = chartConfig.events
const fnOnEvent = interactEvents.filter(item => {
return item.interactOn === interactEventOn
2023-03-11 16:58:32 +08:00
})
2023-03-11 18:19:30 +08:00
if (fnOnEvent.length === 0) return
2023-03-11 16:58:32 +08:00
fnOnEvent.forEach(item => {
2023-06-07 15:06:51 +08:00
const globalConfigPindAprndex = chartEditStore.requestGlobalConfig.requestDataPond.findIndex(cItem =>
cItem.dataPondId === item.interactComponentId
)
if (globalConfigPindAprndex !== -1) {
const { Params, Header } = toRefs(chartEditStore.requestGlobalConfig.requestDataPond[globalConfigPindAprndex].dataPondRequestConfig.requestParams)
Object.keys(item.interactFn).forEach(key => {
if (key in Params.value) {
2023-06-07 15:06:51 +08:00
Params.value[key] = param[item.interactFn[key]]
}
if (key in Header.value) {
2023-06-07 15:06:51 +08:00
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 (key in Params.value) {
2023-06-07 15:06:51 +08:00
Params.value[key] = param[item.interactFn[key]]
}
if (key in Header.value) {
2023-06-07 15:06:51 +08:00
Header.value[key] = param[item.interactFn[key]]
}
})
}
2023-03-11 16:58:32 +08:00
})
}
// 联动事件触发的 type 变更时,清除当前绑定内容
export const clearInteractEvent = (chartConfig: CreateComponentType) => {
}