2026-07-06 11:11:59 +08:00
|
|
|
import { ref } from 'vue'
|
2026-08-21 11:48:10 +08:00
|
|
|
import { getUpstreamInput } from '@/utils/flow'
|
2026-07-06 11:11:59 +08:00
|
|
|
|
|
|
|
|
export function useQuote(nodeId) {
|
|
|
|
|
const quoteOptions = ref([])
|
|
|
|
|
const cascaderRefs = ref([])
|
|
|
|
|
|
2026-08-21 11:48:10 +08:00
|
|
|
const refreshQuoteOptions = () => {
|
|
|
|
|
quoteOptions.value = getUpstreamInput(nodeId) || []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The option tree must exist before Cascader can render a persisted path.
|
|
|
|
|
refreshQuoteOptions()
|
|
|
|
|
|
|
|
|
|
const handleTypeChange = (property) => {
|
|
|
|
|
if (!property) return
|
|
|
|
|
if (property.type === 'input') {
|
|
|
|
|
property.quote = []
|
2026-07-06 11:11:59 +08:00
|
|
|
} else {
|
2026-08-21 11:48:10 +08:00
|
|
|
property.input = ''
|
|
|
|
|
refreshQuoteOptions()
|
2026-07-06 11:11:59 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-21 11:48:10 +08:00
|
|
|
const cascaderChange = (value, property) => {
|
|
|
|
|
if (!property) return
|
|
|
|
|
property.quote = Array.isArray(value) ? [...value] : []
|
|
|
|
|
property.quoteType = value?.[1] === 'input' ? 'input' : 'output'
|
2026-07-06 11:11:59 +08:00
|
|
|
}
|
|
|
|
|
|
2026-08-21 11:48:10 +08:00
|
|
|
const visibleChange = (visible) => {
|
|
|
|
|
if (visible) refreshQuoteOptions()
|
2026-07-06 11:11:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
quoteOptions,
|
|
|
|
|
cascaderRefs,
|
|
|
|
|
handleTypeChange,
|
|
|
|
|
cascaderChange,
|
2026-08-21 11:48:10 +08:00
|
|
|
visibleChange,
|
|
|
|
|
refreshQuoteOptions,
|
2026-07-06 11:11:59 +08:00
|
|
|
}
|
2026-08-07 14:38:16 +08:00
|
|
|
}
|