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() { + > + +