CMVR-IOT-UI/src/views/flow/components/params/useQuote.js

83 lines
2.7 KiB
JavaScript

/**
* 文件说明:参数引用组合逻辑,维护可引用字段和级联选择状态。
* 作用范围:仅服务于流程设计器模块。
*/
import { ref } from 'vue'
import { getInput } from '@/utils/flow'
/**
* 处理 useQuote 对应的数据或交互;作用范围仅限当前组件或模块。
* @param {*} nodeId 流程节点 ID
*/
export function useQuote(nodeId) {
const quoteOptions = ref([])
const cascaderRefs = ref([])
/**
* 处理 handleTypeChange 对应的数据或交互;作用范围仅限当前组件或模块。
* @param {*} index 目标项索引
* @param {*} formData 参数表单数据
* @param {*} type 目标类型
*/
const handleTypeChange = (index, formData, type = 'default') => {
// 根据节点类型处理不同数据源
// 这里简化为通用逻辑,具体实现需根据实际数据结构调整
if (formData.nodeParams[index].type === 'input') {
formData.nodeParams[index].quote = ''
} else {
formData.nodeParams[index].input = ''
const option = getInput(nodeId)
if (option) quoteOptions.value = option
}
}
/**
* 处理 cascaderChange 对应的数据或交互;作用范围仅限当前组件或模块。
* @param {*} value 待处理的新值
* @param {*} index 目标项索引
* @param {*} formData 参数表单数据
* @param {*} field 调用方传入的 field 参数
*/
const cascaderChange = (value, index, formData, field = 'nodeParams') => {
const selectedOptions = cascaderRefs.value[index]?.getCheckedNodes(true)
if (selectedOptions && selectedOptions.length) {
formData[field][index].quote = value
formData[field][index].quoteType = selectedOptions[0].data.type
}
}
/**
* 处理 visibleChange 对应的数据或交互;作用范围仅限当前组件或模块。
* @param {*} visible 是否可见
* @param {*} index 目标项索引
* @param {*} currentQuote 调用方传入的 currentQuote 参数
* @param {*} formData 参数表单数据
* @param {*} field 调用方传入的 field 参数
*/
const visibleChange = (visible, index, currentQuote, formData, field = 'nodeParams') => {
if (visible) {
const option = getInput(nodeId)
if (option) {
quoteOptions.value = option
const currentValue = [...currentQuote]
if (cascaderRefs.value[index] && currentValue.length > 0) {
setTimeout(() => {
formData[field][index].quote = []
setTimeout(() => {
formData[field][index].quote = currentValue
}, 0)
}, 0)
}
}
}
}
return {
quoteOptions,
cascaderRefs,
handleTypeChange,
cascaderChange,
visibleChange
}
}