diff --git a/package.json b/package.json index 3ea102d0..ffd1b86d 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.25", + "@halo-dev/api-client": "^0.0.26", "@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 61bf994c..fc24bf5f 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.25 + '@halo-dev/api-client': ^0.0.26 '@halo-dev/components': workspace:* '@halo-dev/richtext-editor': ^0.0.0-alpha.7 '@iconify-json/mdi': ^1.1.33 @@ -100,7 +100,7 @@ importers: '@formkit/themes': 1.0.0-beta.10_tailwindcss@3.1.8 '@formkit/vue': 1.0.0-beta.10_jhzixbi2r7n2xnmwczrcaimaey '@halo-dev/admin-shared': link:packages/shared - '@halo-dev/api-client': 0.0.25 + '@halo-dev/api-client': 0.0.26 '@halo-dev/components': link:packages/components '@halo-dev/richtext-editor': 0.0.0-alpha.7_vue@3.2.39 '@tiptap/extension-character-count': 2.0.0-beta.31 @@ -1892,8 +1892,8 @@ packages: - windicss dev: false - /@halo-dev/api-client/0.0.25: - resolution: {integrity: sha512-USCCsKam7wH6vExP3SrTBz+vvOndRWPek2CZSfv0FeE8T+TNDR/X/wNRy3BPl//O0wf7TkJUgFyhgbRf+z02YA==} + /@halo-dev/api-client/0.0.26: + resolution: {integrity: sha512-MSyl2wF3KXSQSYWuqdBcaBgct1RzcQAS9HcLL1oBb0lDLjlUgZv6IEANpPZS80UN0bQjvsGl9JOnqwoIUKUK8A==} dev: false /@halo-dev/richtext-editor/0.0.0-alpha.7_vue@3.2.39: diff --git a/src/modules/contents/posts/PostList.vue b/src/modules/contents/posts/PostList.vue index 60d48b5f..ef040d96 100644 --- a/src/modules/contents/posts/PostList.vue +++ b/src/modules/contents/posts/PostList.vue @@ -37,7 +37,6 @@ import { apiClient } from "@/utils/api-client"; import { formatDatetime } from "@/utils/date"; import { usePostCategory } from "@/modules/contents/posts/categories/composables/use-post-category"; import { usePostTag } from "@/modules/contents/posts/tags/composables/use-post-tag"; -import { postLabels } from "@/constants/labels"; enum PostPhase { DRAFT = "未发布", @@ -62,51 +61,42 @@ const selectedPostWithContent = ref(null); const checkedAll = ref(false); const selectedPostNames = ref([]); -const { categories } = usePostCategory({ fetchOnMounted: true }); -const { tags } = usePostTag({ fetchOnMounted: true }); const dialog = useDialog(); const handleFetchPosts = async () => { try { loading.value = true; - const labelSelector: string[] = []; - - if (selectedVisibleFilterItem.value.value) { - labelSelector.push( - `${postLabels.VISIBLE}=${selectedVisibleFilterItem.value.value}` - ); - } - - if (selectedPhaseFilterItem.value.value) { - labelSelector.push( - `${postLabels.PHASE}=${selectedPhaseFilterItem.value.value}` - ); - } - let categories: string[] | undefined; let tags: string[] | undefined; let contributors: string[] | undefined; - if (selectedCategoryFilterItem.value) { - categories = [selectedCategoryFilterItem.value.metadata.name]; + if (selectedCategory.value) { + categories = [ + selectedCategory.value.metadata.name, + selectedCategory.value.metadata.name, + ]; } - if (selectedTagFilterItem.value) { - tags = [selectedTagFilterItem.value.metadata.name]; + if (selectedTag.value) { + tags = [selectedTag.value.metadata.name]; } - if (selectedContributorItem.value) { - contributors = [selectedContributorItem.value.metadata.name]; + if (selectedContributor.value) { + contributors = [selectedContributor.value.metadata.name]; } const { data } = await apiClient.post.listPosts({ page: posts.value.page, size: posts.value.size, - labelSelector, - categories, - tags, - contributors, + visible: selectedVisibleItem.value?.value, + publishPhase: selectedPublishPhaseItem.value?.value, + sort: selectedSortItem.value?.sort, + sortOrder: selectedSortItem.value?.sortOrder, + keyword: keyword.value, + category: categories, + tag: tags, + contributor: contributors, }); posts.value = data; } catch (e) { @@ -265,15 +255,28 @@ onMounted(() => { handleFetchPosts(); }); -interface FilterItem { +// Filters + +interface VisibleItem { label: string; - value: string | undefined; + value?: "PUBLIC" | "INTERNAL" | "PRIVATE"; } -const VisibleFilterItems: FilterItem[] = [ +interface PublishPhaseItem { + label: string; + value?: "DRAFT" | "PENDING_APPROVAL" | "PUBLISHED"; +} + +interface SortItem { + label: string; + sort: "PUBLISH_TIME" | "CREATE_TIME"; + sortOrder: boolean; +} + +const VisibleItems: VisibleItem[] = [ { label: "全部", - value: "", + value: undefined, }, { label: "公开", @@ -289,10 +292,10 @@ const VisibleFilterItems: FilterItem[] = [ }, ]; -const PhaseFilterItems: FilterItem[] = [ +const PublishPhaseItems: PublishPhaseItem[] = [ { label: "全部", - value: "", + value: undefined, }, { label: "已发布", @@ -308,34 +311,67 @@ const PhaseFilterItems: FilterItem[] = [ }, ]; -const selectedVisibleFilterItem = ref(VisibleFilterItems[0]); -const selectedPhaseFilterItem = ref(PhaseFilterItems[0]); -const selectedCategoryFilterItem = ref(); -const selectedTagFilterItem = ref(); -const selectedContributorItem = ref(); +const SortItems: SortItem[] = [ + { + label: "较近发布", + sort: "PUBLISH_TIME", + sortOrder: false, + }, + { + label: "较早发布", + sort: "PUBLISH_TIME", + sortOrder: true, + }, + { + label: "较近创建", + sort: "CREATE_TIME", + sortOrder: false, + }, + { + label: "较早创建", + sort: "CREATE_TIME", + sortOrder: true, + }, +]; -function handleVisibleFilterItemChange(filterItem: FilterItem) { - selectedVisibleFilterItem.value = filterItem; +const { categories } = usePostCategory({ fetchOnMounted: true }); +const { tags } = usePostTag({ fetchOnMounted: true }); + +const selectedVisibleItem = ref(VisibleItems[0]); +const selectedPublishPhaseItem = ref(PublishPhaseItems[0]); +const selectedSortItem = ref(); +const selectedCategory = ref(); +const selectedTag = ref(); +const selectedContributor = ref(); +const keyword = ref(""); + +function handleVisibleItemChange(visibleItem: VisibleItem) { + selectedVisibleItem.value = visibleItem; handleFetchPosts(); } -function handlePhaseFilterItemChange(filterItem: FilterItem) { - selectedPhaseFilterItem.value = filterItem; +function handlePublishPhaseItemChange(publishPhaseItem: PublishPhaseItem) { + selectedPublishPhaseItem.value = publishPhaseItem; handleFetchPosts(); } -function handleCategoryFilterItemChange(category?: Category) { - selectedCategoryFilterItem.value = category; +function handleSortItemChange(sortItem?: SortItem) { + selectedSortItem.value = sortItem; handleFetchPosts(); } -function handleTagFilterItemChange(tag?: Tag) { - selectedTagFilterItem.value = tag; +function handleCategoryChange(category?: Category) { + selectedCategory.value = category; handleFetchPosts(); } -function handleContributorFilterItemChange(user?: User) { - selectedContributorItem.value = user; +function handleTagChange(tag?: Tag) { + selectedTag.value = tag; + handleFetchPosts(); +} + +function handleContributorChange(user?: User) { + selectedContributor.value = user; handleFetchPosts(); } @@ -392,69 +428,84 @@ function handleContributorFilterItemChange(user?: User) { v-if="!selectedPostNames.length" class="flex items-center gap-2" > - +
- 状态:{{ selectedPhaseFilterItem.label }} + 状态:{{ selectedPublishPhaseItem.label }}
- 可见性:{{ selectedVisibleFilterItem.label }} + 可见性:{{ selectedVisibleItem.label }}
- 分类:{{ selectedCategoryFilterItem.spec.displayName }} + 分类:{{ selectedCategory.spec.displayName }}
- 标签:{{ selectedTagFilterItem.spec.displayName }} + 标签:{{ selectedTag.spec.displayName }}
- 标签:{{ selectedContributorItem.spec.displayName }} + 作者:{{ selectedContributor.spec.displayName }} +
+
+ + 排序:{{ selectedSortItem.label }} + +
@@ -479,16 +530,16 @@ function handleContributorFilterItemChange(user?: User) {
  • {{ filterItem.label }}
  • @@ -509,16 +560,15 @@ function handleContributorFilterItemChange(user?: User) {
    • {{ filterItem.label }} @@ -553,13 +603,13 @@ function handleContributorFilterItemChange(user?: User) { v-for="(category, index) in categories" :key="index" v-close-popper - @click="handleCategoryFilterItemChange(category)" + @click="handleCategoryChange(category)" >
      @@ -626,13 +676,13 @@ function handleContributorFilterItemChange(user?: User) { v-for="(tag, index) in tags" :key="index" v-close-popper - @click="handleTagFilterItemChange(tag)" + @click="handleTagChange(tag)" >
      @@ -668,8 +718,8 @@ function handleContributorFilterItemChange(user?: User) {
      • - 较近发布 -
      • -
      • - 较晚发布 -
      • -
      • - 浏览量最多 -
      • -
      • - 浏览量最少 -
      • -
      • - 评论量最多 -
      • -
      • - 评论量最少 + {{ sortItem.label }}