@qin-ui/antd-vue-pro 2.3.3 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qin-ui/antd-vue-pro",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "description": "二次封装antd vue组件",
5
5
  "bin": {
6
6
  "antd-vue-pro": "./bin/init-ai.mjs"
@@ -43,7 +43,7 @@
43
43
  "dependencies": {
44
44
  "scroll-into-view-if-needed": "^3.1.0",
45
45
  "vue-component-type-helpers": "^3.2.5",
46
- "@qin-ui/pro-components-core": "^1.1.1"
46
+ "@qin-ui/pro-components-core": "^1.1.3"
47
47
  },
48
48
  "devDependencies": {
49
49
  "ant-design-vue": "^4"
@@ -13,12 +13,9 @@
13
13
  * ## 渲染流程
14
14
  *
15
15
  * 1. 遍历 fields 数组,过滤 hidden 字段
16
- * 2. 对每个字段:
17
- * a. 通过 PathProvider 提供当前字段路径
18
- * b. 通过 GroupedFieldAttrs 将 field 配置拆分为 gridItemProps / formItemProps / componentProps
19
- * c. 如果字段有 `fields` 子字段 → 递归渲染 BaseFormItem(嵌套表单)
20
- * d. 否则 → 渲染 BaseField(输入组件)
21
- * 3. 通过 ref 回调收集 FormItem 和 Component 实例,注入到 field 对象上
16
+ * 2. 通过 useGroupFieldAttrs Hook 纯计算将 field 配置拆分为 gridItemProps / formItemProps / componentProps / slots
17
+ * 3. 递归渲染 BaseFormItem(嵌套表单)或 BaseField(输入组件)
18
+ * 4. 通过 ref 回调收集 FormItem 和 Component 实例,注入到 field 对象上
22
19
  *
23
20
  * @param {Fields<D>} [fields] - 字段配置数组
24
21
  * @param {boolean | GridProps} [grid] - 是否启用网格布局
@@ -37,8 +34,7 @@ import {
37
34
  import { computed, inject, toValue } from 'vue';
38
35
  import type { Fields, Grid } from '../../types';
39
36
  import { BaseField, SlotComponent, ContainerFragment } from '..';
40
- import PathProvider from '../PathProvider/index.vue';
41
- import GroupedFieldAttrs from '../GroupedFieldAttrs/index.vue';
37
+ import { useGroupFieldAttrs } from '../../hooks/useGroupFieldAttrs';
42
38
  import { INJECT_CONFIG } from '../../../component-provider/constants';
43
39
 
44
40
  defineOptions({ name: 'BaseFormItem', inheritAttrs: false });
@@ -92,6 +88,8 @@ const onComponentMounted = (index: number) => {
92
88
  componentRefs[index]?.getComponentComputedProps(),
93
89
  });
94
90
  };
91
+
92
+ const groupedFields = useGroupFieldAttrs(validFields);
95
93
  </script>
96
94
 
97
95
  <template>
@@ -99,65 +97,51 @@ const onComponentMounted = (index: number) => {
99
97
  :component="enableGrid ? AGrid : undefined"
100
98
  v-bind="computedGridProps"
101
99
  >
102
- <PathProvider
103
- v-for="({ path: _path, name: _name, ...field }, index) of validFields"
104
- :key="toPath(toValue((_name ?? _path) as any)).join('.') || index"
105
- v-bind="{ path: (_name ?? _path) as any }"
106
- >
107
- <template #default="{ path }">
108
- <GroupedFieldAttrs :field="field">
109
- <template
110
- #default="{
111
- gridItemProps,
112
- formItemProps: { formItemContainer, ...formItemProps },
113
- componentProps,
114
- formItemSlots,
115
- }"
100
+ <template v-for="(item, index) of groupedFields" :key="item.path || index">
101
+ <ContainerFragment
102
+ :component="enableGrid ? AGridItem : undefined"
103
+ v-bind="item.gridItemProps"
104
+ >
105
+ <ContainerFragment
106
+ :component="item.formItemContainer"
107
+ :path="item.path"
108
+ >
109
+ <FormItem
110
+ v-bind="item.formItemProps"
111
+ :ref="el => (formItemRefs[index] = el)"
112
+ :name="toPath(item.path)"
113
+ :path="item.path"
114
+ @vue:mounted="onFormItemMounted(index, item.formItemProps)"
116
115
  >
117
- <ContainerFragment
118
- :component="enableGrid ? AGridItem : undefined"
119
- v-bind="gridItemProps"
116
+ <template
117
+ v-for="(slot, name) in item.formItemSlots"
118
+ :key="name"
119
+ #[name]="scoped"
120
120
  >
121
- <ContainerFragment :component="formItemContainer" :path="path">
122
- <FormItem
123
- v-bind="formItemProps"
124
- :ref="el => (formItemRefs[index] = el)"
125
- :name="toPath(path)"
126
- :path="path"
127
- @vue:mounted="onFormItemMounted(index, formItemProps)"
128
- >
129
- <template
130
- v-for="(slot, name) in formItemSlots"
131
- :key="name"
132
- #[name]="scoped"
133
- >
134
- <SlotComponent
135
- :path="path"
136
- :component="slot"
137
- v-bind="scoped"
138
- />
139
- </template>
140
- <template v-if="field.fields">
141
- <BaseFormItem
142
- :grid="(field as any).grid ?? grid"
143
- :fields="field.fields"
144
- :disabled="toValue(field.disabled)"
145
- />
146
- </template>
147
- <template v-else>
148
- <BaseField
149
- :ref="el => (componentRefs[index] = el)"
150
- v-bind="componentProps"
151
- :path="path"
152
- @vue:mounted="onComponentMounted(index)"
153
- />
154
- </template>
155
- </FormItem>
156
- </ContainerFragment>
157
- </ContainerFragment>
158
- </template>
159
- </GroupedFieldAttrs>
160
- </template>
161
- </PathProvider>
121
+ <SlotComponent
122
+ :path="item.path"
123
+ :component="slot"
124
+ v-bind="scoped"
125
+ />
126
+ </template>
127
+ <template v-if="item.rawField.fields">
128
+ <BaseFormItem
129
+ :grid="(item.rawField as any).grid ?? grid"
130
+ :fields="item.rawField.fields"
131
+ :disabled="toValue(item.rawField.disabled)"
132
+ />
133
+ </template>
134
+ <template v-else>
135
+ <BaseField
136
+ :ref="el => (componentRefs[index] = el)"
137
+ v-bind="item.componentProps"
138
+ :path="item.path"
139
+ @vue:mounted="onComponentMounted(index)"
140
+ />
141
+ </template>
142
+ </FormItem>
143
+ </ContainerFragment>
144
+ </ContainerFragment>
145
+ </template>
162
146
  </ContainerFragment>
163
147
  </template>
@@ -126,8 +126,4 @@ export const componentMap: BaseComponentMap = {
126
126
  }
127
127
 
128
128
  // inject keys
129
- export {
130
- InjectionFormKey,
131
- InjectionPathKey,
132
- InjectionFormSlotsKey,
133
- } from '../../../shared/core';
129
+ export { InjectionFormKey, InjectionFormSlotsKey } from '../../../shared/core';
@@ -0,0 +1,120 @@
1
+ import { computed, inject, mergeProps, toValue, type ComputedRef } from 'vue';
2
+ import {
3
+ formItemProps,
4
+ gridItemProps,
5
+ type FormItemProps,
6
+ type GridItemProps,
7
+ } from '../../../shared/ui';
8
+ import { isPlainObject } from '../../../shared/core';
9
+ import { INJECT_CONFIG } from '../../component-provider/constants';
10
+ import { FORM_ITEM_SLOT_KEYS } from '../constants';
11
+ import type { Base, Field } from '../types';
12
+
13
+ const formItemPropKeys = Object.keys(formItemProps()).concat([
14
+ 'formItemContainer',
15
+ ]);
16
+ const gridItemPropKeys = Object.keys(gridItemProps());
17
+
18
+ export interface GroupedField {
19
+ path: string;
20
+ gridItemProps: GridItemProps;
21
+ formItemProps: FormItemProps;
22
+ formItemSlots: Record<(typeof FORM_ITEM_SLOT_KEYS)[number], any>;
23
+ componentProps: Record<string, any>;
24
+ formItemContainer?: Base['formItemContainer'];
25
+ rawField: Field;
26
+ }
27
+
28
+ /**
29
+ * 将 fields 配置数组逐个拆分为 grid / formItem / component / slots 分组。
30
+ */
31
+ export function useGroupFieldAttrs(validFields: ComputedRef<Field[]>) {
32
+ const config = INJECT_CONFIG['pro-form-item'];
33
+ const injectFormItemProps = inject(config.injectionKey, config.default);
34
+
35
+ return computed<GroupedField[]>(() => {
36
+ return validFields.value.map(field => {
37
+ let gridItemProps: Record<string, any> = {};
38
+ let formItemProps: Record<string, any> = {};
39
+ const componentProps: Record<string, any> = { slots: {} };
40
+ const formItemSlots: Record<string, any> = {};
41
+
42
+ if (isPlainObject(field)) {
43
+ // prettier-ignore
44
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
45
+ const { path, name, fields, formItemClass, formItemStyle, hidden, span, getFormItemRef, getComponentRef, getFormItemComputedProps, getComponentComputedProps, slots = {}, formItemDataAttrs = {}, componentDataAttrs = {}, extraProps, formItemContainer, ...rest } =
46
+ field as any;
47
+
48
+ const {
49
+ class: injectClassName,
50
+ style: injectStyle,
51
+ span: injectSpan,
52
+ xs,
53
+ sm,
54
+ md,
55
+ lg,
56
+ xl,
57
+ xxl,
58
+ ...injectRest
59
+ } = injectFormItemProps;
60
+
61
+ const initGridItemProps =
62
+ span || span === 0
63
+ ? { span }
64
+ : { xs, sm, md, lg, xl, xxl, span: injectSpan };
65
+
66
+ gridItemProps = fields ? { span: span ?? 24 } : initGridItemProps;
67
+ formItemProps = mergeProps(
68
+ injectRest,
69
+ { class: injectClassName, style: injectStyle },
70
+ { class: toValue(formItemClass), style: toValue(formItemStyle) },
71
+ formItemDataAttrs
72
+ );
73
+
74
+ Object.keys(rest).forEach(k => {
75
+ if (gridItemPropKeys.includes(k)) {
76
+ gridItemProps[k] = rest[k];
77
+ } else if (formItemPropKeys.includes(k)) {
78
+ formItemProps[k] = rest[k];
79
+ } else {
80
+ componentProps[k] = rest[k];
81
+ }
82
+ });
83
+
84
+ Object.assign(componentProps, componentDataAttrs);
85
+ Object.keys(slots).forEach(k => {
86
+ if (FORM_ITEM_SLOT_KEYS.includes(k as any)) {
87
+ formItemSlots[k] = slots[k];
88
+ } else {
89
+ componentProps.slots[k] = slots[k];
90
+ }
91
+ });
92
+
93
+ const raw = (toValue(name) ?? toValue(path)) as
94
+ | string
95
+ | number[]
96
+ | undefined;
97
+ return {
98
+ path: Array.isArray(raw) ? raw.join('.') : (raw as string) || '',
99
+ gridItemProps: gridItemProps as GridItemProps,
100
+ formItemProps: formItemProps as any,
101
+ formItemSlots,
102
+ componentProps,
103
+ formItemContainer,
104
+ rawField: field,
105
+ };
106
+ }
107
+
108
+ const raw =
109
+ toValue((field as any)?.name) ?? toValue((field as any)?.path);
110
+ return {
111
+ path: Array.isArray(raw) ? raw.join('.') : (raw as string) || '',
112
+ gridItemProps: gridItemProps as GridItemProps,
113
+ formItemProps: formItemProps as any,
114
+ formItemSlots,
115
+ componentProps,
116
+ rawField: field,
117
+ };
118
+ });
119
+ });
120
+ }
@@ -11,7 +11,6 @@ export {
11
11
  useFormRef,
12
12
  // injection keys
13
13
  InjectionFormKey,
14
- InjectionPathKey,
15
14
  InjectionFormSlotsKey,
16
15
  // utils
17
16
  getObject,
@@ -1,29 +0,0 @@
1
- import { GridItemProps, FormItemProps } from '../../../../shared/ui';
2
- import { Base, Field } from '../../types';
3
- import { FORM_ITEM_SLOT_KEYS } from '../../constants';
4
- type Props = {
5
- field: Field;
6
- };
7
- declare function __VLS_template(): {
8
- attrs: Partial<{}>;
9
- slots: {
10
- default?(_: {
11
- gridItemProps: GridItemProps;
12
- formItemProps: FormItemProps & Pick<Base, "formItemContainer">;
13
- formItemSlots: Record<(typeof FORM_ITEM_SLOT_KEYS)[number], any>;
14
- componentProps: Record<string, any>;
15
- }): any;
16
- };
17
- refs: {};
18
- rootEl: any;
19
- };
20
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
21
- declare const __VLS_component: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
22
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
23
- export default _default;
24
- type __VLS_WithTemplateSlots<T, S> = T & {
25
- new (): {
26
- $slots: S;
27
- };
28
- };
29
- //# sourceMappingURL=index.vue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.vue.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/components/GroupedFieldAttrs/index.vue"],"names":[],"mappings":"AA6IA,OAAO,EACL,aAAa,EACb,aAAa,EAGd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAQtD,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AA6EF,iBAAS,cAAc;WAqBT,OAAO,IAA6B;;;2BA1FjC,aAAa;2BACb,aAAa,GAAG,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC;2BAC/C,MAAM,CAAC,CAAC,OAAO,mBAAmB,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC;4BAChD,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;YA6ER,GAAG;;;;EAe/B;AASD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe,sRAMnB,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAQpG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
@@ -1,24 +0,0 @@
1
- import { NamePath } from '../../../../shared/ui';
2
- type __VLS_Props = {
3
- path?: NamePath;
4
- };
5
- declare function __VLS_template(): {
6
- attrs: Partial<{}>;
7
- slots: {
8
- default?(_: {
9
- path: string | undefined;
10
- }): any;
11
- };
12
- refs: {};
13
- rootEl: any;
14
- };
15
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
16
- declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
17
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
18
- export default _default;
19
- type __VLS_WithTemplateSlots<T, S> = T & {
20
- new (): {
21
- $slots: S;
22
- };
23
- };
24
- //# sourceMappingURL=index.vue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.vue.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/components/PathProvider/index.vue"],"names":[],"mappings":"AAuBA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,KAAK,WAAW,GAAG;IAAE,IAAI,CAAC,EAAE,QAAQ,CAAA;CAAE,CAAC;AAavC,iBAAS,cAAc;WAqBT,OAAO,IAA6B;;;;YAVrB,GAAG;;;;EAe/B;AASD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe,kSAMnB,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAQpG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
@@ -1,118 +0,0 @@
1
- <script lang="ts" setup>
2
- /**
3
- * @component GroupedFieldAttrs
4
- * @description 字段属性分组器,将 field 配置对象拆分为三类属性
5
- *
6
- * ## 属性分发逻辑
7
- *
8
- * 单个 field 对象包含多种属性,需要分发到不同的渲染目标:
9
- *
10
- * 1. **gridItemProps** — 网格布局属性(span、xs、sm、md、lg、xl、xxl 等),传递给 GridItem
11
- * 2. **formItemProps** — 表单项属性(label、rules、required 等),传递给 FormItem
12
- * 3. **componentProps** — 组件属性(placeholder、allowClear 等),传递给输入组件
13
- * 4. **formItemSlots** — FormItem 的具名插槽(label、help、extra 等)
14
- *
15
- * 分组依据:
16
- * - 匹配 antd-vue GridItem 的 props key → gridItemProps
17
- * - 匹配 antd-vue FormItem 的 props key → formItemProps
18
- * - 其余所有属性 → componentProps
19
- * - 属于 FORM_ITEM_SLOT_KEYS 的插槽 → formItemSlots
20
- * - 其余插槽 → componentProps.slots
21
- */
22
- import { computed, inject, mergeProps, toValue } from 'vue';
23
- import {
24
- GridItemProps,
25
- FormItemProps,
26
- gridItemProps,
27
- formItemProps,
28
- } from '../../../../shared/ui';
29
- import { INJECT_CONFIG } from '../../../component-provider/constants';
30
- import type { Base, Field } from '../../types';
31
- import { FORM_ITEM_SLOT_KEYS } from '../../constants';
32
- import { isPlainObject } from '../../../../shared/core';
33
-
34
- const formItemPropKeys = Object.keys(formItemProps()).concat([
35
- 'formItemContainer',
36
- ]);
37
- const gridItemPropKeys = Object.keys(gridItemProps());
38
-
39
- type Props = {
40
- field: Field;
41
- };
42
- const props = defineProps<Props>();
43
-
44
- const config = INJECT_CONFIG['pro-form-item'];
45
- const injectFormItemProps = inject(config.injectionKey, config.default);
46
-
47
- type GroupedFieldAttrs = {
48
- gridItemProps: GridItemProps;
49
- formItemProps: FormItemProps & Pick<Base, 'formItemContainer'>;
50
- formItemSlots: Record<(typeof FORM_ITEM_SLOT_KEYS)[number], any>;
51
- componentProps: Record<string, any>;
52
- };
53
-
54
- // 将 field 配置按 key 分发到三类属性分组中
55
- const groupedAttributes = computed<GroupedFieldAttrs>(() => {
56
- let gridItemProps: Record<string, any> = {};
57
- let formItemProps: Record<string, any> = {};
58
- const componentProps: Record<string, any> = { slots: {} };
59
- const formItemSlots: Record<string, any> = {};
60
-
61
- if (isPlainObject(props.field)) {
62
- // prettier-ignore
63
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
64
- const { path, name, fields, formItemClass, formItemStyle, hidden, span, getFormItemRef, getComponentRef, getFormItemComputedProps, getComponentComputedProps, slots = {}, formItemDataAttrs = {}, componentDataAttrs = {}, extraProps, ...rest } =
65
- props.field as any;
66
- const {
67
- class: injectClassName,
68
- style: injectStyle,
69
- span: injectSpan,
70
- xs,
71
- sm,
72
- md,
73
- lg,
74
- xl,
75
- xxl,
76
- ...injectRest
77
- } = injectFormItemProps;
78
-
79
- const initGridItemProps =
80
- span || span === 0
81
- ? { span }
82
- : { xs, sm, md, lg, xl, xxl, span: injectSpan };
83
-
84
- gridItemProps = fields ? { span: span ?? 24 } : initGridItemProps;
85
- formItemProps = mergeProps(
86
- injectRest,
87
- { class: injectClassName, style: injectStyle },
88
- { class: toValue(formItemClass), style: toValue(formItemStyle) },
89
- formItemDataAttrs
90
- );
91
-
92
- Object.keys(rest).forEach(k => {
93
- if (gridItemPropKeys.includes(k)) {
94
- gridItemProps[k] = rest[k];
95
- } else if (formItemPropKeys.includes(k)) {
96
- formItemProps[k as keyof FormItemProps] = rest[k];
97
- } else {
98
- componentProps[k] = rest[k];
99
- }
100
- });
101
-
102
- Object.assign(componentProps, componentDataAttrs);
103
- Object.keys(slots).forEach(k => {
104
- if (FORM_ITEM_SLOT_KEYS.includes(k as any)) {
105
- formItemSlots[k] = slots[k];
106
- } else {
107
- componentProps['slots'][k] = slots[k];
108
- }
109
- });
110
- }
111
-
112
- return { gridItemProps, formItemProps, componentProps, formItemSlots };
113
- });
114
- </script>
115
-
116
- <template>
117
- <slot v-bind="groupedAttributes"></slot>
118
- </template>
@@ -1,19 +0,0 @@
1
- <script lang="ts" setup>
2
- import { computed, provide } from 'vue';
3
- import { InjectionPathKey } from '../../constants';
4
- import { NamePath } from '../../../../shared/ui';
5
-
6
- const props = defineProps<{ path?: NamePath }>();
7
-
8
- const namePath = computed(() => {
9
- return Array.isArray(props.path)
10
- ? props.path.join('.')
11
- : (props.path as string | undefined);
12
- });
13
-
14
- provide(InjectionPathKey, namePath);
15
- </script>
16
-
17
- <template>
18
- <slot :path="namePath" />
19
- </template>