From 9a24604a6bdbc52d827845ce8c4c076541245ec5 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 1 Nov 2022 11:06:18 +0800 Subject: [PATCH] feat: add formkit custom input of attachment (halo-dev/console#674) 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: 添加选择附件类型的 FormKit 输入框。 在 Vue 单组件中使用: ```vue ``` 在 FormKit Schema 中使用(插件 / 主题设置表单定义): ```yaml - $formkit: attachment name: logo label: Logo ``` #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2558 #### Screenshots: image #### Special notes for your reviewer: /cc @halo-dev/sig-halo-console #### Does this PR introduce a user-facing change? ```release-note 添加选择附件类型的 FormKit 输入框。 ``` --- docs/custom-formkit-input/README.md | 1 + src/formkit/formkit.config.ts | 2 + .../inputs/attachment/AttachmentInput.vue | 61 +++++++++++++++++++ src/formkit/inputs/attachment/index.ts | 10 +++ .../components/AttachmentGroupList.vue | 1 + .../components/AttachmentSelectorModal.vue | 1 + .../components/SinglePageSettingModal.vue | 2 +- .../components/CategoryEditingModal.vue | 3 +- .../posts/components/PostSettingModal.vue | 2 +- .../posts/tags/components/TagEditingModal.vue | 2 +- .../users/components/UserEditingModal.vue | 2 +- 11 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 src/formkit/inputs/attachment/AttachmentInput.vue create mode 100644 src/formkit/inputs/attachment/index.ts diff --git a/docs/custom-formkit-input/README.md b/docs/custom-formkit-input/README.md index 60631d871..e4455119a 100644 --- a/docs/custom-formkit-input/README.md +++ b/docs/custom-formkit-input/README.md @@ -12,6 +12,7 @@ - 参数 1. language: 目前支持 `yaml`, `html`, `css`, `javascript`, `json` 2. height: 编辑器高度,如:`100px` +- `attachment`: 附件选择 - `menuCheckbox`:选择一组菜单 - `menuRadio`:选择一个菜单 - `menuItemSelect`:选择菜单项 diff --git a/src/formkit/formkit.config.ts b/src/formkit/formkit.config.ts index 2c0fc28e4..78de33b8c 100644 --- a/src/formkit/formkit.config.ts +++ b/src/formkit/formkit.config.ts @@ -4,6 +4,7 @@ import { createAutoAnimatePlugin } from "@formkit/addons"; import { zh } from "@formkit/i18n"; import type { DefaultConfigOptions } from "@formkit/vue"; import { form } from "./inputs/form"; +import { attachment } from "./inputs/attachment"; import { code } from "./inputs/code"; import { menuCheckbox } from "./inputs/menu-checkbox"; import { menuRadio } from "./inputs/menu-radio"; @@ -22,6 +23,7 @@ const config: DefaultConfigOptions = { plugins: [createAutoAnimatePlugin()], inputs: { form, + attachment, code, menuCheckbox, menuRadio, diff --git a/src/formkit/inputs/attachment/AttachmentInput.vue b/src/formkit/inputs/attachment/AttachmentInput.vue new file mode 100644 index 000000000..53acbecad --- /dev/null +++ b/src/formkit/inputs/attachment/AttachmentInput.vue @@ -0,0 +1,61 @@ + + + diff --git a/src/formkit/inputs/attachment/index.ts b/src/formkit/inputs/attachment/index.ts new file mode 100644 index 000000000..bdc7253ed --- /dev/null +++ b/src/formkit/inputs/attachment/index.ts @@ -0,0 +1,10 @@ +import { initialValue } from "@formkit/inputs"; +import { createInput } from "@formkit/vue"; +import AttachmentInput from "./AttachmentInput.vue"; + +export const attachment = createInput(AttachmentInput, { + type: "input", + props: [], + forceTypeProp: "text", + features: [initialValue], +}); diff --git a/src/modules/contents/attachments/components/AttachmentGroupList.vue b/src/modules/contents/attachments/components/AttachmentGroupList.vue index 7cd2136ca..7b98b332b 100644 --- a/src/modules/contents/attachments/components/AttachmentGroupList.vue +++ b/src/modules/contents/attachments/components/AttachmentGroupList.vue @@ -98,6 +98,7 @@ onMounted(async () => {