diff --git a/package.json b/package.json index c7041022..263abc23 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@formkit/themes": "1.0.0-beta.10", "@formkit/vue": "1.0.0-beta.10", "@halo-dev/admin-shared": "workspace:*", - "@halo-dev/api-client": "^0.0.33", + "@halo-dev/api-client": "^0.0.34", "@halo-dev/components": "workspace:*", "@halo-dev/richtext-editor": "^0.0.0-alpha.7", "@tiptap/extension-character-count": "2.0.0-beta.31", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd97acc8..f1aaf099 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,7 +14,7 @@ importers: '@formkit/themes': 1.0.0-beta.10 '@formkit/vue': 1.0.0-beta.10 '@halo-dev/admin-shared': workspace:* - '@halo-dev/api-client': ^0.0.33 + '@halo-dev/api-client': ^0.0.34 '@halo-dev/components': workspace:* '@halo-dev/richtext-editor': ^0.0.0-alpha.7 '@iconify-json/mdi': ^1.1.33 @@ -101,7 +101,7 @@ importers: '@formkit/themes': 1.0.0-beta.10_tailwindcss@3.1.8 '@formkit/vue': 1.0.0-beta.10_k5hp3txgeyj6le63abiyc7wx3u '@halo-dev/admin-shared': link:packages/shared - '@halo-dev/api-client': 0.0.33 + '@halo-dev/api-client': 0.0.34 '@halo-dev/components': link:packages/components '@halo-dev/richtext-editor': 0.0.0-alpha.7_vue@3.2.40 '@tiptap/extension-character-count': 2.0.0-beta.31 @@ -1886,8 +1886,8 @@ packages: - windicss dev: false - /@halo-dev/api-client/0.0.33: - resolution: {integrity: sha512-L0U11BO0rInJ49JjH/aynFFj28+vnBDXtDKDMNCnaZNo4ijweqdU8q4S6lUo6okGbznYlZ9fWDPDHvS7EKqHKA==} + /@halo-dev/api-client/0.0.34: + resolution: {integrity: sha512-WOEbyRjPSASH1tyQjQQU/RjXKtRPSD+L6erAWLUfy7BIsyCAMSBdkF3auBWaevUt08uyCBeI3ln+sP+VPyFM0A==} dev: false /@halo-dev/richtext-editor/0.0.0-alpha.7_vue@3.2.40: diff --git a/src/modules/system/plugins/PluginList.vue b/src/modules/system/plugins/PluginList.vue index bd0c025d..4f3f7db0 100644 --- a/src/modules/system/plugins/PluginList.vue +++ b/src/modules/system/plugins/PluginList.vue @@ -2,6 +2,7 @@ import { IconAddCircle, IconArrowDown, + IconCloseCircle, IconPlug, VButton, VCard, @@ -9,15 +10,23 @@ import { VPageHeader, VPagination, VSpace, - VTag, } from "@halo-dev/components"; import PluginListItem from "./components/PluginListItem.vue"; import PluginInstallModal from "./components/PluginInstallModal.vue"; -import { onMounted, ref, watch } from "vue"; +import { onMounted, ref } from "vue"; import { apiClient } from "@/utils/api-client"; -import type { Plugin } from "@halo-dev/api-client"; +import type { PluginList } from "@halo-dev/api-client"; -const plugins = ref([] as Plugin[]); +const plugins = ref({ + page: 1, + size: 20, + total: 0, + items: [], + first: true, + last: false, + hasNext: false, + hasPrevious: false, +}); const loading = ref(false); const pluginInstall = ref(false); const keyword = ref(""); @@ -26,34 +35,87 @@ const handleFetchPlugins = async () => { try { loading.value = true; - const fieldSelector: Array = []; + const { data } = await apiClient.plugin.listPlugins({ + page: plugins.value.page, + size: plugins.value.size, + keyword: keyword.value, + enabled: selectedEnabledItem.value?.value, + sort: [selectedSortItem.value?.value].filter( + (item) => !!item + ) as string[], + }); - if (keyword.value) { - fieldSelector.push(`name=${keyword.value}`); - } - - const { data } = - await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin({ - page: 0, - size: 0, - fieldSelector, - }); - plugins.value = data.items; + plugins.value = data; } catch (e) { - console.error("Fail to fetch plugins", e); + console.error("Failed to fetch plugins", e); } finally { loading.value = false; } }; -watch( - () => keyword.value, - () => { - handleFetchPlugins(); - } -); +const handlePaginationChange = ({ + page, + size, +}: { + page: number; + size: number; +}) => { + plugins.value.page = page; + plugins.value.size = size; + handleFetchPlugins(); +}; onMounted(handleFetchPlugins); + +// Filters +interface EnabledItem { + label: string; + value?: boolean; +} + +interface SortItem { + label: string; + value: string; +} + +const EnabledItems: EnabledItem[] = [ + { + label: "全部", + value: undefined, + }, + { + label: "已启用", + value: true, + }, + { + label: "未启用", + value: false, + }, +]; + +const SortItems: SortItem[] = [ + { + label: "较近安装", + value: "creationTimestamp,desc", + }, + { + label: "较早安装", + value: "creationTimestamp,asc", + }, +]; + +const selectedEnabledItem = ref(); +const selectedSortItem = ref(); + +function handleEnabledItemChange(enabledItem: EnabledItem) { + selectedEnabledItem.value = enabledItem; + handleFetchPlugins(); +} + +function handleSortItemChange(sortItem?: SortItem) { + selectedSortItem.value = sortItem; + handleFetchPlugins(); +} -
- 类别 - - - -
- -
- 提供方 - - - -
- -
  • - 较近安装 -
  • -
  • - 较晚安装 + {{ sortItem.label }}
@@ -222,7 +246,7 @@ onMounted(handleFetchPlugins); @@ -248,14 +272,20 @@ onMounted(handleFetchPlugins); class="box-border h-full w-full divide-y divide-gray-100" role="list" > -
  • +