1
0

WorkflowDetailsCard.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="px-4 flex items-start mb-2 mt-1">
  3. <ui-popover :disabled="data.active === 'shared'" 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. id="search-input"
  49. v-model="query"
  50. :disabled="data.active === 'shared'"
  51. :placeholder="`${t('common.search')}... (${
  52. shortcut['action:search'].readable
  53. })`"
  54. prepend-icon="riSearch2Line"
  55. class="px-4 mt-4 mb-2"
  56. />
  57. <div
  58. :class="[data.active === 'shared' ? 'overflow-hidden' : 'overflow-auto']"
  59. class="scroll bg-scroll px-4 flex-1 relative"
  60. >
  61. <div
  62. v-show="data.active === 'shared'"
  63. class="absolute h-full w-full bg-white dark:bg-black bg-opacity-10 dark:bg-opacity-10 backdrop-blur rounded-lg z-10 flex items-center justify-center"
  64. style="top: 0; left: 50%; transform: translateX(-50%); width: 95%"
  65. >
  66. <p>{{ t('workflow.cantEdit') }}</p>
  67. </div>
  68. <template v-for="(items, catId) in blocks" :key="catId">
  69. <div class="flex items-center top-0 space-x-2 mb-2">
  70. <span
  71. :class="categories[catId].color"
  72. class="h-3 w-3 rounded-full"
  73. ></span>
  74. <p class="capitalize text-gray-600 dark:text-gray-200">
  75. {{ categories[catId].name }}
  76. </p>
  77. </div>
  78. <div class="grid grid-cols-2 gap-2 mb-4">
  79. <div
  80. v-for="block in items"
  81. :key="block.id"
  82. :title="
  83. t(
  84. `workflow.blocks.${block.id}.${
  85. block.description ? 'description' : 'name'
  86. }`
  87. )
  88. "
  89. draggable="true"
  90. class="transform select-none cursor-move relative p-4 rounded-lg bg-input transition group"
  91. @dragstart="
  92. $event.dataTransfer.setData('block', JSON.stringify(block))
  93. "
  94. >
  95. <a
  96. :href="`https://docs.automa.site/blocks/${block.id}.html`"
  97. :title="t('common.docs')"
  98. target="_blank"
  99. rel="noopener"
  100. class="absolute top-px right-2 top-2 text-gray-600 dark:text-gray-300 invisible group-hover:visible"
  101. >
  102. <v-remixicon name="riInformationLine" size="18" />
  103. </a>
  104. <v-remixicon :name="block.icon" size="24" class="mb-2" />
  105. <p class="leading-tight text-overflow capitalize">
  106. {{ block.name }}
  107. </p>
  108. </div>
  109. </div>
  110. </template>
  111. </div>
  112. </template>
  113. <script setup>
  114. import { computed, ref } from 'vue';
  115. import { useI18n } from 'vue-i18n';
  116. import { useShortcut } from '@/composable/shortcut';
  117. import { tasks, categories } from '@/utils/shared';
  118. defineProps({
  119. workflow: {
  120. type: Object,
  121. default: () => ({}),
  122. },
  123. data: {
  124. type: Object,
  125. default: () => ({}),
  126. },
  127. dataChanged: {
  128. type: Boolean,
  129. default: false,
  130. },
  131. });
  132. const emit = defineEmits(['update']);
  133. const { t } = useI18n();
  134. const shortcut = useShortcut('action:search', () => {
  135. const searchInput = document.querySelector('#search-input input');
  136. searchInput?.focus();
  137. });
  138. const icons = [
  139. 'riGlobalLine',
  140. 'riFileTextLine',
  141. 'riEqualizerLine',
  142. 'riTimerLine',
  143. 'riCalendarLine',
  144. 'riFlashlightLine',
  145. 'riLightbulbFlashLine',
  146. 'riDatabase2Line',
  147. 'riWindowLine',
  148. 'riCursorLine',
  149. 'riDownloadLine',
  150. 'riCommandLine',
  151. ];
  152. const blocksArr = Object.entries(tasks).map(([key, block]) => ({
  153. ...block,
  154. id: key,
  155. name: t(`workflow.blocks.${key}.name`),
  156. }));
  157. const query = ref('');
  158. const blocks = computed(() =>
  159. blocksArr.reduce((arr, block) => {
  160. if (
  161. block.name.toLocaleLowerCase().includes(query.value.toLocaleLowerCase())
  162. ) {
  163. (arr[block.category] = arr[block.category] || []).push(block);
  164. }
  165. return arr;
  166. }, {})
  167. );
  168. function updateWorkflowIcon(value) {
  169. if (!value.startsWith('http')) return;
  170. const iconUrl = value.slice(0, 1024);
  171. emit('update', { icon: iconUrl });
  172. }
  173. </script>