EditWhileLoop.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div>
  3. <ui-textarea
  4. :model-value="data.description"
  5. :placeholder="t('common.description')"
  6. class="w-full mb-1"
  7. @change="updateData({ description: $event })"
  8. />
  9. <ui-button
  10. variant="accent"
  11. class="w-full mt-4"
  12. @click="showConditionBuilder = true"
  13. >
  14. {{ t('workflow.blocks.while-loop.editCondition') }}
  15. </ui-button>
  16. <ui-modal v-model="showConditionBuilder" custom-content>
  17. <ui-card padding="p-0" class="w-full max-w-3xl">
  18. <div class="px-4 pt-4 flex items-center">
  19. <p class="flex-1">
  20. {{ t('workflow.conditionBuilder.title') }}
  21. </p>
  22. <v-remixicon
  23. name="riCloseLine"
  24. class="cursor-pointer"
  25. @click="showConditionBuilder = false"
  26. />
  27. </div>
  28. <shared-condition-builder
  29. :model-value="data.conditions"
  30. class="overflow-auto p-4 mt-4 scroll"
  31. style="height: calc(100vh - 8rem)"
  32. @change="updateData({ conditions: $event })"
  33. />
  34. </ui-card>
  35. </ui-modal>
  36. </div>
  37. </template>
  38. <script setup>
  39. import { onMounted, ref } from 'vue';
  40. import { useI18n } from 'vue-i18n';
  41. import { nanoid } from 'nanoid';
  42. import SharedConditionBuilder from '@/components/newtab/shared/SharedConditionBuilder/index.vue';
  43. const props = defineProps({
  44. data: {
  45. type: Object,
  46. default: () => ({}),
  47. },
  48. });
  49. const emit = defineEmits(['update:data']);
  50. const { t } = useI18n();
  51. const defaultConditions = () => [
  52. {
  53. id: nanoid(),
  54. conditions: [
  55. {
  56. id: nanoid(),
  57. items: [
  58. {
  59. id: nanoid(),
  60. type: 'value',
  61. category: 'value',
  62. data: { value: '' },
  63. },
  64. { id: nanoid(), category: 'compare', type: 'eq' },
  65. {
  66. id: nanoid(),
  67. type: 'value',
  68. category: 'value',
  69. data: { value: '' },
  70. },
  71. ],
  72. },
  73. {
  74. id: nanoid(),
  75. items: [
  76. {
  77. id: nanoid(),
  78. type: 'value',
  79. category: 'value',
  80. data: { value: '' },
  81. },
  82. { id: nanoid(), category: 'compare', type: 'eq' },
  83. {
  84. id: nanoid(),
  85. type: 'value',
  86. category: 'value',
  87. data: { value: '' },
  88. },
  89. ],
  90. },
  91. ],
  92. },
  93. ];
  94. const showConditionBuilder = ref(false);
  95. function updateData(value) {
  96. emit('update:data', { ...props.data, ...value });
  97. }
  98. onMounted(() => {
  99. if (props.data.conditions === null) {
  100. updateData({ conditions: defaultConditions() });
  101. }
  102. });
  103. </script>