Skip to content

Commit

Permalink
feat: add menu select form item (#6642)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/area ui
/kind feature
/milestone 2.20.x

#### What this PR does / why we need it:

为 FormKit 添加菜单选择输入类型

<img width="549" alt="image" src="https://github.com/user-attachments/assets/b5e40c1d-908f-4cdc-89d5-76f9b67ae298">

#### Does this PR introduce a user-facing change?

```release-note
为 FormKit 添加菜单选择输入类型
```
  • Loading branch information
ruibaby committed Sep 12, 2024
1 parent ba18f70 commit 697963d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions ui/docs/custom-formkit-input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
9. removeControl: 是否显示删除按钮,默认为 `true`
- `menuCheckbox`:选择一组菜单
- `menuRadio`:选择一个菜单
- `menuSelect`: 通用菜单选择组件,支持单选、多选、排序
- `menuItemSelect`:选择菜单项
- `postSelect`:选择文章
- `singlePageSelect`:选择自定义页面
Expand Down
7 changes: 4 additions & 3 deletions ui/src/formkit/formkit.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { en, zh } from "@formkit/i18n";
import { group as nativeGroup } from "@formkit/inputs";
import { group as nativeGroup, select as nativeSelect } from "@formkit/inputs";
import { generateClasses } from "@formkit/themes";
import type { DefaultConfigOptions } from "@formkit/vue";
import { attachment } from "./inputs/attachment";
Expand All @@ -19,14 +19,14 @@ import { postSelect } from "./inputs/post-select";
import { repeater } from "./inputs/repeater";
import { roleSelect } from "./inputs/role-select";
import { secret } from "./inputs/secret";
import { select } from "./inputs/select";
import { singlePageSelect } from "./inputs/singlePage-select";
import { tagCheckbox } from "./inputs/tag-checkbox";
import { tagSelect } from "./inputs/tag-select";
import { verificationForm } from "./inputs/verify-form";
import { select as nativeSelect } from "@formkit/inputs";
import { select } from "./inputs/select";
import theme from "./theme";

import { menuSelect } from "./inputs/menu-select";
import { userSelect } from "./inputs/user-select";
import autoScrollToErrors from "./plugins/auto-scroll-to-errors";
import passwordPreventAutocomplete from "./plugins/password-prevent-autocomplete";
Expand Down Expand Up @@ -58,6 +58,7 @@ const config: DefaultConfigOptions = {
menuCheckbox,
menuItemSelect,
menuRadio,
menuSelect,
nativeGroup,
password,
postSelect,
Expand Down
25 changes: 25 additions & 0 deletions ui/src/formkit/inputs/menu-select.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { FormKitNode, FormKitTypeDefinition } from "@formkit/core";
import { coreApiClient } from "@halo-dev/api-client";
import { select } from "./select";

function optionsHandler(node: FormKitNode) {
node.on("created", async () => {
const { data } = await coreApiClient.menu.listMenu();

if (node.context) {
node.context.attrs.options = data.items.map((menu) => {
return {
value: menu.metadata.name,
label: menu.spec.displayName,
};
});
}
});
}

export const menuSelect: FormKitTypeDefinition = {
...select,
props: [...(select.props as string[])],
forceTypeProp: "select",
features: [optionsHandler],
};

0 comments on commit 697963d

Please sign in to comment.