From 811f998a45e3e95fff4d90bf4e0fc72a77969f08 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 6 Sep 2022 15:24:11 +0800 Subject: [PATCH] feat: menu items support setting ref relations (halo-dev/console#604) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature /milestone 2.0 #### What this PR does / why we need it: 菜单项支持设置与文章、分类、标签的关联关系。关联之后,当被关联对象有所改变时,同步菜单项更新。适配:https://github.com/halo-dev/halo/pull/2380 > 自定义页面(pageRef)会等到 https://github.com/halo-dev/halo/pull/2381 合并之后再做适配。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2295 #### Screenshots: image image #### Special notes for your reviewer: /hold until https://github.com/halo-dev/halo/pull/2380 merge #### Does this PR introduce a user-facing change? ```release-note None ``` --- package.json | 2 +- packages/shared/package.json | 2 +- pnpm-lock.yaml | 12 +- src/modules/contents/posts/PostList.vue | 4 +- .../posts/categories/CategoryList.vue | 2 +- .../composables/use-post-category.ts | 10 +- .../posts/components/PostSettingModal.vue | 4 +- src/modules/contents/posts/tags/TagList.vue | 4 +- .../posts/tags/composables/use-post-tag.ts | 10 +- .../menus/components/MenuItemEditingModal.vue | 225 ++++++++++++++++-- .../menus/components/MenuItemListItem.vue | 34 ++- 11 files changed, 268 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index 4354b3ea3..b66481d10 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,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.14", + "@halo-dev/api-client": "^0.0.15", "@halo-dev/components": "workspace:*", "@halo-dev/richtext-editor": "^0.0.0-alpha.5", "@tiptap/extension-character-count": "2.0.0-beta.31", diff --git a/packages/shared/package.json b/packages/shared/package.json index 642ab4078..3919a8451 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -38,7 +38,7 @@ "homepage": "https://github.com/halo-dev/halo-admin/tree/next/shared/components#readme", "license": "MIT", "dependencies": { - "@halo-dev/api-client": "^0.0.14", + "@halo-dev/api-client": "^0.0.15", "@halo-dev/components": "workspace:*", "axios": "^0.27.2", "lodash.merge": "^4.6.2" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 86fb0c963..8f05b8f2f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,7 +13,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.14 + '@halo-dev/api-client': ^0.0.15 '@halo-dev/components': workspace:* '@halo-dev/richtext-editor': ^0.0.0-alpha.5 '@iconify-json/vscode-icons': ^1.1.11 @@ -92,7 +92,7 @@ importers: '@formkit/themes': 1.0.0-beta.10_tailwindcss@3.1.8 '@formkit/vue': 1.0.0-beta.10_wwmyxdjqen5bmh3tr2meig5lki '@halo-dev/admin-shared': link:packages/shared - '@halo-dev/api-client': 0.0.14 + '@halo-dev/api-client': 0.0.15 '@halo-dev/components': link:packages/components '@halo-dev/richtext-editor': 0.0.0-alpha.5_vue@3.2.37 '@tiptap/extension-character-count': 2.0.0-beta.31 @@ -194,14 +194,14 @@ importers: packages/shared: specifiers: - '@halo-dev/api-client': ^0.0.14 + '@halo-dev/api-client': ^0.0.15 '@halo-dev/components': workspace:* '@types/lodash.merge': ^4.6.7 axios: ^0.27.2 lodash.merge: ^4.6.2 vite-plugin-dts: ^1.4.1 dependencies: - '@halo-dev/api-client': 0.0.14 + '@halo-dev/api-client': 0.0.15 '@halo-dev/components': link:../components axios: 0.27.2 lodash.merge: 4.6.2 @@ -2129,8 +2129,8 @@ packages: - windicss dev: false - /@halo-dev/api-client/0.0.14: - resolution: {integrity: sha512-Qh0/l2f5e8lxBgAU2brN28F3CzZTlxGUGY0puUGbuDRYqEENbQ5pGTHG3CzuiG4it4Pn16xSTCXICO6M9m9X4A==} + /@halo-dev/api-client/0.0.15: + resolution: {integrity: sha512-RCQXU2s5IJJ3pUORg0n2b/CYbDox/Jm4aXB2J9ZbKod3vdS3HM6X33iVXc/pyuxRjucijly3WyLkiTZ0bkwLbg==} dev: false /@halo-dev/richtext-editor/0.0.0-alpha.5_vue@3.2.37: diff --git a/src/modules/contents/posts/PostList.vue b/src/modules/contents/posts/PostList.vue index f7e096cba..6b4f29e6b 100644 --- a/src/modules/contents/posts/PostList.vue +++ b/src/modules/contents/posts/PostList.vue @@ -54,8 +54,8 @@ const checkedAll = ref(false); const selectedPostNames = ref([]); const { users } = useUserFetch(); -const { categories } = usePostCategory(); -const { tags } = usePostTag(); +const { categories } = usePostCategory({ fetchOnMounted: true }); +const { tags } = usePostTag({ fetchOnMounted: true }); const dialog = useDialog(); const handleFetchPosts = async () => { diff --git a/src/modules/contents/posts/categories/CategoryList.vue b/src/modules/contents/posts/categories/CategoryList.vue index 2ecdad35f..0689ff2d8 100644 --- a/src/modules/contents/posts/categories/CategoryList.vue +++ b/src/modules/contents/posts/categories/CategoryList.vue @@ -40,7 +40,7 @@ const { loading, handleFetchCategories, handleDelete, -} = usePostCategory(); +} = usePostCategory({ fetchOnMounted: true }); const handleUpdateInBatch = useDebounceFn(async () => { const categoriesTreeToUpdate = resetCategoriesTreePriority( diff --git a/src/modules/contents/posts/categories/composables/use-post-category.ts b/src/modules/contents/posts/categories/composables/use-post-category.ts index 8d774ecc6..e15124e92 100644 --- a/src/modules/contents/posts/categories/composables/use-post-category.ts +++ b/src/modules/contents/posts/categories/composables/use-post-category.ts @@ -14,7 +14,11 @@ interface usePostCategoryReturn { handleDelete: (category: CategoryTree) => void; } -export function usePostCategory(): usePostCategoryReturn { +export function usePostCategory(options?: { + fetchOnMounted: boolean; +}): usePostCategoryReturn { + const { fetchOnMounted } = options || {}; + const categories = ref([] as Category[]); const categoriesTree = ref([] as CategoryTree[]); const loading = ref(false); @@ -59,7 +63,9 @@ export function usePostCategory(): usePostCategoryReturn { }); }; - onMounted(handleFetchCategories); + onMounted(() => { + fetchOnMounted && handleFetchCategories(); + }); return { categories, diff --git a/src/modules/contents/posts/components/PostSettingModal.vue b/src/modules/contents/posts/components/PostSettingModal.vue index d42aa55b4..57810a51a 100644 --- a/src/modules/contents/posts/components/PostSettingModal.vue +++ b/src/modules/contents/posts/components/PostSettingModal.vue @@ -67,7 +67,7 @@ const saving = ref(false); const publishing = ref(false); const publishCanceling = ref(false); -const { categories } = usePostCategory(); +const { categories } = usePostCategory({ fetchOnMounted: true }); const categoriesMap = computed(() => { return categories.value.map((category) => { return { @@ -77,7 +77,7 @@ const categoriesMap = computed(() => { }); }); -const { tags } = usePostTag(); +const { tags } = usePostTag({ fetchOnMounted: true }); const tagsMap = computed(() => { return tags.value.map((tag) => { return { diff --git a/src/modules/contents/posts/tags/TagList.vue b/src/modules/contents/posts/tags/TagList.vue index 0f5421ed3..f31b5ae3d 100644 --- a/src/modules/contents/posts/tags/TagList.vue +++ b/src/modules/contents/posts/tags/TagList.vue @@ -40,7 +40,9 @@ const viewTypes = [ const viewType = ref("list"); -const { tags, loading, handleFetchTags, handleDelete } = usePostTag(); +const { tags, loading, handleFetchTags, handleDelete } = usePostTag({ + fetchOnMounted: true, +}); const editingModal = ref(false); const selectedTag = ref(null); diff --git a/src/modules/contents/posts/tags/composables/use-post-tag.ts b/src/modules/contents/posts/tags/composables/use-post-tag.ts index 434c6c880..e704b3a22 100644 --- a/src/modules/contents/posts/tags/composables/use-post-tag.ts +++ b/src/modules/contents/posts/tags/composables/use-post-tag.ts @@ -11,7 +11,11 @@ interface usePostTagReturn { handleDelete: (tag: Tag) => void; } -export function usePostTag(): usePostTagReturn { +export function usePostTag(options?: { + fetchOnMounted: boolean; +}): usePostTagReturn { + const { fetchOnMounted } = options || {}; + const tags = ref([] as Tag[]); const loading = ref(false); @@ -53,7 +57,9 @@ export function usePostTag(): usePostTagReturn { }); }; - onMounted(handleFetchTags); + onMounted(() => { + fetchOnMounted && handleFetchTags(); + }); return { tags, diff --git a/src/modules/interface/menus/components/MenuItemEditingModal.vue b/src/modules/interface/menus/components/MenuItemEditingModal.vue index d4c45b04a..6f30c778d 100644 --- a/src/modules/interface/menus/components/MenuItemEditingModal.vue +++ b/src/modules/interface/menus/components/MenuItemEditingModal.vue @@ -1,12 +1,14 @@