From 524b9badf2e29ef266927cae66c1f60759794ab3 Mon Sep 17 00:00:00 2001 From: Vben Date: Tue, 10 Sep 2024 21:48:51 +0800 Subject: [PATCH] feat: add VbenForm component (#4352) * feat: add form component * fix: build error * feat: add form adapter * feat: add some component * feat: add some component * feat: add example * feat: suppoer custom action button * chore: update * feat: add example * feat: add formModel,formDrawer demo * fix: build error * fix: typo * fix: ci error --------- Co-authored-by: jinmao Co-authored-by: likui628 <90845831+likui628@users.noreply.github.com> --- apps/web-antd/src/adapter/form.ts | 114 ++++++ apps/web-antd/src/adapter/index.ts | 1 + apps/web-antd/src/layouts/basic.vue | 13 +- .../views/_core/authentication/code-login.vue | 44 ++- .../_core/authentication/forget-password.vue | 27 +- .../src/views/_core/authentication/login.vue | 79 ++++- .../views/_core/authentication/register.vue | 86 ++++- apps/web-ele/src/adapter/form.ts | 89 +++++ apps/web-ele/src/adapter/index.ts | 1 + apps/web-ele/src/layouts/basic.vue | 13 +- .../views/_core/authentication/code-login.vue | 44 ++- .../_core/authentication/forget-password.vue | 27 +- .../src/views/_core/authentication/login.vue | 79 ++++- .../views/_core/authentication/register.vue | 86 ++++- apps/web-naive/src/adapter/form.ts | 98 ++++++ apps/web-naive/src/adapter/index.ts | 1 + apps/web-naive/src/layouts/basic.vue | 13 +- .../views/_core/authentication/code-login.vue | 44 ++- .../_core/authentication/forget-password.vue | 27 +- .../src/views/_core/authentication/login.vue | 79 ++++- .../views/_core/authentication/register.vue | 86 ++++- docs/.vitepress/config/zh.mts | 4 + docs/src/components/common-ui/vben-form.md | 11 + docs/src/en/guide/in-depth/login.md | 10 - docs/src/guide/in-depth/login.md | 9 - .../eslint-config/src/configs/unicorn.ts | 2 + .../vite-config/src/config/application.ts | 6 +- internal/vite-config/src/plugins/archiver.ts | 10 +- packages/@core/base/design/src/css/global.css | 5 +- packages/@core/base/icons/src/lucide.ts | 2 +- packages/@core/base/shared/build.config.ts | 1 - packages/@core/base/shared/package.json | 29 +- packages/@core/base/shared/src/index.ts | 5 - .../src/utils/__tests__/state-handler.test.ts | 60 ++++ .../shared/src/utils/__tests__/util.test.ts | 80 +++++ packages/@core/base/shared/src/utils/index.ts | 2 + .../base/shared/src/utils/state-handler.ts | 50 +++ packages/@core/base/shared/src/utils/util.ts | 19 + .../composables/src/use-content-style.ts | 4 +- .../@core/composables/src/use-namespace.ts | 2 +- .../composables/src/use-priority-value.ts | 52 ++- .../src/use-simple-locale/messages.ts | 8 + packages/@core/preferences/src/preferences.ts | 3 +- .../preferences/src/update-css-variables.ts | 6 +- .../@core/preferences/src/use-preferences.ts | 2 +- packages/@core/ui-kit/form-ui/build.config.ts | 21 ++ packages/@core/ui-kit/form-ui/package.json | 50 +++ .../@core/ui-kit/form-ui/postcss.config.mjs | 1 + .../form-ui/src/components/form-actions.vue | 103 ++++++ packages/@core/ui-kit/form-ui/src/config.ts | 65 ++++ packages/@core/ui-kit/form-ui/src/form-api.ts | 175 ++++++++++ .../ui-kit/form-ui/src/form-render/context.ts | 24 ++ .../form-ui/src/form-render/dependencies.ts | 116 +++++++ .../form-ui/src/form-render/expandable.ts | 97 ++++++ .../form-ui/src/form-render/form-field.vue | 283 +++++++++++++++ .../form-ui/src/form-render/form-label.vue | 20 ++ .../ui-kit/form-ui/src/form-render/form.vue | 140 ++++++++ .../ui-kit/form-ui/src/form-render/helper.ts | 60 ++++ .../ui-kit/form-ui/src/form-render/index.ts | 3 + packages/@core/ui-kit/form-ui/src/index.ts | 11 + packages/@core/ui-kit/form-ui/src/types.ts | 327 ++++++++++++++++++ .../ui-kit/form-ui/src/use-form-context.ts | 59 ++++ .../@core/ui-kit/form-ui/src/use-vben-form.ts | 49 +++ .../@core/ui-kit/form-ui/src/vben-form.vue | 72 ++++ .../ui-kit/form-ui/src/vben-use-form.vue | 57 +++ .../@core/ui-kit/form-ui/tailwind.config.mjs | 1 + packages/@core/ui-kit/form-ui/tsconfig.json | 6 + .../ui-kit/menu-ui/src/components/menu.vue | 6 +- packages/@core/ui-kit/popup-ui/package.json | 2 +- .../src/drawer/__tests__/drawer-api.test.ts | 2 +- .../ui-kit/popup-ui/src/drawer/drawer-api.ts | 6 +- .../ui-kit/popup-ui/src/drawer/drawer.vue | 45 ++- .../ui-kit/popup-ui/src/drawer/use-drawer.ts | 2 +- .../src/modal/__tests__/modal-api.test.ts | 2 +- .../ui-kit/popup-ui/src/modal/modal-api.ts | 6 +- .../@core/ui-kit/popup-ui/src/modal/modal.vue | 55 ++- .../ui-kit/popup-ui/src/modal/use-modal.ts | 22 +- .../@core/ui-kit/shadcn-ui/components.json | 2 +- packages/@core/ui-kit/shadcn-ui/package.json | 21 +- .../shadcn-ui/src/components/button/button.ts | 24 ++ .../src/components/button/button.vue | 16 +- .../src/components/button/icon-button.vue | 9 +- .../shadcn-ui/src/components/button/index.ts | 1 + .../src/components/checkbox/checkbox.vue | 16 +- .../count-to-animator/count-to-animator.vue | 2 +- .../expandable-arrow/expandable-arrow.vue | 36 ++ .../src/components/expandable-arrow/index.ts | 1 + .../components/full-screen/full-screen.vue | 4 +- .../shadcn-ui/src/components/icon/icon.vue | 7 +- .../ui-kit/shadcn-ui/src/components/index.ts | 9 +- .../input-password/input-password.vue | 45 +-- .../shadcn-ui/src/components/input/index.ts | 2 - .../shadcn-ui/src/components/input/input.vue | 53 --- .../shadcn-ui/src/components/input/types.ts | 25 -- .../shadcn-ui/src/components/link/link.vue | 2 +- .../src/components/menu-badge/menu-badge.vue | 2 +- .../src/components/pin-input/input.vue | 85 +++-- .../src/components/pin-input/types.ts | 24 +- .../render-content/render-content.vue | 57 +-- .../src/components/scrollbar/scrollbar.vue | 2 +- .../components/segmented/tabs-indicator.vue | 10 +- .../shadcn-ui/src/components/select/index.ts | 1 + .../src/components/select/select.vue | 29 ++ .../src/components/spinner/loading.vue | 2 +- .../src/components/spinner/spinner.vue | 2 +- .../src/components/tooltip/help-tooltip.vue | 31 ++ .../shadcn-ui/src/components/tooltip/index.ts | 1 + .../src/components/ui/accordion/Accordion.vue | 19 + .../ui/accordion/AccordionContent.vue | 26 ++ .../components/ui/accordion/AccordionItem.vue | 27 ++ .../ui/accordion/AccordionTrigger.vue | 41 +++ .../src/components/ui/accordion/index.ts | 4 + .../src/components/ui/avatar/Avatar.vue | 6 +- .../src/components/ui/badge/Badge.vue | 6 +- .../components/ui/breadcrumb/Breadcrumb.vue | 4 +- .../ui/breadcrumb/BreadcrumbEllipsis.vue | 6 +- .../ui/breadcrumb/BreadcrumbItem.vue | 6 +- .../ui/breadcrumb/BreadcrumbLink.vue | 13 +- .../ui/breadcrumb/BreadcrumbList.vue | 6 +- .../ui/breadcrumb/BreadcrumbPage.vue | 6 +- .../ui/breadcrumb/BreadcrumbSeparator.vue | 6 +- .../src/components/ui/button/Button.vue | 12 +- .../src/components/ui/button/button.ts | 4 +- .../src/components/ui/button/index.ts | 2 + .../src/components/ui/button/types.ts | 20 ++ .../shadcn-ui/src/components/ui/card/Card.vue | 6 +- .../src/components/ui/card/CardContent.vue | 6 +- .../components/ui/card/CardDescription.vue | 6 +- .../src/components/ui/card/CardFooter.vue | 6 +- .../src/components/ui/card/CardHeader.vue | 6 +- .../src/components/ui/card/CardTitle.vue | 6 +- .../src/components/ui/checkbox/Checkbox.vue | 8 +- .../context-menu/ContextMenuCheckboxItem.vue | 8 +- .../ui/context-menu/ContextMenuContent.vue | 8 +- .../ui/context-menu/ContextMenuItem.vue | 6 +- .../ui/context-menu/ContextMenuLabel.vue | 6 +- .../ui/context-menu/ContextMenuRadioItem.vue | 8 +- .../ui/context-menu/ContextMenuSeparator.vue | 8 +- .../ui/context-menu/ContextMenuShortcut.vue | 6 +- .../ui/context-menu/ContextMenuSubContent.vue | 8 +- .../ui/context-menu/ContextMenuSubTrigger.vue | 6 +- .../components/ui/dialog/DialogContent.vue | 2 +- .../ui/dialog/DialogDescription.vue | 8 +- .../src/components/ui/dialog/DialogFooter.vue | 6 +- .../src/components/ui/dialog/DialogHeader.vue | 6 +- .../ui/dialog/DialogScrollContent.vue | 8 +- .../src/components/ui/dialog/DialogTitle.vue | 8 +- .../DropdownMenuCheckboxItem.vue | 8 +- .../ui/dropdown-menu/DropdownMenuContent.vue | 6 +- .../ui/dropdown-menu/DropdownMenuItem.vue | 6 +- .../ui/dropdown-menu/DropdownMenuLabel.vue | 6 +- .../dropdown-menu/DropdownMenuRadioItem.vue | 8 +- .../dropdown-menu/DropdownMenuSeparator.vue | 6 +- .../ui/dropdown-menu/DropdownMenuShortcut.vue | 6 +- .../dropdown-menu/DropdownMenuSubContent.vue | 8 +- .../dropdown-menu/DropdownMenuSubTrigger.vue | 8 +- .../src/components/ui/form/FormControl.vue | 19 + .../components/ui/form/FormDescription.vue | 20 ++ .../src/components/ui/form/FormItem.vue | 20 ++ .../src/components/ui/form/FormLabel.vue | 18 + .../src/components/ui/form/FormMessage.vue | 18 + .../shadcn-ui/src/components/ui/form/index.ts | 11 + .../src/components/ui/form/injectionKeys.ts | 4 + .../src/components/ui/form/useFormField.ts | 38 ++ .../ui/hover-card/HoverCardContent.vue | 2 +- .../src/components/ui/input/Input.vue | 8 +- .../src/components/ui/label/Label.vue | 29 ++ .../src/components/ui/label/index.ts | 1 + .../ui/number-field/NumberField.vue | 8 +- .../ui/number-field/NumberFieldContent.vue | 6 +- .../ui/number-field/NumberFieldDecrement.vue | 8 +- .../ui/number-field/NumberFieldIncrement.vue | 8 +- .../ui/number-field/NumberFieldInput.vue | 2 +- .../src/components/ui/pin-input/PinInput.vue | 8 +- .../components/ui/pin-input/PinInputGroup.vue | 8 +- .../components/ui/pin-input/PinInputInput.vue | 8 +- .../components/ui/popover/PopoverContent.vue | 6 +- .../components/ui/radio-group/RadioGroup.vue | 29 ++ .../ui/radio-group/RadioGroupItem.vue | 39 +++ .../src/components/ui/radio-group/index.ts | 2 + .../components/ui/scroll-area/ScrollArea.vue | 6 +- .../components/ui/scroll-area/ScrollBar.vue | 6 +- .../components/ui/select/SelectContent.vue | 6 +- .../src/components/ui/select/SelectGroup.vue | 8 +- .../src/components/ui/select/SelectItem.vue | 8 +- .../src/components/ui/select/SelectLabel.vue | 8 +- .../ui/select/SelectScrollDownButton.vue | 8 +- .../ui/select/SelectScrollUpButton.vue | 8 +- .../components/ui/select/SelectSeparator.vue | 8 +- .../components/ui/select/SelectTrigger.vue | 8 +- .../src/components/ui/separator/Separator.vue | 42 +++ .../src/components/ui/separator/index.ts | 1 + .../src/components/ui/sheet/SheetContent.vue | 6 +- .../components/ui/sheet/SheetDescription.vue | 8 +- .../src/components/ui/sheet/SheetFooter.vue | 6 +- .../src/components/ui/sheet/SheetHeader.vue | 6 +- .../src/components/ui/sheet/SheetTitle.vue | 8 +- .../src/components/ui/switch/Switch.vue | 8 +- .../src/components/ui/tabs/TabsContent.vue | 8 +- .../src/components/ui/tabs/TabsList.vue | 8 +- .../src/components/ui/tabs/TabsTrigger.vue | 8 +- .../src/components/ui/textarea/Textarea.vue | 32 ++ .../src/components/ui/textarea/index.ts | 1 + .../src/components/ui/toast/Toast.vue | 2 +- .../src/components/ui/toast/ToastAction.vue | 8 +- .../src/components/ui/toast/ToastClose.vue | 6 +- .../components/ui/toast/ToastDescription.vue | 8 +- .../src/components/ui/toast/ToastTitle.vue | 8 +- .../src/components/ui/toast/ToastViewport.vue | 8 +- .../src/components/ui/toast/toast.ts | 4 +- .../ui/toggle-group/ToggleGroup.vue | 6 +- .../ui/toggle-group/ToggleGroupItem.vue | 6 +- .../src/components/ui/toggle/Toggle.vue | 6 +- .../components/ui/tooltip/TooltipContent.vue | 6 +- packages/@core/ui-kit/shadcn-ui/src/index.ts | 2 +- packages/effects/common-ui/package.json | 2 +- .../common-ui/src/components/captcha/index.ts | 8 +- .../captcha/point-selection-captcha.vue | 14 +- .../common-ui/src/components/captcha/types.ts | 6 + .../effects/common-ui/src/components/index.ts | 2 + .../src/ui/authentication/code-login.vue | 120 ++----- .../src/ui/authentication/forget-password.vue | 50 ++- .../ui/authentication/login-expired-modal.vue | 22 +- .../common-ui/src/ui/authentication/login.vue | 104 ++---- .../src/ui/authentication/register.vue | 131 ++----- .../common-ui/src/ui/authentication/types.ts | 10 - packages/effects/layouts/package.json | 1 + .../layouts/src/basic/header/header.vue | 8 +- .../widgets/global-search/global-search.vue | 2 +- .../widgets/global-search/search-panel.vue | 2 +- .../layouts/src/widgets/language-toggle.vue | 2 +- .../widgets/lock-screen/lock-screen-modal.vue | 69 ++-- .../src/widgets/lock-screen/lock-screen.vue | 78 ++--- .../src/widgets/notification/notification.vue | 2 +- .../preferences/preferences-button.vue | 2 +- .../preferences/preferences-drawer.vue | 2 +- .../src/widgets/theme-toggle/theme-button.vue | 6 +- .../widgets/user-dropdown/user-dropdown.vue | 6 +- .../src/request-client/request-client.ts | 19 +- packages/icons/src/svg/icons/refresh.svg | 1 - packages/icons/src/svg/index.ts | 2 - packages/locales/src/langs/en-US.json | 9 +- packages/locales/src/langs/zh-CN.json | 9 +- packages/stores/src/modules/tabbar.ts | 6 +- packages/types/src/{user.d.ts => user.ts} | 0 packages/utils/src/helpers/generate-menus.ts | 2 +- .../src/helpers/generate-routes-backend.ts | 2 +- .../src/helpers/generate-routes-frontend.ts | 2 +- playground/src/adapter/form.ts | 114 ++++++ playground/src/adapter/index.ts | 1 + playground/src/layouts/basic.vue | 13 +- playground/src/locales/langs/en-US.json | 8 + playground/src/locales/langs/zh-CN.json | 8 + .../src/router/routes/modules/examples.ts | 49 +++ .../views/_core/authentication/code-login.vue | 44 ++- .../_core/authentication/forget-password.vue | 27 +- .../src/views/_core/authentication/login.vue | 96 ++++- .../views/_core/authentication/register.vue | 86 ++++- .../views/demos/features/clipboard/index.vue | 2 +- .../src/views/examples/captcha/index.vue | 8 +- .../examples/drawer/form-drawer-demo.vue | 56 +++ .../src/views/examples/drawer/index.vue | 21 ++ playground/src/views/examples/form/basic.vue | 270 +++++++++++++++ playground/src/views/examples/form/custom.vue | 79 +++++ .../src/views/examples/form/dynamic.vue | 271 +++++++++++++++ playground/src/views/examples/form/query.vue | 149 ++++++++ playground/src/views/examples/form/rules.vue | 188 ++++++++++ .../views/examples/modal/form-model-demo.vue | 58 ++++ playground/src/views/examples/modal/index.vue | 20 +- pnpm-lock.yaml | 78 ++++- vben-admin.code-workspace | 4 + 271 files changed, 5974 insertions(+), 1247 deletions(-) create mode 100644 apps/web-antd/src/adapter/form.ts create mode 100644 apps/web-antd/src/adapter/index.ts create mode 100644 apps/web-ele/src/adapter/form.ts create mode 100644 apps/web-ele/src/adapter/index.ts create mode 100644 apps/web-naive/src/adapter/form.ts create mode 100644 apps/web-naive/src/adapter/index.ts create mode 100644 docs/src/components/common-ui/vben-form.md delete mode 100644 packages/@core/base/shared/src/index.ts create mode 100644 packages/@core/base/shared/src/utils/__tests__/state-handler.test.ts create mode 100644 packages/@core/base/shared/src/utils/__tests__/util.test.ts create mode 100644 packages/@core/base/shared/src/utils/state-handler.ts create mode 100644 packages/@core/base/shared/src/utils/util.ts create mode 100644 packages/@core/ui-kit/form-ui/build.config.ts create mode 100644 packages/@core/ui-kit/form-ui/package.json create mode 100644 packages/@core/ui-kit/form-ui/postcss.config.mjs create mode 100644 packages/@core/ui-kit/form-ui/src/components/form-actions.vue create mode 100644 packages/@core/ui-kit/form-ui/src/config.ts create mode 100644 packages/@core/ui-kit/form-ui/src/form-api.ts create mode 100644 packages/@core/ui-kit/form-ui/src/form-render/context.ts create mode 100644 packages/@core/ui-kit/form-ui/src/form-render/dependencies.ts create mode 100644 packages/@core/ui-kit/form-ui/src/form-render/expandable.ts create mode 100644 packages/@core/ui-kit/form-ui/src/form-render/form-field.vue create mode 100644 packages/@core/ui-kit/form-ui/src/form-render/form-label.vue create mode 100644 packages/@core/ui-kit/form-ui/src/form-render/form.vue create mode 100644 packages/@core/ui-kit/form-ui/src/form-render/helper.ts create mode 100644 packages/@core/ui-kit/form-ui/src/form-render/index.ts create mode 100644 packages/@core/ui-kit/form-ui/src/index.ts create mode 100644 packages/@core/ui-kit/form-ui/src/types.ts create mode 100644 packages/@core/ui-kit/form-ui/src/use-form-context.ts create mode 100644 packages/@core/ui-kit/form-ui/src/use-vben-form.ts create mode 100644 packages/@core/ui-kit/form-ui/src/vben-form.vue create mode 100644 packages/@core/ui-kit/form-ui/src/vben-use-form.vue create mode 100644 packages/@core/ui-kit/form-ui/tailwind.config.mjs create mode 100644 packages/@core/ui-kit/form-ui/tsconfig.json create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/button/button.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/expandable-arrow/expandable-arrow.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/expandable-arrow/index.ts delete mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/input/index.ts delete mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/input/input.vue delete mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/input/types.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/select/index.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/select/select.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/tooltip/help-tooltip.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/accordion/Accordion.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/accordion/AccordionContent.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/accordion/AccordionItem.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/accordion/AccordionTrigger.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/accordion/index.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/button/types.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/form/FormControl.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/form/FormDescription.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/form/FormItem.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/form/FormLabel.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/form/FormMessage.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/form/index.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/form/injectionKeys.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/form/useFormField.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/label/Label.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/label/index.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/radio-group/RadioGroup.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/radio-group/RadioGroupItem.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/radio-group/index.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/separator/Separator.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/separator/index.ts create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/textarea/Textarea.vue create mode 100644 packages/@core/ui-kit/shadcn-ui/src/components/ui/textarea/index.ts create mode 100644 packages/effects/common-ui/src/components/captcha/types.ts delete mode 100644 packages/icons/src/svg/icons/refresh.svg rename packages/types/src/{user.d.ts => user.ts} (100%) create mode 100644 playground/src/adapter/form.ts create mode 100644 playground/src/adapter/index.ts create mode 100644 playground/src/views/examples/drawer/form-drawer-demo.vue create mode 100644 playground/src/views/examples/form/basic.vue create mode 100644 playground/src/views/examples/form/custom.vue create mode 100644 playground/src/views/examples/form/dynamic.vue create mode 100644 playground/src/views/examples/form/query.vue create mode 100644 playground/src/views/examples/form/rules.vue create mode 100644 playground/src/views/examples/modal/form-model-demo.vue diff --git a/apps/web-antd/src/adapter/form.ts b/apps/web-antd/src/adapter/form.ts new file mode 100644 index 000000000..06e8cf134 --- /dev/null +++ b/apps/web-antd/src/adapter/form.ts @@ -0,0 +1,114 @@ +import type { + BaseFormComponentType, + VbenFormSchema as FormSchema, + VbenFormProps, +} from '@vben/common-ui'; + +import { h } from 'vue'; + +import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui'; +import { $t } from '@vben/locales'; + +import { + AutoComplete, + Button, + Checkbox, + CheckboxGroup, + DatePicker, + Divider, + Input, + InputNumber, + InputPassword, + Mentions, + Radio, + RadioGroup, + RangePicker, + Rate, + Select, + Space, + Switch, + TimePicker, + TreeSelect, + Upload, +} from 'ant-design-vue'; + +// 业务表单组件适配 + +export type FormComponentType = + | 'AutoComplete' + | 'Checkbox' + | 'CheckboxGroup' + | 'DatePicker' + | 'Divider' + | 'Input' + | 'InputNumber' + | 'InputPassword' + | 'Mentions' + | 'Radio' + | 'RadioGroup' + | 'RangePicker' + | 'Rate' + | 'Select' + | 'Space' + | 'Switch' + | 'TimePicker' + | 'TreeSelect' + | 'Upload' + | BaseFormComponentType; + +// 初始化表单组件,并注册到form组件内部 +setupVbenForm({ + components: { + AutoComplete, + Checkbox, + CheckboxGroup, + DatePicker, + // 自定义默认的重置按钮 + DefaultResetActionButton: (props, { attrs, slots }) => { + return h(Button, { ...props, attrs, type: 'default' }, slots); + }, + // 自定义默认的提交按钮 + DefaultSubmitActionButton: (props, { attrs, slots }) => { + return h(Button, { ...props, attrs, type: 'primary' }, slots); + }, + Divider, + Input, + InputNumber, + InputPassword, + Mentions, + Radio, + RadioGroup, + RangePicker, + Rate, + Select, + Space, + Switch, + TimePicker, + TreeSelect, + Upload, + }, + config: { + baseModelPropName: 'value', + modelPropNameMap: { + Checkbox: 'checked', + Radio: 'checked', + Switch: 'checked', + Upload: 'fileList', + }, + }, + defineRules: { + required: (value, _params, ctx) => { + if ((!value && value !== 0) || value.length === 0) { + return $t('formRules.required', [ctx.label]); + } + return true; + }, + }, +}); + +const useVbenForm = useForm; + +export { useVbenForm, z }; + +export type VbenFormSchema = FormSchema; +export type { VbenFormProps }; diff --git a/apps/web-antd/src/adapter/index.ts b/apps/web-antd/src/adapter/index.ts new file mode 100644 index 000000000..698d687b9 --- /dev/null +++ b/apps/web-antd/src/adapter/index.ts @@ -0,0 +1 @@ +export * from './form'; diff --git a/apps/web-antd/src/layouts/basic.vue b/apps/web-antd/src/layouts/basic.vue index 9e25d99f3..3c302634b 100644 --- a/apps/web-antd/src/layouts/basic.vue +++ b/apps/web-antd/src/layouts/basic.vue @@ -13,11 +13,12 @@ import { UserDropdown, } from '@vben/layouts'; import { preferences } from '@vben/preferences'; -import { storeToRefs, useAccessStore, useUserStore } from '@vben/stores'; +import { useAccessStore, useUserStore } from '@vben/stores'; import { openWindow } from '@vben/utils'; import { $t } from '#/locales'; import { useAuthStore } from '#/store'; +import LoginForm from '#/views/_core/authentication/login.vue'; const notifications = ref([ { @@ -87,8 +88,6 @@ const menus = computed(() => [ }, ]); -const { loginLoading } = storeToRefs(authStore); - const avatar = computed(() => { return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar; }); @@ -130,11 +129,9 @@ function handleMakeAll() { + > + +