From 5ce3a18785b84971d0ba20aa6544f56b606c382b Mon Sep 17 00:00:00 2001 From: Vben Date: Sun, 22 Sep 2024 14:16:06 +0800 Subject: [PATCH] docs: update docs (#4466) * chore: fixed known issues with form components * docs: add vben form doc --- apps/web-antd/src/adapter/form.ts | 13 +- apps/web-ele/src/adapter/form.ts | 2 +- apps/web-naive/src/adapter/form.ts | 2 +- docs/.vitepress/components/demo-preview.vue | 18 +- docs/.vitepress/config/zh.mts | 10 +- .../theme/components/site-layout.vue | 66 ++- docs/.vitepress/theme/styles/base.css | 4 + docs/package.json | 7 + docs/src/_env/adapter/form.ts | 127 +++++ docs/src/_env/adapter/index.ts | 1 + .../common-ui/vben-count-to-animator.md | 52 +++ docs/src/components/common-ui/vben-form.md | 439 +++++++++++++++++- .../vben-count-to-animator/basic/index.vue | 6 + .../vben-count-to-animator/custom/index.vue | 12 + docs/src/demos/vben-form/api/index.vue | 236 ++++++++++ docs/src/demos/vben-form/basic/index.vue | 231 +++++++++ docs/src/demos/vben-form/custom/index.vue | 68 +++ docs/src/demos/vben-form/dynamic/index.vue | 168 +++++++ docs/src/demos/vben-form/query/index.vue | 94 ++++ docs/src/demos/vben-form/rules/index.vue | 189 ++++++++ docs/tsconfig.json | 6 + .../src/utils/__tests__/inference.test.ts | 16 + .../@core/base/shared/src/utils/inference.ts | 10 + packages/@core/ui-kit/form-ui/src/form-api.ts | 8 +- .../form-ui/src/form-render/dependencies.ts | 10 +- .../form-ui/src/form-render/form-field.vue | 12 + packages/@core/ui-kit/form-ui/src/types.ts | 11 +- .../captcha/point-selection-captcha/index.vue | 4 +- .../effects/common-ui/src/components/index.ts | 9 +- .../src/widgets/notification/notification.vue | 8 +- playground/src/adapter/form.ts | 13 +- playground/src/views/examples/form/api.vue | 1 + playground/src/views/examples/form/custom.vue | 6 +- .../src/views/examples/form/dynamic.vue | 11 + pnpm-lock.yaml | 193 ++++---- pnpm-workspace.yaml | 14 +- 36 files changed, 1938 insertions(+), 139 deletions(-) create mode 100644 docs/src/_env/adapter/form.ts create mode 100644 docs/src/_env/adapter/index.ts create mode 100644 docs/src/components/common-ui/vben-count-to-animator.md create mode 100644 docs/src/demos/vben-count-to-animator/basic/index.vue create mode 100644 docs/src/demos/vben-count-to-animator/custom/index.vue create mode 100644 docs/src/demos/vben-form/api/index.vue create mode 100644 docs/src/demos/vben-form/basic/index.vue create mode 100644 docs/src/demos/vben-form/custom/index.vue create mode 100644 docs/src/demos/vben-form/dynamic/index.vue create mode 100644 docs/src/demos/vben-form/query/index.vue create mode 100644 docs/src/demos/vben-form/rules/index.vue diff --git a/apps/web-antd/src/adapter/form.ts b/apps/web-antd/src/adapter/form.ts index ba811917..b55b9b0a 100644 --- a/apps/web-antd/src/adapter/form.ts +++ b/apps/web-antd/src/adapter/form.ts @@ -27,13 +27,13 @@ import { Select, Space, Switch, + Textarea, TimePicker, TreeSelect, Upload, } from 'ant-design-vue'; -// 业务表单组件适配 - +// 这里需要自行根据业务组件库进行适配,需要用到的组件都需要在这里类型说明 export type FormComponentType = | 'AutoComplete' | 'Checkbox' @@ -51,6 +51,7 @@ export type FormComponentType = | 'Select' | 'Space' | 'Switch' + | 'Textarea' | 'TimePicker' | 'TreeSelect' | 'Upload' @@ -83,12 +84,16 @@ setupVbenForm({ Select, Space, Switch, + Textarea, TimePicker, TreeSelect, Upload, }, config: { + // ant design vue组件库默认都是 v-model:value baseModelPropName: 'value', + + // 一些组件是 v-model:checked 或者 v-model:fileList modelPropNameMap: { Checkbox: 'checked', Radio: 'checked', @@ -97,12 +102,14 @@ setupVbenForm({ }, }, defineRules: { + // 输入项目必填国际化适配 required: (value, _params, ctx) => { - if ((!value && value !== 0) || value.length === 0) { + if (value === undefined || value === null || value.length === 0) { return $t('formRules.required', [ctx.label]); } return true; }, + // 选择项目必填国际化适配 selectRequired: (value, _params, ctx) => { if (value === undefined || value === null) { return $t('formRules.selectRequired', [ctx.label]); diff --git a/apps/web-ele/src/adapter/form.ts b/apps/web-ele/src/adapter/form.ts index f5aa854e..b4fa0a06 100644 --- a/apps/web-ele/src/adapter/form.ts +++ b/apps/web-ele/src/adapter/form.ts @@ -73,7 +73,7 @@ setupVbenForm({ }, defineRules: { required: (value, _params, ctx) => { - if ((!value && value !== 0) || value.length === 0) { + if (value === undefined || value === null || value.length === 0) { return $t('formRules.required', [ctx.label]); } return true; diff --git a/apps/web-naive/src/adapter/form.ts b/apps/web-naive/src/adapter/form.ts index 30a86a4a..552919af 100644 --- a/apps/web-naive/src/adapter/form.ts +++ b/apps/web-naive/src/adapter/form.ts @@ -82,7 +82,7 @@ setupVbenForm({ }, defineRules: { required: (value, _params, ctx) => { - if ((!value && value !== 0) || value.length === 0) { + if (value === undefined || value === null || value.length === 0) { return $t('formRules.required', [ctx.label]); } return true; diff --git a/docs/.vitepress/components/demo-preview.vue b/docs/.vitepress/components/demo-preview.vue index 2aba9832..4c8829f8 100644 --- a/docs/.vitepress/components/demo-preview.vue +++ b/docs/.vitepress/components/demo-preview.vue @@ -24,14 +24,16 @@ const parsedFiles = computed(() => { class="not-prose relative w-full overflow-x-auto rounded-t-lg px-4 py-6" >
- -
- - ERROR: - - The preview directory does not exist. Please check the 'dir' - parameter. -
+ + +
+ + ERROR: + + The preview directory does not exist. Please check the 'dir' + parameter. +
+
diff --git a/docs/.vitepress/config/zh.mts b/docs/.vitepress/config/zh.mts index e713a31b..bb054217 100644 --- a/docs/.vitepress/config/zh.mts +++ b/docs/.vitepress/config/zh.mts @@ -154,15 +154,19 @@ function sidebarComponents(): DefaultTheme.SidebarItem[] { items: [ { link: 'common-ui/vben-modal', - text: 'Vben Modal 模态框', + text: 'Modal 模态框', }, { link: 'common-ui/vben-drawer', - text: 'Vben Drawer 抽屉', + text: 'Drawer 抽屉', }, { link: 'common-ui/vben-form', - text: 'Vben Form 表单', + text: 'Form 表单', + }, + { + link: 'common-ui/vben-count-to-animator', + text: 'CountToAnimator 数字动画', }, ], }, diff --git a/docs/.vitepress/theme/components/site-layout.vue b/docs/.vitepress/theme/components/site-layout.vue index dbda5597..d643cae9 100644 --- a/docs/.vitepress/theme/components/site-layout.vue +++ b/docs/.vitepress/theme/components/site-layout.vue @@ -1,30 +1,92 @@