WorkflowActions.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <ui-card v-if="!workflow.isProtected" padding="p-1 flex items-center">
  3. <ui-popover>
  4. <template #trigger>
  5. <button
  6. v-tooltip.group="t('workflow.host.title')"
  7. class="hoverable p-2 rounded-lg"
  8. >
  9. <v-remixicon
  10. :class="{ 'text-primary': data.isHost }"
  11. name="riBaseStationLine"
  12. />
  13. </button>
  14. </template>
  15. <div :class="{ 'text-center': data.loadingHost }" class="w-64">
  16. <div class="flex items-center text-gray-600 dark:text-gray-200">
  17. <p>
  18. {{ t('workflow.host.set') }}
  19. </p>
  20. <a
  21. :title="t('common.docs')"
  22. href="https://docs.automa.site/guide/host-workflow.html"
  23. target="_blank"
  24. class="ml-1"
  25. >
  26. <v-remixicon name="riInformationLine" size="20" />
  27. </a>
  28. <div class="flex-grow"></div>
  29. <template v-if="$store.state.user">
  30. <ui-spinner v-if="data.loadingHost" color="text-accent" />
  31. <ui-switch
  32. v-else
  33. :model-value="data.isHost"
  34. @change="$emit('host', $event)"
  35. />
  36. </template>
  37. <ui-switch v-else v-close-popover @click="$emit('host', 'auth')" />
  38. </div>
  39. <transition-expand>
  40. <ui-input
  41. v-if="data.isHost"
  42. v-tooltip:bottom="t('workflow.host.id')"
  43. :model-value="host.hostId"
  44. prepend-icon="riLinkM"
  45. readonly
  46. class="mt-4 block w-full"
  47. @click="$event.target.select()"
  48. />
  49. </transition-expand>
  50. </div>
  51. </ui-popover>
  52. <button
  53. v-tooltip.group="t('workflow.share.title')"
  54. :class="{ 'text-primary': data.hasShared }"
  55. class="hoverable p-2 rounded-lg"
  56. @click="$emit('share')"
  57. >
  58. <v-remixicon name="riShareLine" />
  59. </button>
  60. </ui-card>
  61. <ui-card padding="p-1 ml-4">
  62. <button
  63. v-for="item in modalActions"
  64. :key="item.id"
  65. v-tooltip.group="item.name"
  66. class="hoverable p-2 rounded-lg"
  67. @click="$emit('showModal', item.id)"
  68. >
  69. <v-remixicon :name="item.icon" />
  70. </button>
  71. </ui-card>
  72. <ui-card padding="p-1 ml-4 flex items-center">
  73. <button
  74. v-if="!workflow.isDisabled"
  75. v-tooltip.group="
  76. `${t('common.execute')} (${
  77. shortcuts['editor:execute-workflow'].readable
  78. })`
  79. "
  80. class="hoverable p-2 rounded-lg"
  81. @click="$emit('execute')"
  82. >
  83. <v-remixicon name="riPlayLine" />
  84. </button>
  85. <button
  86. v-else
  87. v-tooltip="t('workflow.clickToEnable')"
  88. class="p-2"
  89. @click="$emit('update', { isDisabled: false })"
  90. >
  91. {{ t('common.disabled') }}
  92. </button>
  93. </ui-card>
  94. <ui-card padding="p-1 ml-4 space-x-1">
  95. <ui-popover>
  96. <template #trigger>
  97. <button class="rounded-lg p-2 hoverable">
  98. <v-remixicon name="riMore2Line" />
  99. </button>
  100. </template>
  101. <ui-list class="w-36">
  102. <ui-list-item
  103. class="cursor-pointer"
  104. @click="$emit('update', { isDisabled: !workflow.isDisabled })"
  105. >
  106. <v-remixicon name="riToggleLine" class="mr-2 -ml-1" />
  107. {{ t(`common.${workflow.isDisabled ? 'enable' : 'disable'}`) }}
  108. </ui-list-item>
  109. <ui-list-item
  110. v-for="item in moreActions"
  111. :key="item.id"
  112. v-close-popover
  113. class="cursor-pointer"
  114. @click="$emit(item.id)"
  115. >
  116. <v-remixicon :name="item.icon" class="mr-2 -ml-1" />
  117. {{ item.name }}
  118. </ui-list-item>
  119. </ui-list>
  120. </ui-popover>
  121. <ui-button
  122. :title="shortcuts['editor:save'].readable"
  123. variant="accent"
  124. class="relative"
  125. @click="$emit('save')"
  126. >
  127. <span
  128. v-if="isDataChanged"
  129. class="flex h-3 w-3 absolute top-0 left-0 -ml-1 -mt-1"
  130. >
  131. <span
  132. class="animate-ping absolute inline-flex h-full w-full rounded-full bg-primary opacity-75"
  133. ></span>
  134. <span
  135. class="relative inline-flex rounded-full h-3 w-3 bg-blue-600"
  136. ></span>
  137. </span>
  138. <v-remixicon name="riSaveLine" class="mr-2 -ml-1 my-1" />
  139. {{ t('common.save') }}
  140. </ui-button>
  141. </ui-card>
  142. </template>
  143. <script setup>
  144. import { useI18n } from 'vue-i18n';
  145. import { useGroupTooltip } from '@/composable/groupTooltip';
  146. import { useShortcut, getShortcut } from '@/composable/shortcut';
  147. defineProps({
  148. isDataChanged: {
  149. type: Boolean,
  150. default: false,
  151. },
  152. workflow: {
  153. type: Object,
  154. default: () => ({}),
  155. },
  156. host: {
  157. type: Object,
  158. default: () => ({}),
  159. },
  160. data: {
  161. type: Object,
  162. default: () => ({}),
  163. },
  164. });
  165. const emit = defineEmits([
  166. 'showModal',
  167. 'execute',
  168. 'rename',
  169. 'delete',
  170. 'save',
  171. 'export',
  172. 'update',
  173. 'share',
  174. 'host',
  175. ]);
  176. useGroupTooltip();
  177. const { t } = useI18n();
  178. const shortcuts = useShortcut(
  179. [
  180. getShortcut('editor:save', 'save'),
  181. getShortcut('editor:execute-workflow', 'execute'),
  182. ],
  183. ({ data }) => {
  184. emit(data);
  185. }
  186. );
  187. const modalActions = [
  188. {
  189. id: 'table',
  190. name: t('workflow.table.title'),
  191. icon: 'riTable2',
  192. },
  193. {
  194. id: 'global-data',
  195. name: t('common.globalData'),
  196. icon: 'riDatabase2Line',
  197. },
  198. {
  199. id: 'settings',
  200. name: t('common.settings'),
  201. icon: 'riSettings3Line',
  202. },
  203. ];
  204. const moreActions = [
  205. {
  206. id: 'export',
  207. name: t('common.export'),
  208. icon: 'riDownloadLine',
  209. },
  210. {
  211. id: 'rename',
  212. name: t('common.rename'),
  213. icon: 'riPencilLine',
  214. },
  215. {
  216. id: 'delete',
  217. name: t('common.delete'),
  218. icon: 'riDeleteBin7Line',
  219. },
  220. ];
  221. </script>