-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathDataSource.vue
More file actions
152 lines (148 loc) · 4.43 KB
/
DataSource.vue
File metadata and controls
152 lines (148 loc) · 4.43 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
<DynamicsForm
v-model="form_data"
:render_data="model_form_field"
:model="form_data"
ref="dynamicsFormRef"
label-position="top"
require-asterisk-position="right"
:other-params="{ current_workspace_id: workspace_id, current_knowledge_id: knowledge_id }"
>
<template #default>
<h4 class="title-decoration-1 mb-16 mt-4">
{{ $t('views.tool.dataSource.selectDataSource') }}
</h4>
<el-form-item
:label="$t('views.tool.dataSource.title')"
prop="node_id"
:rules="base_form_data_rule.node_id"
>
<el-row class="w-full" :gutter="8">
<el-col :span="8" v-for="node in source_node_list" :key="node.id">
<el-card
shadow="never"
class="card-checkbox cursor w-full mb-8"
:class="base_form_data.node_id === node.id ? 'active' : ''"
style="--el-card-padding: 4px 12px"
@click="sourceChange(node.id)"
>
<div class="flex align-center">
<component
:is="iconComponent(`${node.type}-icon`)"
class="mr-8"
:size="20"
:item="node?.properties.node_data"
/>
{{ node.properties.stepName }}
</div>
</el-card>
</el-col>
</el-row>
</el-form-item>
</template>
</DynamicsForm>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { WorkflowKind, WorkflowType } from '@/enums/application'
import DynamicsForm from '@/components/dynamics-form/index.vue'
import type { FormField } from '@/components/dynamics-form/type'
import { iconComponent } from '@/workflow/icons/utils'
import type { Dict } from '@/api/type/common'
import type { FormRules } from 'element-plus'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import { useRoute } from 'vue-router'
import { t } from '@/locales'
import useStore from '@/stores'
const { user } = useStore()
const route = useRoute()
const props = defineProps<{
workflow: any
knowledge_id: string
loading: boolean
}>()
const apiType = computed(() => {
if (route.path.includes('shared')) {
return 'systemShare'
} else if (route.path.includes('resource-management')) {
return 'systemManage'
} else {
return 'workspace'
}
})
const model_form_field = ref<Array<FormField>>([])
const workspace_id = computed(() => {
return user.getWorkspaceId()
})
const emit = defineEmits(['update:loading'])
const _loading = computed({
get: () => {
return props.loading
},
set: (v: boolean) => {
emit('update:loading', v)
},
})
const dynamicsFormRef = ref<InstanceType<typeof DynamicsForm>>()
const base_form_data = ref<{ node_id: string }>({ node_id: '' })
const dynamics_form_data = ref<Dict<any>>({})
const form_data = computed({
get: () => {
return { ...dynamics_form_data.value, ...base_form_data.value }
},
set: (event: any) => {
dynamics_form_data.value = event
},
})
const source_node_list = computed(() => {
return props.workflow?.nodes?.filter((n: any) => n.properties.kind === WorkflowKind.DataSource)
})
const sourceChange = (node_id: string) => {
base_form_data.value.node_id = node_id
const n = source_node_list.value.find((n: any) => n.id == node_id)
node_id = n
? [WorkflowType.DataSourceLocalNode, WorkflowType.DataSourceWebNode].includes(n.type)
? n.type
: n.properties.node_data.tool_lib_id
: node_id
loadSharedApi({ type: 'knowledge', systemType: apiType.value })
.getKnowledgeWorkflowFormList(
props.knowledge_id,
[WorkflowType.DataSourceLocalNode, WorkflowType.DataSourceWebNode].includes(n.type)
? 'local'
: 'tool',
node_id,
n,
_loading,
)
.then((ok: any) => {
dynamicsFormRef.value?.render(ok.data)
})
}
const base_form_data_rule = ref<FormRules>({
node_id: {
required: true,
trigger: 'blur',
message: t('views.tool.dataSource.requiredMessage'),
},
})
const validate = () => {
return dynamicsFormRef.value?.validate()
}
const get_data = () => {
return form_data.value
}
watch(
source_node_list,
() => {
if (!base_form_data.value.node_id) {
if (source_node_list.value && source_node_list.value.length > 0) {
sourceChange(source_node_list.value[0].id)
}
}
},
{ immediate: true },
)
defineExpose({ validate, get_data })
</script>
<style lang="scss" scoped></style>