EditConditions.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div>
  3. <ui-button
  4. :disabled="conditions.length >= 10"
  5. variant="accent"
  6. class="mb-4"
  7. @click="addCondition"
  8. >
  9. {{ t('workflow.blocks.conditions.add') }}
  10. </ui-button>
  11. <ul class="space-y-2">
  12. <li
  13. v-for="(condition, index) in conditions"
  14. :key="index"
  15. class="relative rounded-lg bg-input transition-colors group"
  16. >
  17. <input
  18. v-model="condition.compareValue"
  19. type="text"
  20. placeholder="value"
  21. class="py-2 px-4 w-full transition rounded-lg bg-transparent"
  22. />
  23. <button
  24. class="bg-white absolute top-1/2 right-4 p-2 rounded-lg -translate-y-1/2 group-hover:right-14"
  25. @click="deleteCondition(index)"
  26. >
  27. <v-remixicon size="20" name="riDeleteBin7Line" />
  28. </button>
  29. <select
  30. v-model="condition.type"
  31. :title="getTitle(index)"
  32. class="bg-white absolute right-4 font-mono z-10 p-2 top-1/2 leading-tight -translate-y-1/2 text-center transition rounded-lg appearance-none"
  33. >
  34. <option
  35. v-for="(name, type) in conditionTypes"
  36. :key="type"
  37. :value="type"
  38. >
  39. {{ type }}
  40. </option>
  41. </select>
  42. <div
  43. class="w-full bg-gray-300 h-px mx-auto"
  44. style="max-width: 89%"
  45. ></div>
  46. <input
  47. v-model="condition.value"
  48. type="text"
  49. placeholder="value"
  50. class="py-2 px-4 w-full transition rounded-lg bg-transparent"
  51. />
  52. </li>
  53. </ul>
  54. </div>
  55. </template>
  56. <script setup>
  57. import { toRef } from 'vue';
  58. import { useI18n } from 'vue-i18n';
  59. import emitter from 'tiny-emitter/instance';
  60. const props = defineProps({
  61. data: {
  62. type: Object,
  63. default: () => ({}),
  64. },
  65. blockId: {
  66. type: String,
  67. default: '',
  68. },
  69. });
  70. defineEmits(['update:data']);
  71. const conditionTypes = {
  72. '==': 'equals',
  73. '!=': 'ne',
  74. '>': 'gt',
  75. '>=': 'gte',
  76. '<': 'lt',
  77. '<=': 'lte',
  78. '()': 'contains',
  79. };
  80. const { t } = useI18n();
  81. const conditions = toRef(props.data, 'conditions');
  82. function getTitle(index) {
  83. const type = conditionTypes[conditions.value[index]?.type] || 'equals';
  84. return t(`workflow.blocks.conditions.${type}`);
  85. }
  86. function addCondition() {
  87. if (conditions.value.length >= 10) return;
  88. emitter.emit('conditions-block:add', {
  89. id: props.blockId,
  90. });
  91. conditions.value.unshift({
  92. compareValue: '',
  93. value: '',
  94. type: '==',
  95. });
  96. }
  97. function deleteCondition(index) {
  98. conditions.value.splice(index, 1);
  99. emitter.emit('conditions-block:delete', {
  100. index,
  101. id: props.blockId,
  102. });
  103. }
  104. // function updateData(value) {
  105. // emit('update:data', { ...props.data, ...value });
  106. // }
  107. </script>