From 7bdbf2500f628a8765de9c54160a34a6bfaecfb8 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 27 Jul 2022 16:36:04 +0800 Subject: [PATCH] refactor: plugin list item component Signed-off-by: Ryan Wang --- src/modules/system/plugins/PluginList.vue | 145 +----------------- .../plugins/components/PluginListItem.vue | 136 ++++++++++++++++ .../system/plugins/composables/use-plugin.ts | 8 + 3 files changed, 146 insertions(+), 143 deletions(-) create mode 100644 src/modules/system/plugins/components/PluginListItem.vue diff --git a/src/modules/system/plugins/PluginList.vue b/src/modules/system/plugins/PluginList.vue index a3bd66d9..987646d7 100644 --- a/src/modules/system/plugins/PluginList.vue +++ b/src/modules/system/plugins/PluginList.vue @@ -3,30 +3,21 @@ import { IconAddCircle, IconArrowDown, IconPlug, - IconSettings, VButton, VCard, VPageHeader, VPagination, VSpace, - VSwitch, VTag, } from "@halo-dev/components"; +import PluginListItem from "./components/PluginListItem.vue"; import PluginInstallModal from "./components/PluginInstallModal.vue"; import { onMounted, ref } from "vue"; import { apiClient } from "@halo-dev/admin-shared"; import type { Plugin } from "@halo-dev/api-client"; -import { usePluginLifeCycle } from "./composables/use-plugin"; const plugins = ref([] as Plugin[]); const pluginInstall = ref(false); -const selectedPlugin = ref(null); - -const { changeStatus, uninstall } = usePluginLifeCycle(selectedPlugin); - -const isStarted = (plugin: Plugin) => { - return plugin.status?.phase === "STARTED" && plugin.spec.enabled; -}; const handleFetchPlugins = async () => { try { @@ -38,16 +29,6 @@ const handleFetchPlugins = async () => { } }; -function handleChangeStatus(plugin: Plugin) { - selectedPlugin.value = plugin; - changeStatus(); -} - -function handleUninstall(plugin: Plugin) { - selectedPlugin.value = plugin; - uninstall(); -} - onMounted(handleFetchPlugins);
  • -
    -
    -
    - -
    - -
    -
    -
    -
    -
    - - - {{ plugin.spec.displayName }} - - - - - {{ isStarted(plugin) ? "已启用" : "未启用" }} - - -
    -
    - - - {{ plugin.spec.description }} - - - @{{ plugin.spec.author }} {{ plugin.spec.version }} - - -
    -
    -
    -
    - - - - -
    - -
    - - - - - - -
    -
    -
    -
    +
diff --git a/src/modules/system/plugins/components/PluginListItem.vue b/src/modules/system/plugins/components/PluginListItem.vue new file mode 100644 index 00000000..2916c18a --- /dev/null +++ b/src/modules/system/plugins/components/PluginListItem.vue @@ -0,0 +1,136 @@ + + diff --git a/src/modules/system/plugins/composables/use-plugin.ts b/src/modules/system/plugins/composables/use-plugin.ts index 43a5d007..523e6190 100644 --- a/src/modules/system/plugins/composables/use-plugin.ts +++ b/src/modules/system/plugins/composables/use-plugin.ts @@ -1,4 +1,5 @@ import type { Ref } from "vue"; +import { computed } from "vue"; import type { Plugin } from "@halo-dev/api-client"; import cloneDeep from "lodash.clonedeep"; import { apiClient } from "@halo-dev/admin-shared"; @@ -7,6 +8,12 @@ import { useDialog } from "@halo-dev/components"; export function usePluginLifeCycle(plugin: Ref) { const dialog = useDialog(); + const isStarted = computed(() => { + return ( + plugin.value?.status?.phase === "STARTED" && plugin.value?.spec.enabled + ); + }); + const changeStatus = () => { if (!plugin.value) return; @@ -68,6 +75,7 @@ export function usePluginLifeCycle(plugin: Ref) { }; return { + isStarted, changeStatus, uninstall, };