diff --git a/console/src/locales/en.yaml b/console/src/locales/en.yaml index 745358719..bd7fa9bc4 100644 --- a/console/src/locales/en.yaml +++ b/console/src/locales/en.yaml @@ -736,9 +736,6 @@ core: uninstall_when_enabled: confirm_text: Stop running and uninstall description: The current plugin is still in the enabled state and will be uninstalled after it stops running. This operation cannot be undone. - change_status: - active_title: Are you sure you want to active this plugin? - inactive_title: Are you sure you want to inactive this plugin? remote_download: title: Remote download address detected, do you want to download? description: "Please carefully verify whether this address can be trusted: {url}" diff --git a/console/src/locales/zh-CN.yaml b/console/src/locales/zh-CN.yaml index a4b19a273..21abecdad 100644 --- a/console/src/locales/zh-CN.yaml +++ b/console/src/locales/zh-CN.yaml @@ -736,9 +736,6 @@ core: uninstall_when_enabled: confirm_text: 停止运行并卸载 description: 当前插件还在启用状态,将在停止运行后卸载,该操作不可恢复。 - change_status: - active_title: 确定要启用该插件吗? - inactive_title: 确定要停用该插件吗? remote_download: title: 检测到了远程下载地址,是否需要下载? description: 请仔细鉴别此地址是否可信:{url} diff --git a/console/src/locales/zh-TW.yaml b/console/src/locales/zh-TW.yaml index bd043c506..6b7477519 100644 --- a/console/src/locales/zh-TW.yaml +++ b/console/src/locales/zh-TW.yaml @@ -736,9 +736,6 @@ core: uninstall_when_enabled: confirm_text: 停止運行並卸載 description: 當前插件還在啟用狀態,將在停止運行後卸載,該操作不可恢復。 - change_status: - active_title: 確定要啟用該插件嗎? - inactive_title: 確定要停用該插件嗎? remote_download: title: 偵測到遠端下載地址,是否需要下載? description: 請仔細鑑別此地址是否可信:{url} diff --git a/console/src/modules/system/plugins/components/PluginListItem.vue b/console/src/modules/system/plugins/components/PluginListItem.vue index d90d34869..1741f462e 100644 --- a/console/src/modules/system/plugins/components/PluginListItem.vue +++ b/console/src/modules/system/plugins/components/PluginListItem.vue @@ -40,7 +40,7 @@ const emit = defineEmits<{ const { plugin } = toRefs(props); -const { getFailedMessage, changeStatus, uninstall } = +const { getFailedMessage, changeStatus, changingStatus, uninstall } = usePluginLifeCycle(plugin); const handleResetSettingConfig = async () => { @@ -205,6 +205,7 @@ const { dropdownItems } = useEntityDropdownItemExtensionPoint(
diff --git a/console/src/modules/system/plugins/composables/use-plugin.ts b/console/src/modules/system/plugins/composables/use-plugin.ts index de3bffec2..7605592a6 100644 --- a/console/src/modules/system/plugins/composables/use-plugin.ts +++ b/console/src/modules/system/plugins/composables/use-plugin.ts @@ -1,5 +1,5 @@ import type { ComputedRef, Ref } from "vue"; -import { computed } from "vue"; +import { computed, ref } from "vue"; import type { Plugin } from "@halo-dev/api-client"; import cloneDeep from "lodash.clonedeep"; import { apiClient } from "@/utils/api-client"; @@ -10,6 +10,7 @@ interface usePluginLifeCycleReturn { isStarted: ComputedRef; getFailedMessage: () => string | undefined; changeStatus: () => void; + changingStatus: Ref; uninstall: (deleteExtensions?: boolean) => void; } @@ -36,37 +37,25 @@ export function usePluginLifeCycle( } }; - const changeStatus = () => { + const changingStatus = ref(false); + + const changeStatus = async () => { if (!plugin?.value) return; - const pluginToUpdate = cloneDeep(plugin.value); + try { + changingStatus.value = true; + const pluginToUpdate = cloneDeep(plugin.value); + pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled; + await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({ + name: pluginToUpdate.metadata.name, + plugin: pluginToUpdate, + }); - Dialog.info({ - title: pluginToUpdate.spec.enabled - ? t("core.plugin.operations.change_status.inactive_title") - : t("core.plugin.operations.change_status.active_title"), - confirmText: t("core.common.buttons.confirm"), - cancelText: t("core.common.buttons.cancel"), - onConfirm: async () => { - try { - pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled; - await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({ - name: pluginToUpdate.metadata.name, - plugin: pluginToUpdate, - }); - - Toast.success( - pluginToUpdate.spec.enabled - ? t("core.common.toast.active_success") - : t("core.common.toast.inactive_success") - ); - } catch (e) { - console.error(e); - } finally { - window.location.reload(); - } - }, - }); + window.location.reload(); + } catch (e) { + console.error(e); + changingStatus.value = false; + } }; const uninstall = (deleteExtensions?: boolean) => { @@ -150,6 +139,7 @@ export function usePluginLifeCycle( isStarted, getFailedMessage, changeStatus, + changingStatus, uninstall, }; }