|
2 | 2 | <NodeContainer :nodeModel="nodeModel"> |
3 | 3 | <h5 class="title-decoration-1 mb-8">全局变量</h5> |
4 | 4 | <div |
| 5 | + v-for="item in nodeModel.properties.config.globalFields" |
5 | 6 | class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter" |
6 | 7 | @mouseenter="showicon = true" |
7 | 8 | @mouseleave="showicon = false" |
8 | 9 | > |
9 | | - <span>当前时间 {time}</span> |
| 10 | + <span>{{ item.label }} {{ '{' + item.value + '}' }}</span> |
10 | 11 | <el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true"> |
11 | | - <el-button link @click="copyClick(globeLabel)" style="padding: 0"> |
12 | | - <AppIcon iconName="app-copy"></AppIcon> |
13 | | - </el-button> |
14 | | - </el-tooltip> |
15 | | - </div> |
16 | | - <div v-for="(item, index) in inputFieldList" :key="index" |
17 | | - class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter" |
18 | | - @mouseenter="showicon = true" |
19 | | - @mouseleave="showicon = false" |
20 | | - > |
21 | | - <span>{{ item.name }} {{ '{' + item.variable + '}' }}</span> |
22 | | - <el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true"> |
23 | | - <el-button link @click="copyClick('{{' + '全局变量.' + item.variable + '}}')" style="padding: 0"> |
| 12 | + <el-button |
| 13 | + link |
| 14 | + @click="copyClick('{{' + '全局变量.' + item.value + '}}')" |
| 15 | + style="padding: 0" |
| 16 | + > |
24 | 17 | <AppIcon iconName="app-copy"></AppIcon> |
25 | 18 | </el-button> |
26 | 19 | </el-tooltip> |
27 | 20 | </div> |
28 | 21 | </NodeContainer> |
29 | 22 | </template> |
30 | 23 | <script setup lang="ts"> |
31 | | -import { set } from 'lodash' |
| 24 | +import { cloneDeep, set } from 'lodash' |
32 | 25 | import NodeContainer from '@/workflow/common/NodeContainer.vue' |
33 | 26 | import { copyClick } from '@/utils/clipboard' |
34 | 27 | import { ref, computed, onMounted } from 'vue' |
35 | 28 |
|
36 | 29 | const props = defineProps<{ nodeModel: any }>() |
37 | 30 |
|
38 | | -const globeLabel = '{{全局变量.time}}' |
39 | | -
|
40 | 31 | const showicon = ref(false) |
41 | | -
|
| 32 | +const globalFields = [ |
| 33 | + { label: '当前时间', value: 'time' }, |
| 34 | + { label: '历史聊天记录', value: 'history_context' }, |
| 35 | + { label: '对话id', value: 'chat_id' } |
| 36 | +] |
42 | 37 | const inputFieldList = ref<any[]>([]) |
43 | 38 |
|
44 | | -function handleRefreshFieldList(data: any[]) { |
45 | | - props.nodeModel.graphModel.nodes |
| 39 | +const getRefreshFieldList = () => { |
| 40 | + return props.nodeModel.graphModel.nodes |
46 | 41 | .filter((v: any) => v.id === 'base-node') |
47 | | - .map((v: any) => { |
48 | | - // eslint-disable-next-line vue/no-mutating-props |
49 | | - props.nodeModel.properties.config.globalFields = [ |
50 | | - { |
51 | | - label: '当前时间', |
52 | | - value: 'time' |
53 | | - }, ...v.properties.input_field_list.map((i: any) => { |
54 | | - return { label: i.name, value: i.variable } |
55 | | - }) |
56 | | - ] |
57 | | - inputFieldList.value = v.properties.input_field_list |
58 | | - }) |
| 42 | + .map((v: any) => cloneDeep(v.properties.input_field_list)) |
| 43 | + .reduce((x: any, y: any) => [...x, ...y], []) |
| 44 | + .map((i: any) => ({ label: i.name, value: i.variable })) |
59 | 45 | } |
60 | | -
|
61 | | -props.nodeModel.graphModel.eventCenter.on('refreshFieldList', (data: any) => { |
62 | | - handleRefreshFieldList(data) |
63 | | -}) |
| 46 | +const refreshFieldList = () => { |
| 47 | + const refreshFieldList = getRefreshFieldList() |
| 48 | + set(props.nodeModel.properties.config, 'globalFields', [...globalFields, ...refreshFieldList]) |
| 49 | +} |
| 50 | +props.nodeModel.graphModel.eventCenter.on('refreshFieldList', refreshFieldList) |
64 | 51 |
|
65 | 52 | onMounted(() => { |
66 | | - handleRefreshFieldList([]) |
| 53 | + refreshFieldList() |
67 | 54 | }) |
68 | 55 | </script> |
69 | 56 | <style lang="scss" scoped></style> |
0 commit comments