SettingsGeneral.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <div class="flex items-center">
  3. <div class="mr-4 flex-1">
  4. <p>
  5. {{ t('workflow.settings.onError.title') }}
  6. </p>
  7. <p class="text-gray-600 dark:text-gray-200 text-sm leading-tight">
  8. {{ t('workflow.settings.onError.description') }}
  9. </p>
  10. </div>
  11. <ui-select
  12. :model-value="settings.onError"
  13. @change="updateSetting('onError', $event)"
  14. >
  15. <option v-for="item in onError" :key="item.id" :value="item.id">
  16. {{ t(`workflow.settings.onError.items.${item.name}`) }}
  17. </option>
  18. </ui-select>
  19. <div
  20. v-if="settings.onError === 'restart-workflow'"
  21. :title="t('workflow.settings.restartWorkflow.description')"
  22. class="flex items-center bg-input transition-colors rounded-lg ml-4"
  23. >
  24. <input
  25. :value="settings.restartTimes ?? 3"
  26. type="number"
  27. class="py-2 pl-2 text-right appearance-none w-12 rounded-lg bg-transparent"
  28. @input="updateSetting('restartTimes', +($event.target.value ?? 3))"
  29. />
  30. <span class="px-2 text-sm">
  31. {{ t('workflow.settings.restartWorkflow.times') }}
  32. </span>
  33. </div>
  34. </div>
  35. <div class="flex items-center pt-4">
  36. <div class="mr-4 flex-1">
  37. <p>
  38. {{ t('workflow.settings.notification.title') }}
  39. </p>
  40. <p class="text-gray-600 dark:text-gray-200 text-sm leading-tight">
  41. {{
  42. t(
  43. `workflow.settings.notification.${
  44. permissions.has.notifications ? 'description' : 'noPermission'
  45. }`
  46. )
  47. }}
  48. </p>
  49. </div>
  50. <ui-switch
  51. v-if="permissions.has.notifications"
  52. :model-value="settings.notification"
  53. @change="updateSetting('notification', $event)"
  54. />
  55. <ui-button v-else @click="permissions.request(true)">
  56. {{ t('workflow.blocks.clipboard.grantPermission') }}
  57. </ui-button>
  58. </div>
  59. <div
  60. v-for="item in settingItems"
  61. :key="item.id"
  62. class="flex items-center pt-4"
  63. >
  64. <div class="mr-4 flex-1">
  65. <p>
  66. {{ item.name }}
  67. </p>
  68. <p
  69. v-if="item.notSupport?.includes(browserType)"
  70. class="text-sm leading-tight text-red-400 dark:text-red-300"
  71. >
  72. {{
  73. t('log.messages.browser-not-supported', {
  74. browser: browserType,
  75. })
  76. }}
  77. </p>
  78. <p v-else class="text-gray-600 dark:text-gray-200 text-sm leading-tight">
  79. {{ item.description }}
  80. </p>
  81. </div>
  82. <ui-switch
  83. v-if="!item.notSupport?.includes(browserType)"
  84. :model-value="settings[item.id]"
  85. @change="updateSetting(item.id, $event)"
  86. />
  87. </div>
  88. <div class="flex items-center pt-4">
  89. <div class="mr-4 flex-1">
  90. <p>
  91. {{ t('workflow.settings.clearCache.title') }}
  92. </p>
  93. <p class="text-gray-600 dark:text-gray-200 text-sm leading-tight">
  94. {{ t('workflow.settings.clearCache.description') }}
  95. </p>
  96. </div>
  97. <ui-button @click="onClearCacheClick">
  98. {{ t('workflow.settings.clearCache.btn') }}
  99. </ui-button>
  100. </div>
  101. <div class="flex items-center pt-4">
  102. <div class="mr-4 flex-1">
  103. <p>
  104. {{ t('workflow.settings.publicId.title') }}
  105. </p>
  106. <p class="text-gray-600 dark:text-gray-200 text-sm leading-tight">
  107. {{ t('workflow.settings.publicId.description') }}
  108. </p>
  109. </div>
  110. <a
  111. href="https://docs.automa.site/blocks/trigger.html#trigger-using-js-customevent"
  112. target="_blank"
  113. rel="noopener"
  114. class="mr-2 text-gray-600 dark:text-gray-200"
  115. >
  116. <v-remixicon name="riInformationLine" />
  117. </a>
  118. <ui-input
  119. :model-value="settings.publicId"
  120. placeholder="myWorkflowPublicId"
  121. @change="updateSetting('publicId', $event)"
  122. />
  123. </div>
  124. </template>
  125. <script setup>
  126. import { useI18n } from 'vue-i18n';
  127. import { useToast } from 'vue-toastification';
  128. import { clearCache } from '@/utils/helper';
  129. import { useHasPermissions } from '@/composable/hasPermissions';
  130. const props = defineProps({
  131. settings: {
  132. type: Object,
  133. default: () => ({}),
  134. },
  135. });
  136. const emit = defineEmits(['update']);
  137. const { t } = useI18n();
  138. const toast = useToast();
  139. const permissions = useHasPermissions(['notifications']);
  140. const browserType = BROWSER_TYPE;
  141. const onError = [
  142. {
  143. id: 'keep-running',
  144. name: 'keepRunning',
  145. },
  146. {
  147. id: 'stop-workflow',
  148. name: 'stopWorkflow',
  149. },
  150. {
  151. id: 'restart-workflow',
  152. name: 'restartWorkflow',
  153. },
  154. ];
  155. const settingItems = [
  156. {
  157. id: 'debugMode',
  158. notSupport: ['firefox'],
  159. name: t('workflow.settings.debugMode.title'),
  160. description: t('workflow.settings.debugMode.description'),
  161. },
  162. {
  163. id: 'inputAutocomplete',
  164. name: t('workflow.settings.autocomplete.title'),
  165. description: t('workflow.settings.autocomplete.description'),
  166. },
  167. {
  168. id: 'reuseLastState',
  169. name: t('workflow.settings.reuseLastState.title'),
  170. description: t('workflow.settings.reuseLastState.description'),
  171. },
  172. {
  173. id: 'saveLog',
  174. name: t('workflow.settings.saveLog'),
  175. description: '',
  176. },
  177. {
  178. id: 'executedBlockOnWeb',
  179. name: t('workflow.settings.executedBlockOnWeb'),
  180. description: '',
  181. },
  182. ];
  183. async function onClearCacheClick() {
  184. const cacheCleared = await clearCache(props.workflow);
  185. if (cacheCleared) toast(t('workflow.settings.clearCache.info'));
  186. }
  187. function updateSetting(key, value) {
  188. emit('update', { key, value });
  189. }
  190. </script>