From 93f8a6caffc72d1dffbf0a69788709f90a888c8e Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 26 Dec 2022 23:32:31 +0800 Subject: [PATCH] feat: add annotations form for more extension (halo-dev/console#801) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature #### What this PR does / why we need it: 为更多模型添加 Annotation Form 的支持。此 PR 包括: 1. 自定义页面。 2. 文章分类。 3. 文章标签。 4. 菜单项。 5. 用户。 此 PR 是对 https://github.com/halo-dev/console/pull/770 的补充。 #### Special notes for your reviewer: 测试方式: 1. 将一下内容放到任意一个主题下,后缀为 `yaml`,文件名随意。 ```yaml spec: targetRef: group: content.halo.run kind: Post formSchema: - $formkit: "text" name: "download" label: "下载地址" - $formkit: "text" name: "version" label: "版本" apiVersion: v1alpha1 kind: AnnotationSetting metadata: generateName: annotation- --- spec: targetRef: group: content.halo.run kind: SinglePage formSchema: - $formkit: "text" name: "download" label: "下载地址" - $formkit: "text" name: "version" label: "版本" apiVersion: v1alpha1 kind: AnnotationSetting metadata: generateName: annotation- --- spec: targetRef: group: content.halo.run kind: Category formSchema: - $formkit: "text" name: "download" label: "下载地址" - $formkit: "text" name: "version" label: "版本" apiVersion: v1alpha1 kind: AnnotationSetting metadata: generateName: annotation- --- spec: targetRef: group: content.halo.run kind: Tag formSchema: - $formkit: "text" name: "download" label: "下载地址" - $formkit: "text" name: "version" label: "版本" apiVersion: v1alpha1 kind: AnnotationSetting metadata: generateName: annotation- --- spec: targetRef: group: "" kind: MenuItem formSchema: - $formkit: "text" name: "icon" label: "图标" - $formkit: "text" name: "version" label: "版本" apiVersion: v1alpha1 kind: AnnotationSetting metadata: generateName: annotation- ``` 3. 后端需要使用 https://github.com/halo-dev/halo/pull/3028 4. 测试上述提到的模型的 Annotations 表单。 5. 检查是否可以设置正常。 #### Does this PR introduce a user-facing change? ```release-note None ``` --- src/components/form/AnnotationsForm.vue | 6 +- .../components/SinglePageSettingModal.vue | 52 +++++++ .../components/CategoryEditingModal.vue | 134 +++++++++++------ .../posts/tags/components/TagEditingModal.vue | 121 ++++++++++----- .../menus/components/MenuItemEditingModal.vue | 140 +++++++++++------ .../users/components/UserEditingModal.vue | 141 ++++++++++++------ 6 files changed, 425 insertions(+), 169 deletions(-) diff --git a/src/components/form/AnnotationsForm.vue b/src/components/form/AnnotationsForm.vue index 2d640f3fd..5547fe012 100644 --- a/src/components/form/AnnotationsForm.vue +++ b/src/components/form/AnnotationsForm.vue @@ -148,7 +148,11 @@ const specFormInvalid = ref(true); const customFormInvalid = ref(true); const handleSubmit = async () => { - submitForm("specForm"); + if (avaliableAnnotationSettings.value.length) { + submitForm("specForm"); + } else { + specFormInvalid.value = false; + } submitForm("customForm"); await nextTick(); }; diff --git a/src/modules/contents/pages/components/SinglePageSettingModal.vue b/src/modules/contents/pages/components/SinglePageSettingModal.vue index bb31dd731..07d9e2f0e 100644 --- a/src/modules/contents/pages/components/SinglePageSettingModal.vue +++ b/src/modules/contents/pages/components/SinglePageSettingModal.vue @@ -9,6 +9,7 @@ import { singlePageLabels } from "@/constants/labels"; import { randomUUID } from "@/utils/id"; import { toDatetimeLocal, toISOString } from "@/utils/date"; import { submitForm } from "@formkit/core"; +import AnnotationsForm from "@/components/form/AnnotationsForm.vue"; const initialFormState: SinglePage = { spec: { @@ -75,6 +76,8 @@ const onVisibleChange = (visible: boolean) => { } }; +const annotationsFormRef = ref>(); + const handleSubmit = () => { if (submitType.value === "publish") { handlePublish(); @@ -101,6 +104,20 @@ const handlePublishClick = () => { }; const handleSave = async () => { + annotationsFormRef.value?.handleSubmit(); + await nextTick(); + + const { customAnnotations, annotations, customFormInvalid, specFormInvalid } = + annotationsFormRef.value || {}; + if (customFormInvalid || specFormInvalid) { + return; + } + + formState.value.metadata.annotations = { + ...annotations, + ...customAnnotations, + }; + if (props.onlyEmit) { emit("saved", formState.value); return; @@ -138,6 +155,20 @@ const handleSave = async () => { }; const handlePublish = async () => { + annotationsFormRef.value?.handleSubmit(); + await nextTick(); + + const { customAnnotations, annotations, customFormInvalid, specFormInvalid } = + annotationsFormRef.value || {}; + if (customFormInvalid || specFormInvalid) { + return; + } + + formState.value.metadata.annotations = { + ...annotations, + ...customAnnotations, + }; + if (props.onlyEmit) { emit("published", formState.value); return; @@ -364,6 +395,27 @@ const onPublishTimeChange = (value: string) => { +
+
+
+ +
+
+
+ 元数据 +
+
+
+ +
+
+