feat: add menu select form item (#6642)

#### 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 添加菜单选择输入类型
```
pull/6647/head
Ryan Wang 2024-09-12 13:28:20 +08:00 committed by GitHub
parent ba18f7010b
commit 697963d628
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 3 deletions

View File

@ -38,6 +38,7 @@
9. removeControl: 是否显示删除按钮,默认为 `true`
- `menuCheckbox`:选择一组菜单
- `menuRadio`:选择一个菜单
- `menuSelect`: 通用菜单选择组件,支持单选、多选、排序
- `menuItemSelect`:选择菜单项
- `postSelect`:选择文章
- `singlePageSelect`:选择自定义页面

View File

@ -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";
@ -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";
@ -58,6 +58,7 @@ const config: DefaultConfigOptions = {
menuCheckbox,
menuItemSelect,
menuRadio,
menuSelect,
nativeGroup,
password,
postSelect,

View File

@ -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],
};