BlockBasicWithFallback.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <block-base
  3. :id="componentId"
  4. :hide-edit="block.details.disableEdit"
  5. :hide-delete="block.details.disableDelete"
  6. class="block-basic group"
  7. @edit="$emit('edit')"
  8. @delete="$emit('delete', id)"
  9. >
  10. <Handle :id="`${id}-input-1`" type="target" :position="Position.Left" />
  11. <div class="flex items-center">
  12. <span
  13. :class="data.disableBlock ? 'bg-box-transparent' : block.category.color"
  14. class="inline-block p-2 mr-2 rounded-lg dark:text-black"
  15. >
  16. <v-remixicon :name="block.details.icon || 'riGlobalLine'" />
  17. </span>
  18. <div class="overflow-hidden flex-1">
  19. <p
  20. v-if="block.details.id"
  21. class="font-semibold leading-tight text-overflow whitespace-nowrap"
  22. >
  23. {{ t(`workflow.blocks.${block.details.id}.name`) }}
  24. </p>
  25. <p class="text-gray-600 dark:text-gray-200 text-overflow leading-tight">
  26. {{ data.description }}
  27. </p>
  28. </div>
  29. </div>
  30. <slot :block="block"></slot>
  31. <div class="fallback flex items-center justify-end">
  32. <v-remixicon
  33. v-if="block"
  34. :title="t('workflow.blocks.base.onError.fallbackTitle')"
  35. name="riInformationLine"
  36. size="18"
  37. />
  38. <span class="ml-1">
  39. {{ t('common.fallback') }}
  40. </span>
  41. </div>
  42. <Handle :id="`${id}-output-1`" type="source" :position="Position.Right" />
  43. <Handle
  44. :id="`${id}-output-fallback`"
  45. type="source"
  46. :position="Position.Right"
  47. style="top: auto; bottom: 10px"
  48. />
  49. <template #prepend>
  50. <div
  51. v-if="block.details.id !== 'trigger'"
  52. :title="t('workflow.blocks.base.moveToGroup')"
  53. draggable="true"
  54. class="bg-white dark:bg-gray-700 invisible group-hover:visible z-50 absolute -top-2 -right-2 rounded-md p-1 shadow-md"
  55. @dragstart="handleStartDrag"
  56. @mousedown.stop
  57. >
  58. <v-remixicon name="riDragDropLine" size="20" />
  59. </div>
  60. </template>
  61. </block-base>
  62. </template>
  63. <script setup>
  64. import { Handle, Position } from '@braks/vue-flow';
  65. import { useI18n } from 'vue-i18n';
  66. import { useEditorBlock } from '@/composable/editorBlock';
  67. import { useComponentId } from '@/composable/componentId';
  68. import BlockBase from './BlockBase.vue';
  69. const props = defineProps({
  70. id: {
  71. type: String,
  72. default: '',
  73. },
  74. label: {
  75. type: String,
  76. default: '',
  77. },
  78. data: {
  79. type: Object,
  80. default: () => ({}),
  81. },
  82. });
  83. defineEmits(['delete', 'edit', 'update']);
  84. const { t } = useI18n();
  85. const block = useEditorBlock(props.label);
  86. const componentId = useComponentId('block-base');
  87. function handleStartDrag(event) {
  88. const payload = {
  89. data: block.data,
  90. id: block.details.id,
  91. blockId: block.id,
  92. fromBlockBasic: true,
  93. };
  94. event.dataTransfer.setData('block', JSON.stringify(payload));
  95. }
  96. </script>