-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathNodeCascader.vue
More file actions
132 lines (126 loc) · 3.56 KB
/
NodeCascader.vue
File metadata and controls
132 lines (126 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<template>
<el-cascader
@wheel="wheel"
:teleported="false"
:options="options"
@visible-change="visibleChange"
v-bind="$attrs"
v-model="data"
separator=" > "
clearable
>
<template #default="{ node, data }">
<span class="flex align-center" @wheel="wheel">
<component
:is="iconComponent(`${data.type}-icon`)"
class="mr-8"
:size="18"
:item="data"
/>{{ data.label }}</span
>
</template>
</el-cascader>
</template>
<script setup lang="ts">
import { ref, onMounted, computed, inject } from 'vue'
import { iconComponent } from '../icons/utils'
import { t } from '@/locales'
import { WorkflowMode } from '@/enums/application'
const props = defineProps<{
nodeModel: any
modelValue: Array<any>
global?: boolean
}>()
const emit = defineEmits(['update:modelValue'])
const workflowMode = inject('workflowMode') as WorkflowMode
const data = computed({
set: (value) => {
emit('update:modelValue', value)
},
get: () => {
return props.modelValue
},
})
const options = ref<Array<any>>([])
const wheel = (e: any) => {
if (e.ctrlKey === true) {
e.preventDefault()
return true
} else {
e.stopPropagation()
return true
}
}
function visibleChange(bool: boolean) {
if (bool) {
initOptions()
}
}
const validate = () => {
const incomingNodeValue = getOptionsValue()
if (!data.value || data.value.length === 0) {
return Promise.reject(t('workflow.variable.ReferencingRequired'))
}
if (data.value.length < 2) {
return Promise.reject(t('workflow.variable.ReferencingError'))
}
const node_id = data.value[0]
const node_field = data.value[1]
const nodeParent = incomingNodeValue.find((item: any) => item.value === node_id)
if (!nodeParent) {
data.value = []
return Promise.reject(t('workflow.variable.NoReferencing'))
}
if (!nodeParent.children.some((item: any) => item.value === node_field)) {
data.value = []
return Promise.reject(t('workflow.variable.NoReferencing'))
}
return Promise.resolve('')
}
const get_up_node_field_list = (contain_self: boolean, use_cache: boolean) => {
const result = props.nodeModel.get_up_node_field_list(contain_self, use_cache)
if (props.nodeModel.graphModel.get_up_node_field_list) {
const _u = props.nodeModel.graphModel.get_up_node_field_list(contain_self, use_cache)
_u.forEach((item: any) => {
result.push(item)
})
}
return result.filter((v: any) => v.children && v.children.length > 0)
}
const getOptionsValue = () => {
if (
[WorkflowMode.ApplicationLoop, WorkflowMode.KnowledgeLoop, WorkflowMode.ToolLoop].includes(
workflowMode,
)
) {
return props.global
? get_up_node_field_list(false, true).filter(
(v: any) =>
['global', 'chat', 'output', 'loop'].includes(v.value) &&
v.children &&
v.children.length > 0,
)
: get_up_node_field_list(false, true).filter((v: any) => v.children && v.children.length > 0)
} else {
const result = props.global
? props.nodeModel
.get_up_node_field_list(false, true)
.filter(
(v: any) =>
['global', 'chat', 'output'].includes(v.value) && v.children && v.children.length > 0,
)
: props.nodeModel
.get_up_node_field_list(false, true)
.filter((v: any) => v.children && v.children.length > 0)
return result
}
}
const initOptions = () => {
options.value = getOptionsValue()
}
defineExpose({ validate })
onMounted(() => {
initOptions()
})
</script>
<style scoped></style>