Parcourir la source

feat: 添加输出节点

jiaxing.liao il y a 1 semaine
Parent
commit
80dd658907

+ 16 - 2
apps/web/src/nodes/_base/OutputVariables.vue

@@ -20,12 +20,20 @@
 					@input="handleOutputChange"
 				/>
 				<el-select
+					v-if="setType"
 					v-model="output.type"
 					:options="VARIABLE_TYPE_OPTIONS"
 					class="w-1/3 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white min-w-[100px]"
 					@change="handleOutputChange"
 				>
 				</el-select>
+				<VarSelect
+					v-if="setValue"
+					v-model="output.value"
+					class="w-1/3"
+					placeholder="{x} 设置变量值"
+					@change="(val) => val && (output.type = val.type as NodeVariableType)"
+				/>
 				<IconButton link icon="lucide:trash-2" class="text-red-500" @click="removeOutput(index)" />
 			</div>
 		</div>
@@ -35,18 +43,24 @@
 <script setup lang="ts">
 import { ref, watch } from 'vue'
 import { IconButton } from '@repo/ui'
+import VarSelect from './VarSelect.vue'
 import { VARIABLE_TYPE_OPTIONS } from '@/constant'
-import type { NodeVariable } from '@/nodes/Interface'
+import type { NodeVariable, NodeVariableType } from '@/nodes/Interface'
 
 interface Props {
 	modelValue: NodeVariable[]
+	setType?: boolean
+	setValue?: boolean
 }
 
 interface Emits {
 	(e: 'update:modelValue', value: NodeVariable[]): void
 }
 
-const props = defineProps<Props>()
+const props = withDefaults(defineProps<Props>(), {
+	setType: true,
+	setValue: false
+})
 const emit = defineEmits<Emits>()
 
 const outputs = ref<NodeVariable[]>(props.modelValue || [])

+ 2 - 0
apps/web/src/nodes/src/end/index.ts

@@ -1,4 +1,5 @@
 import { NodeConnectionTypes, type INodeType, type INodeDataBaseSchema } from '../../Interface'
+import Setter from './setter.vue'
 
 export type EndData = INodeDataBaseSchema
 
@@ -6,6 +7,7 @@ export const endNode: INodeType = {
 	version: ['1'],
 	displayName: '输出',
 	name: 'end',
+	Setter,
 	description: '流程结束并输出节点',
 	group: '业务逻辑',
 	icon: 'lucide:unplug',

+ 42 - 0
apps/web/src/nodes/src/end/setter.vue

@@ -0,0 +1,42 @@
+<script setup lang="ts">
+import { ref, watch } from 'vue'
+import OutputVariables from '@/nodes/_base/OutputVariables.vue'
+
+import type { EndData } from './index'
+
+const props = defineProps<{
+	data: EndData
+}>()
+
+const emit = defineEmits<{
+	(e: 'update', data: EndData): void
+}>()
+
+const formData = ref<EndData>(props.data)
+
+watch(
+	() => formData.value,
+	(newVal) => {
+		emit('update', newVal)
+	}
+)
+
+watch(
+	props.data,
+	(newVal) => {
+		if (newVal) {
+			formData.value = newVal
+		}
+	},
+	{
+		immediate: true,
+		deep: true
+	}
+)
+</script>
+
+<template>
+	<el-scrollbar class="box-border p-12px">
+		<OutputVariables v-model="formData.outputs" :set-type="false" :set-value="true" />
+	</el-scrollbar>
+</template>

+ 2 - 2
apps/web/src/nodes/src/index.ts

@@ -6,7 +6,7 @@
  * @Describe: 节点物料管理
  */
 import { startNode } from './start'
-// import { endNode } from './end'
+import { endNode } from './end'
 import { httpNode } from './http'
 import { conditionNode } from './condition'
 import { databaseNode } from './database'
@@ -18,7 +18,7 @@ import type { INodeType } from '../Interface'
 
 const nodes = [
 	startNode,
-	// endNode,
+	endNode,
 	httpNode,
 	conditionNode,
 	databaseNode,