Skip to content

Commit 5ce3a18

Browse files
authored
docs: update docs (#4466)
* chore: fixed known issues with form components * docs: add vben form doc
1 parent dac8070 commit 5ce3a18

File tree

36 files changed

+1938
-139
lines changed

36 files changed

+1938
-139
lines changed

apps/web-antd/src/adapter/form.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ import {
2727
Select,
2828
Space,
2929
Switch,
30+
Textarea,
3031
TimePicker,
3132
TreeSelect,
3233
Upload,
3334
} from 'ant-design-vue';
3435

35-
// 业务表单组件适配
36-
36+
// 这里需要自行根据业务组件库进行适配,需要用到的组件都需要在这里类型说明
3737
export type FormComponentType =
3838
| 'AutoComplete'
3939
| 'Checkbox'
@@ -51,6 +51,7 @@ export type FormComponentType =
5151
| 'Select'
5252
| 'Space'
5353
| 'Switch'
54+
| 'Textarea'
5455
| 'TimePicker'
5556
| 'TreeSelect'
5657
| 'Upload'
@@ -83,12 +84,16 @@ setupVbenForm<FormComponentType>({
8384
Select,
8485
Space,
8586
Switch,
87+
Textarea,
8688
TimePicker,
8789
TreeSelect,
8890
Upload,
8991
},
9092
config: {
93+
// ant design vue组件库默认都是 v-model:value
9194
baseModelPropName: 'value',
95+
96+
// 一些组件是 v-model:checked 或者 v-model:fileList
9297
modelPropNameMap: {
9398
Checkbox: 'checked',
9499
Radio: 'checked',
@@ -97,12 +102,14 @@ setupVbenForm<FormComponentType>({
97102
},
98103
},
99104
defineRules: {
105+
// 输入项目必填国际化适配
100106
required: (value, _params, ctx) => {
101-
if ((!value && value !== 0) || value.length === 0) {
107+
if (value === undefined || value === null || value.length === 0) {
102108
return $t('formRules.required', [ctx.label]);
103109
}
104110
return true;
105111
},
112+
// 选择项目必填国际化适配
106113
selectRequired: (value, _params, ctx) => {
107114
if (value === undefined || value === null) {
108115
return $t('formRules.selectRequired', [ctx.label]);

apps/web-ele/src/adapter/form.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ setupVbenForm<FormComponentType>({
7373
},
7474
defineRules: {
7575
required: (value, _params, ctx) => {
76-
if ((!value && value !== 0) || value.length === 0) {
76+
if (value === undefined || value === null || value.length === 0) {
7777
return $t('formRules.required', [ctx.label]);
7878
}
7979
return true;

apps/web-naive/src/adapter/form.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ setupVbenForm<FormComponentType>({
8282
},
8383
defineRules: {
8484
required: (value, _params, ctx) => {
85-
if ((!value && value !== 0) || value.length === 0) {
85+
if (value === undefined || value === null || value.length === 0) {
8686
return $t('formRules.required', [ctx.label]);
8787
}
8888
return true;

docs/.vitepress/components/demo-preview.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ const parsedFiles = computed(() => {
2424
class="not-prose relative w-full overflow-x-auto rounded-t-lg px-4 py-6"
2525
>
2626
<div class="flex w-full max-w-[700px] px-2">
27-
<slot v-if="parsedFiles.length > 0"></slot>
28-
<div v-else class="text-destructive text-sm">
29-
<span class="bg-destructive text-foreground rounded-sm px-1 py-1">
30-
ERROR:
31-
</span>
32-
The preview directory does not exist. Please check the 'dir'
33-
parameter.
34-
</div>
27+
<ClientOnly>
28+
<slot v-if="parsedFiles.length > 0"></slot>
29+
<div v-else class="text-destructive text-sm">
30+
<span class="bg-destructive text-foreground rounded-sm px-1 py-1">
31+
ERROR:
32+
</span>
33+
The preview directory does not exist. Please check the 'dir'
34+
parameter.
35+
</div>
36+
</ClientOnly>
3537
</div>
3638
</div>
3739
<PreviewGroup v-if="parsedFiles.length > 0" :files="parsedFiles">

docs/.vitepress/config/zh.mts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,19 @@ function sidebarComponents(): DefaultTheme.SidebarItem[] {
154154
items: [
155155
{
156156
link: 'common-ui/vben-modal',
157-
text: 'Vben Modal 模态框',
157+
text: 'Modal 模态框',
158158
},
159159
{
160160
link: 'common-ui/vben-drawer',
161-
text: 'Vben Drawer 抽屉',
161+
text: 'Drawer 抽屉',
162162
},
163163
{
164164
link: 'common-ui/vben-form',
165-
text: 'Vben Form 表单',
165+
text: 'Form 表单',
166+
},
167+
{
168+
link: 'common-ui/vben-count-to-animator',
169+
text: 'CountToAnimator 数字动画',
166170
},
167171
],
168172
},

docs/.vitepress/theme/components/site-layout.vue

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,92 @@
11
<script lang="ts" setup>
2-
import { nextTick, onMounted, watch } from 'vue';
2+
import {
3+
computed,
4+
nextTick,
5+
onBeforeUnmount,
6+
onMounted,
7+
ref,
8+
watch,
9+
} from 'vue';
310
11+
// import { useAntdDesignTokens } from '@vben/hooks';
12+
// import { initPreferences } from '@vben/preferences';
13+
14+
import { ConfigProvider, theme } from 'ant-design-vue';
415
import mediumZoom from 'medium-zoom';
516
import { useRoute } from 'vitepress';
617
import DefaultTheme from 'vitepress/theme';
718
819
const { Layout } = DefaultTheme;
920
const route = useRoute();
21+
// const { tokens } = useAntdDesignTokens();
1022
1123
const initZoom = () => {
1224
// mediumZoom('[data-zoomable]', { background: 'var(--vp-c-bg)' });
1325
mediumZoom('.VPContent img', { background: 'var(--vp-c-bg)' });
1426
};
1527
28+
const isDark = ref(true);
29+
1630
watch(
1731
() => route.path,
1832
() => nextTick(() => initZoom()),
1933
);
2034
35+
// initPreferences({
36+
// namespace: 'docs',
37+
// });
38+
2139
onMounted(() => {
2240
initZoom();
2341
});
42+
43+
// 使用该函数
44+
const observer = watchDarkModeChange((dark) => {
45+
isDark.value = dark;
46+
});
47+
48+
onBeforeUnmount(() => {
49+
observer?.disconnect();
50+
});
51+
52+
function watchDarkModeChange(callback: (isDark: boolean) => void) {
53+
if (typeof window === 'undefined') {
54+
return;
55+
}
56+
const htmlElement = document.documentElement;
57+
58+
const observer = new MutationObserver(() => {
59+
const isDark = htmlElement.classList.contains('dark');
60+
callback(isDark);
61+
});
62+
63+
observer.observe(htmlElement, {
64+
attributeFilter: ['class'],
65+
attributes: true,
66+
});
67+
68+
const initialIsDark = htmlElement.classList.contains('dark');
69+
callback(initialIsDark);
70+
71+
return observer;
72+
}
73+
74+
const tokenTheme = computed(() => {
75+
const algorithm = isDark.value
76+
? [theme.darkAlgorithm]
77+
: [theme.defaultAlgorithm];
78+
79+
return {
80+
algorithm,
81+
// token: tokens,
82+
};
83+
});
2484
</script>
2585

2686
<template>
27-
<Layout />
87+
<ConfigProvider :theme="tokenTheme">
88+
<Layout />
89+
</ConfigProvider>
2890
</template>
2991

3092
<style>

docs/.vitepress/theme/styles/base.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ html.dark {
55
.dark .VPContent {
66
/* background-color: #14161a; */
77
}
8+
9+
.form-valid-error p {
10+
margin: 0;
11+
}

docs/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
"dev": "vitepress dev",
88
"docs:preview": "vitepress preview"
99
},
10+
"imports": {
11+
"#/*": "./src/_env/*"
12+
},
1013
"dependencies": {
1114
"@vben-core/shadcn-ui": "workspace:*",
1215
"@vben/common-ui": "workspace:*",
16+
"@vben/hooks": "workspace:*",
17+
"@vben/locales": "workspace:*",
18+
"@vben/preferences": "workspace:*",
1319
"@vben/styles": "workspace:*",
20+
"ant-design-vue": "catalog:",
1421
"lucide-vue-next": "catalog:",
1522
"medium-zoom": "catalog:",
1623
"radix-vue": "catalog:",

docs/src/_env/adapter/form.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import type {
2+
BaseFormComponentType,
3+
VbenFormSchema as FormSchema,
4+
VbenFormProps,
5+
} from '@vben/common-ui';
6+
7+
import { h } from 'vue';
8+
9+
import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
10+
import { $t } from '@vben/locales';
11+
12+
import {
13+
AutoComplete,
14+
Button,
15+
Checkbox,
16+
CheckboxGroup,
17+
DatePicker,
18+
Divider,
19+
Input,
20+
InputNumber,
21+
InputPassword,
22+
Mentions,
23+
Radio,
24+
RadioGroup,
25+
RangePicker,
26+
Rate,
27+
Select,
28+
Space,
29+
Switch,
30+
Textarea,
31+
TimePicker,
32+
TreeSelect,
33+
Upload,
34+
} from 'ant-design-vue';
35+
36+
// 这里需要自行根据业务组件库进行适配,需要用到的组件都需要在这里类型说明
37+
export type FormComponentType =
38+
| 'AutoComplete'
39+
| 'Checkbox'
40+
| 'CheckboxGroup'
41+
| 'DatePicker'
42+
| 'Divider'
43+
| 'Input'
44+
| 'InputNumber'
45+
| 'InputPassword'
46+
| 'Mentions'
47+
| 'Radio'
48+
| 'RadioGroup'
49+
| 'RangePicker'
50+
| 'Rate'
51+
| 'Select'
52+
| 'Space'
53+
| 'Switch'
54+
| 'Textarea'
55+
| 'TimePicker'
56+
| 'TreeSelect'
57+
| 'Upload'
58+
| BaseFormComponentType;
59+
60+
// 初始化表单组件,并注册到form组件内部
61+
setupVbenForm<FormComponentType>({
62+
components: {
63+
AutoComplete,
64+
Checkbox,
65+
CheckboxGroup,
66+
DatePicker,
67+
// 自定义默认的重置按钮
68+
DefaultResetActionButton: (props, { attrs, slots }) => {
69+
return h(Button, { ...props, attrs, type: 'default' }, slots);
70+
},
71+
// 自定义默认的提交按钮
72+
DefaultSubmitActionButton: (props, { attrs, slots }) => {
73+
return h(Button, { ...props, attrs, type: 'primary' }, slots);
74+
},
75+
Divider,
76+
Input,
77+
InputNumber,
78+
InputPassword,
79+
Mentions,
80+
Radio,
81+
RadioGroup,
82+
RangePicker,
83+
Rate,
84+
Select,
85+
Space,
86+
Switch,
87+
Textarea,
88+
TimePicker,
89+
TreeSelect,
90+
Upload,
91+
},
92+
config: {
93+
// ant design vue组件库默认都是 v-model:value
94+
baseModelPropName: 'value',
95+
96+
// 一些组件是 v-model:checked 或者 v-model:fileList
97+
modelPropNameMap: {
98+
Checkbox: 'checked',
99+
Radio: 'checked',
100+
Switch: 'checked',
101+
Upload: 'fileList',
102+
},
103+
},
104+
defineRules: {
105+
// 输入项目必填国际化适配
106+
required: (value, _params, ctx) => {
107+
if (value === undefined || value === null || value.length === 0) {
108+
return $t('formRules.required', [ctx.label]);
109+
}
110+
return true;
111+
},
112+
// 选择项目必填国际化适配
113+
selectRequired: (value, _params, ctx) => {
114+
if (value === undefined || value === null) {
115+
return $t('formRules.selectRequired', [ctx.label]);
116+
}
117+
return true;
118+
},
119+
},
120+
});
121+
122+
const useVbenForm = useForm<FormComponentType>;
123+
124+
export { useVbenForm, z };
125+
126+
export type VbenFormSchema = FormSchema<FormComponentType>;
127+
export type { VbenFormProps };

docs/src/_env/adapter/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './form';

0 commit comments

Comments
 (0)