mirror of
https://github.com/halo-dev/halo.git
synced 2025-12-20 16:44:38 +08:00
feat: show the startup status of the plugin (#5520)
#### What type of PR is this? /area ui /kind feature /milestone 2.14.x #### What this PR does / why we need it: Show the startup status of the plugin <img width="444" alt="image" src="https://github.com/halo-dev/halo/assets/21301288/0f5d47c2-9d81-4cb7-b114-6b2eebe753c5"> #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/5254 #### Does this PR introduce a user-facing change? ```release-note 插件支持显示启动中的状态。 ```
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { ComputedRef, Ref } from "vue";
|
||||
import { computed } from "vue";
|
||||
import { type Plugin } from "@halo-dev/api-client";
|
||||
import { type Plugin, PluginStatusPhaseEnum } from "@halo-dev/api-client";
|
||||
import { cloneDeep } from "lodash-es";
|
||||
import { apiClient } from "@/utils/api-client";
|
||||
import { Dialog, Toast } from "@halo-dev/components";
|
||||
@@ -9,7 +9,7 @@ import { useMutation } from "@tanstack/vue-query";
|
||||
|
||||
interface usePluginLifeCycleReturn {
|
||||
isStarted: ComputedRef<boolean | undefined>;
|
||||
getFailedMessage: () => string | undefined;
|
||||
getStatusMessage: () => string | undefined;
|
||||
changeStatus: () => void;
|
||||
changingStatus: Ref<boolean>;
|
||||
uninstall: (deleteExtensions?: boolean) => void;
|
||||
@@ -22,18 +22,33 @@ export function usePluginLifeCycle(
|
||||
|
||||
const isStarted = computed(() => {
|
||||
return (
|
||||
plugin?.value?.status?.phase === "STARTED" && plugin.value?.spec.enabled
|
||||
plugin?.value?.status?.phase === PluginStatusPhaseEnum.Started &&
|
||||
plugin.value?.spec.enabled
|
||||
);
|
||||
});
|
||||
|
||||
const getFailedMessage = () => {
|
||||
const getStatusMessage = () => {
|
||||
if (!plugin?.value) return;
|
||||
|
||||
const { enabled } = plugin.value.spec || {};
|
||||
const { phase } = plugin.value.status || {};
|
||||
|
||||
// Starting up
|
||||
if (
|
||||
enabled &&
|
||||
phase !== (PluginStatusPhaseEnum.Started || PluginStatusPhaseEnum.Failed)
|
||||
) {
|
||||
return t("core.common.status.starting_up");
|
||||
}
|
||||
|
||||
// Starting failed
|
||||
if (!isStarted.value) {
|
||||
const lastCondition = plugin.value.status?.conditions?.[0];
|
||||
|
||||
return (
|
||||
[lastCondition?.reason, lastCondition?.message].join(":") || "Unknown"
|
||||
[lastCondition?.reason, lastCondition?.message]
|
||||
.filter(Boolean)
|
||||
.join(":") || "Unknown"
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -138,7 +153,7 @@ export function usePluginLifeCycle(
|
||||
|
||||
return {
|
||||
isStarted,
|
||||
getFailedMessage,
|
||||
getStatusMessage,
|
||||
changeStatus,
|
||||
changingStatus,
|
||||
uninstall,
|
||||
|
||||
Reference in New Issue
Block a user