refactor: plugin enable/disable api

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/588/head
Ryan Wang 2022-07-07 17:05:46 +08:00
parent d15c1636bd
commit 70f7b522f1
2 changed files with 8 additions and 10 deletions

View File

@ -14,7 +14,7 @@ import type { Plugin } from "@/types/extension";
import { axiosInstance } from "@halo-dev/admin-shared"; import { axiosInstance } from "@halo-dev/admin-shared";
const pluginActiveId = ref("detail"); const pluginActiveId = ref("detail");
const plugin = ref<Plugin>(); const plugin = ref<Plugin>({} as Plugin);
const { params } = useRoute(); const { params } = useRoute();
@ -30,17 +30,15 @@ const handleFetchPlugin = async () => {
}; };
const isStarted = computed(() => { const isStarted = computed(() => {
return ( return plugin.value.status?.phase === "STARTED" && plugin.value.spec.enabled;
plugin.value?.status?.phase === "STARTED" && plugin.value?.spec.enabled
);
}); });
const handleChangePluginStatus = async () => { const handleChangePluginStatus = async () => {
try { try {
plugin.value.spec.enabled = !plugin.value.spec.enabled;
await axiosInstance.put( await axiosInstance.put(
`/apis/plugin.halo.run/v1alpha1/plugins/${plugin.value?.metadata.name}/${ `/apis/plugin.halo.run/v1alpha1/plugins/${plugin.value.metadata.name}`,
isStarted.value ? "stop" : "startup" plugin.value
}`
); );
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -45,10 +45,10 @@ const handleFetchPlugins = async () => {
const handleChangePluginStatus = async (plugin: Plugin) => { const handleChangePluginStatus = async (plugin: Plugin) => {
try { try {
plugin.spec.enabled = !plugin.spec.enabled;
await axiosInstance.put( await axiosInstance.put(
`/apis/plugin.halo.run/v1alpha1/plugins/${plugin.metadata.name}/${ `/apis/plugin.halo.run/v1alpha1/plugins/${plugin.metadata.name}`,
isStarted(plugin) ? "stop" : "startup" plugin
}`
); );
} catch (e) { } catch (e) {
console.error(e); console.error(e);