OutputVariables.vue 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!--
  2. * @Author: liuJie
  3. * @Date: 2026-01-27 14:38:32
  4. * @LastEditors: liuJie
  5. * @LastEditTime: 2026-01-27 17:26:25
  6. * @Describe: file describe
  7. -->
  8. <template>
  9. <div class="">
  10. <div class="flex items-center justify-between">
  11. <label class="text-sm font-medium text-gray-700">
  12. 输出变量
  13. <span class="text-red-500">*</span>
  14. </label>
  15. <ElButton @click="addOutput" class="p-1 hover:bg-gray-100 rounded transition-colors" title="添加输出">
  16. <Icon icon="lucide:plus" :height="16" :width="16" class="text-gray-600" />
  17. </ElButton>
  18. </div>
  19. <div class="space-y-2">
  20. <div v-for="(output, index) in outputs" :key="output.id" class="flex items-center gap-2 group">
  21. <ElInput v-model="output.name" type="text" placeholder="result"
  22. class="w-1/3 px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
  23. @input="handleOutputChange" />
  24. <ElSelect v-model="output.type" @change="handleOutputChange"
  25. class="w-1/3 px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white min-w-[100px]">
  26. <el-option value="String">String</el-option>
  27. <el-option value="Number">Number</el-option>
  28. <el-option value="Boolean">Boolean</el-option>
  29. <el-option value="Object">Object</el-option>
  30. <el-option value="Array">Array</el-option>
  31. </ElSelect>
  32. <ElButton @click="removeOutput(index)"
  33. class="w-1/3 p-1 opacity-0 group-hover:opacity-100 hover:bg-red-50 rounded transition-all" title="删除输出">
  34. <Icon icon="lucide:trash-2" :height="16" :width="16" class="text-red-500" />
  35. </ElButton>
  36. </div>
  37. <div v-if="outputs.length === 0" class="text-sm text-gray-400 text-center py-4">
  38. 请添加至少一个输出变量
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script setup lang="ts">
  44. import { ref, watch } from 'vue'
  45. import { Icon } from '@iconify/vue'
  46. interface OutputVariable {
  47. id: string
  48. name: string
  49. type: string
  50. }
  51. interface Props {
  52. modelValue: OutputVariable[]
  53. }
  54. interface Emits {
  55. (e: 'update:modelValue', value: OutputVariable[]): void
  56. }
  57. const props = defineProps<Props>()
  58. const emit = defineEmits<Emits>()
  59. const outputs = ref<OutputVariable[]>(props.modelValue || [])
  60. watch(
  61. () => props.modelValue,
  62. (newVal) => {
  63. outputs.value = newVal || []
  64. }
  65. )
  66. const addOutput = () => {
  67. const newOutput: OutputVariable = {
  68. id: `output_${Date.now()}`,
  69. name: 'result',
  70. type: 'String'
  71. }
  72. outputs.value.push(newOutput)
  73. handleOutputChange()
  74. }
  75. const removeOutput = (index: number) => {
  76. outputs.value.splice(index, 1)
  77. handleOutputChange()
  78. }
  79. const handleOutputChange = () => {
  80. emit('update:modelValue', outputs.value)
  81. }
  82. </script>