WorkflowDetailsCard.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="px-4 flex items-start mb-2 mt-1">
  3. <ui-popover class="mr-2 h-8">
  4. <template #trigger>
  5. <span
  6. :title="t('workflow.sidebar.workflowIcon')"
  7. class="cursor-pointer inline-block h-full"
  8. >
  9. <ui-img
  10. v-if="workflow.icon.startsWith('http')"
  11. :src="workflow.icon"
  12. class="w-8 h-8"
  13. />
  14. <v-remixicon v-else :name="workflow.icon" size="26" class="mt-1" />
  15. </span>
  16. </template>
  17. <div class="w-56">
  18. <p class="mb-2">{{ t('workflow.sidebar.workflowIcon') }}</p>
  19. <div class="grid grid-cols-5 mb-2 gap-1">
  20. <span
  21. v-for="icon in icons"
  22. :key="icon"
  23. class="cursor-pointer rounded-lg inline-block text-center p-2 hoverable"
  24. @click="$emit('update', { icon })"
  25. >
  26. <v-remixicon :name="icon" />
  27. </span>
  28. </div>
  29. <ui-input
  30. :model-value="workflow.icon.startsWith('ri') ? '' : workflow.icon"
  31. type="url"
  32. placeholder="http://example.com/img.png"
  33. label="Icon URL"
  34. @change="updateWorkflowIcon"
  35. />
  36. </div>
  37. </ui-popover>
  38. <div class="flex-1 overflow-hidden">
  39. <p class="font-semibold mt-1 text-overflow text-lg leading-tight">
  40. {{ workflow.name }}
  41. </p>
  42. <p class="line-clamp leading-tight">
  43. {{ workflow.description }}
  44. </p>
  45. </div>
  46. </div>
  47. <ui-input
  48. v-model="query"
  49. :placeholder="`${t('common.search')}...`"
  50. prepend-icon="riSearch2Line"
  51. class="px-4 mt-4 mb-2"
  52. />
  53. <div class="scroll bg-scroll overflow-auto px-4 flex-1 overflow-auto">
  54. <template v-for="(items, catId) in blocks" :key="catId">
  55. <div class="flex items-center top-0 space-x-2 mb-2">
  56. <span
  57. :class="categories[catId].color"
  58. class="h-3 w-3 rounded-full"
  59. ></span>
  60. <p class="capitalize text-gray-600">{{ categories[catId].name }}</p>
  61. </div>
  62. <div class="grid grid-cols-2 gap-2 mb-4">
  63. <div
  64. v-for="block in items"
  65. :key="block.id"
  66. :title="
  67. t(
  68. `workflow.blocks.${block.id}.${
  69. block.description ? 'description' : 'name'
  70. }`
  71. )
  72. "
  73. draggable="true"
  74. class="transform select-none cursor-move relative p-4 rounded-lg bg-input transition"
  75. @dragstart="
  76. $event.dataTransfer.setData('block', JSON.stringify(block))
  77. "
  78. >
  79. <a
  80. v-if="block.docs"
  81. :href="`https://github.com/Kholid060/automa/wiki/Blocks#${block.id}`"
  82. target="_blank"
  83. :title="t('common.docs')"
  84. rel="noopener"
  85. class="absolute top-px right-2"
  86. >
  87. &#128712;
  88. </a>
  89. <v-remixicon :name="block.icon" size="24" class="mb-2" />
  90. <p class="leading-tight text-overflow">
  91. {{ block.name }}
  92. </p>
  93. </div>
  94. </div>
  95. </template>
  96. </div>
  97. </template>
  98. <script setup>
  99. import { computed, ref } from 'vue';
  100. import { useI18n } from 'vue-i18n';
  101. import { tasks, categories } from '@/utils/shared';
  102. defineProps({
  103. workflow: {
  104. type: Object,
  105. default: () => ({}),
  106. },
  107. dataChanged: {
  108. type: Boolean,
  109. default: false,
  110. },
  111. });
  112. const emit = defineEmits(['update']);
  113. const { t } = useI18n();
  114. const icons = [
  115. 'riGlobalLine',
  116. 'riFileTextLine',
  117. 'riEqualizerLine',
  118. 'riTimerLine',
  119. 'riCalendarLine',
  120. 'riFlashlightLine',
  121. 'riLightbulbFlashLine',
  122. 'riDatabase2Line',
  123. 'riWindowLine',
  124. 'riCursorLine',
  125. 'riDownloadLine',
  126. 'riCommandLine',
  127. ];
  128. const blocksArr = Object.entries(tasks).map(([key, block]) => ({
  129. ...block,
  130. id: key,
  131. name: t(`workflow.blocks.${key}.name`),
  132. }));
  133. const query = ref('');
  134. const blocks = computed(() =>
  135. blocksArr.reduce((arr, block) => {
  136. if (
  137. block.name.toLocaleLowerCase().includes(query.value.toLocaleLowerCase())
  138. ) {
  139. (arr[block.category] = arr[block.category] || []).push(block);
  140. }
  141. return arr;
  142. }, {})
  143. );
  144. function updateWorkflowIcon(value) {
  145. if (!value.startsWith('http')) return;
  146. const iconUrl = value.slice(0, 1024);
  147. emit('update', { icon: iconUrl });
  148. }
  149. </script>