BlockSettingLines.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div class="block-lines max-w-xl">
  3. <ui-select
  4. v-model="state.activeEdge"
  5. :placeholder="t('workflow.blocks.base.settings.line.select')"
  6. class="w-full"
  7. >
  8. <option v-for="edge in state.edges" :key="edge.id" :value="edge.id">
  9. {{ edge.name }}
  10. </option>
  11. </ui-select>
  12. <div v-if="activeEdge" class="mt-4">
  13. <div class="flex items-center mt-2">
  14. <label class="flex items-center mr-4 mt-5">
  15. <ui-switch
  16. :model-value="activeEdge.animated"
  17. @change="updateActiveEdge('animated', $event)"
  18. />
  19. <span class="ml-2">
  20. {{ t('workflow.blocks.base.settings.line.animated') }}
  21. </span>
  22. </label>
  23. <ui-input
  24. :model-value="activeEdge.label"
  25. :label="t('workflow.blocks.base.settings.line.label')"
  26. placeholder="A label"
  27. class="flex-1"
  28. @change="updateActiveEdge('label', $event)"
  29. />
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script setup>
  35. import { inject, onMounted, reactive, computed } from 'vue';
  36. import { useI18n } from 'vue-i18n';
  37. import { debounce } from '@/utils/helper';
  38. const props = defineProps({
  39. blockId: {
  40. type: String,
  41. default: '',
  42. },
  43. });
  44. const { t } = useI18n();
  45. const editor = inject('workflow-editor');
  46. const state = reactive({
  47. retrieved: false,
  48. edges: {},
  49. activeEdge: '',
  50. });
  51. const activeEdge = computed(() => state.edges[state.activeEdge]);
  52. const updateActiveEdge = debounce((name, value) => {
  53. const edge = editor.value.getEdge.value(state.activeEdge);
  54. edge[name] = value;
  55. state.edges[state.activeEdge][name] = value;
  56. }, 250);
  57. onMounted(() => {
  58. state.edges = editor.value.getEdges.value.reduce(
  59. (acc, { id, source, targetNode, label, animated, labelStyle }) => {
  60. if (source !== props.blockId) return acc;
  61. let name = t('workflow.blocks.base.settings.line.to', {
  62. name: t(`workflow.blocks.${targetNode.label}.name`),
  63. });
  64. if (targetNode.data.description) {
  65. name += ` (${targetNode.data.description.slice(0, 32)})`;
  66. }
  67. acc[id] = {
  68. name,
  69. id,
  70. label: `${label || ''}`,
  71. animated: animated ?? false,
  72. labelStyle: labelStyle || '',
  73. };
  74. return acc;
  75. },
  76. {}
  77. );
  78. });
  79. </script>