fix: 【工作流】 修复父级节点删除后,节点变量未校验问题 (#672)

This commit is contained in:
shaohuzhang1 2024-07-01 10:20:01 +08:00 committed by GitHub
parent 2f2f74fdab
commit d240c411f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,19 +37,18 @@ const options = ref<Array<any>>([])
function visibleChange(bool: boolean) { function visibleChange(bool: boolean) {
if (bool) { if (bool) {
options.value = [] options.value = getIncomingNode(props.nodeModel.id)
getIncomingNode(props.nodeModel.id)
} }
} }
function _getIncomingNode(id: String, startId: String) { function _getIncomingNode(id: String, startId: String, value: Array<any>) {
let list = props.nodeModel.graphModel.getNodeIncomingNode(id) let list = props.nodeModel.graphModel.getNodeIncomingNode(id)
list = list.filter((item: any) => item.id !== startId) list = list.filter((item: any) => item.id !== startId)
let firstElement = null let firstElement = null
if (list.length > 0) { if (list.length > 0) {
list.forEach((item: any) => { list.forEach((item: any) => {
if (!options.value.some((obj: any) => obj.id === item.id)) { if (!value.some((obj: any) => obj.id === item.id)) {
options.value.unshift({ value.unshift({
value: item.id, value: item.id,
label: item.properties.stepName, label: item.properties.stepName,
type: item.type, type: item.type,
@ -67,19 +66,21 @@ function _getIncomingNode(id: String, startId: String) {
}) })
list.forEach((item: any) => { list.forEach((item: any) => {
_getIncomingNode(item.id, startId) _getIncomingNode(item.id, startId, value)
}) })
} }
if (firstElement) { if (firstElement) {
options.value.unshift(firstElement) value.unshift(firstElement)
} }
return value
} }
function getIncomingNode(id: string) { function getIncomingNode(id: string) {
_getIncomingNode(id, id) return _getIncomingNode(id, id, [])
} }
const validate = () => { const validate = () => {
getIncomingNode(props.nodeModel.id) const incomingNodeValue = getIncomingNode(props.nodeModel.id)
if (!data.value) { options.value = incomingNodeValue
if (!data.value || data.value.length === 0) {
return Promise.reject('引用变量必填') return Promise.reject('引用变量必填')
} }
if (data.value.length < 2) { if (data.value.length < 2) {
@ -87,18 +88,20 @@ const validate = () => {
} }
const node_id = data.value[0] const node_id = data.value[0]
const node_field = data.value[1] const node_field = data.value[1]
const nodeParent = options.value.find((item: any) => item.value === node_id) const nodeParent = incomingNodeValue.find((item: any) => item.value === node_id)
if (!nodeParent) { if (!nodeParent) {
data.value = []
return Promise.reject('不存在的引用变量') return Promise.reject('不存在的引用变量')
} }
if (!nodeParent.children.some((item: any) => item.value === node_field)) { if (!nodeParent.children.some((item: any) => item.value === node_field)) {
data.value = []
return Promise.reject('不存在的引用变量') return Promise.reject('不存在的引用变量')
} }
return Promise.resolve('') return Promise.resolve('')
} }
defineExpose({ validate }) defineExpose({ validate })
onMounted(() => { onMounted(() => {
getIncomingNode(props.nodeModel.id) options.value = getIncomingNode(props.nodeModel.id)
}) })
</script> </script>
<style scoped></style> <style scoped></style>