From 1f8cf9fac5fbe9f1a4b21f4dee4c89278124cc61 Mon Sep 17 00:00:00 2001 From: Li Date: Thu, 23 Feb 2023 17:16:11 +0800 Subject: [PATCH] fix: default value of formkit schema is not initialize in annotation form (#880) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /milestone 2.3.x /area console #### What this PR does / why we need it: #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3357 #### Special notes for your reviewer: 测试使用主题/插件自定义的元数据信息,是否能够在 console 中显示默认值。 #### Does this PR introduce a user-facing change? ```release-note 使用主题/插件配置的元数据将能够展示默认值 ``` --- src/components/form/AnnotationsForm.vue | 27 +++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/components/form/AnnotationsForm.vue b/src/components/form/AnnotationsForm.vue index c7a6d7a1..822422f8 100644 --- a/src/components/form/AnnotationsForm.vue +++ b/src/components/form/AnnotationsForm.vue @@ -100,22 +100,23 @@ const handleProcessCustomAnnotations = () => { }) .filter((item) => item) as { key: string; value: string }[]; - annotations.value = Object.entries(props.value || {}) - .map(([key, value]) => { - const fromThemeSpec = formSchemas.some((item) => { - if (typeof item === "object" && "$formkit" in item) { - return item.name === key; + annotations.value = formSchemas + .map((item) => { + if (typeof item === "object" && "$formkit" in item) { + if (props.value && item.name in props.value) { + return { + key: item.name, + value: props.value[item.name], + }; + } else { + return { + key: item.name, + value: item.value, + }; } - return false; - }); - if (fromThemeSpec) { - return { - key, - value, - }; } }) - .filter((item) => item) + .filter(Boolean) .reduce((acc, cur) => { if (cur) { acc[cur.key] = cur.value;