@qin-ui/antd-vue-pro 2.4.4 → 2.4.5

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.4.4",
3
+ "version": "2.4.5",
4
4
  "description": "二次封装antd vue组件",
5
5
  "bin": {
6
6
  "antd-vue-pro": "./bin/init-ai.mjs"
@@ -23,7 +23,8 @@
23
23
  "README.md",
24
24
  "LICENSE",
25
25
  "api.json",
26
- "AI-CONTEXT.md"
26
+ "AI-CONTEXT.md",
27
+ "tsconfig.json"
27
28
  ],
28
29
  "homepage": "https://dufan3715.github.io/pro-components/",
29
30
  "repository": {
@@ -43,7 +44,7 @@
43
44
  "dependencies": {
44
45
  "scroll-into-view-if-needed": "^3.1.0",
45
46
  "vue-component-type-helpers": "^3.2.5",
46
- "@qin-ui/pro-components-core": "^2.0.3"
47
+ "@qin-ui/pro-components-core": "^2.0.4"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@vue/test-utils": "^2.4.11",
@@ -1,6 +1,6 @@
1
1
  import { GridItemProps, FormItemProps, TableProps } from '../../../shared/ui';
2
2
  import { Base, Grid } from '../../form/types';
3
- import { ProFormProps } from '../../form';
3
+ import { ProFormProps } from '../../form/components';
4
4
  import { ProTableProps } from '../../table';
5
5
  import { AllowedComponentProps } from 'vue';
6
6
 
@@ -42,7 +42,8 @@ import {
42
42
  useInjectFormItemContext,
43
43
  } from '../../../../shared/ui';
44
44
  import type { Field } from '../../types';
45
- import { ContainerFragment, SlotComponent } from '..';
45
+ import ContainerFragment from '../ContainerFragment/index.vue';
46
+ import SlotComponent from '../SlotComponent/index.vue';
46
47
  import { componentMap, InjectionFormSlotsKey } from '../../constants';
47
48
  import {
48
49
  INJECT_COMPONENTS,
@@ -52,6 +53,10 @@ import { useForm } from '../../hooks/useForm';
52
53
  import { getInitProps, warnUnknownComponent } from './utils';
53
54
  import { useLocale } from '../../../../locale';
54
55
 
56
+ const cloneDeepIfObject = (val: unknown) =>
57
+ // 原始值直接传递,引用值克隆快照
58
+ typeof val === 'object' && val !== null ? cloneDeep(val) : val;
59
+
55
60
  defineOptions({ name: 'BaseField', inheritAttrs: false });
56
61
 
57
62
  type Props = {
@@ -121,7 +126,7 @@ const value = computed({
121
126
  // 仅当 set 转换函数需要旧值参数时,才获取旧值上下文
122
127
  const oldVal =
123
128
  setFormatter.length > 1
124
- ? cloneDeep(form.getFormData?.(props.path))
129
+ ? cloneDeepIfObject(form.getFormData?.(props.path))
125
130
  : undefined;
126
131
  newVal = setFormatter(val, oldVal);
127
132
  }
@@ -160,7 +165,6 @@ const groupedAttrs = computed(() => {
160
165
  ) as Required<Field>;
161
166
 
162
167
  // prettier-ignore
163
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
164
168
  const { valueFormatter, modelProp, slots, componentClass, componentStyle, componentContainer, [effectiveModelProp]: _modelVal, [`onUpdate:${effectiveModelProp}`]: onUpdateValue, ...bindAttrs } = mergedProps as any;
165
169
 
166
170
  return {
@@ -173,9 +177,9 @@ const groupedAttrs = computed(() => {
173
177
  };
174
178
  });
175
179
 
176
- // 从 ProForm 插槽注入的 slots 集合(优先级最高)
177
- const formSlots = inject(InjectionFormSlotsKey, undefined) as
178
- | Record<string, any>
180
+ // 从 ProForm 插槽注入的 slots 集合(优先级最高;shallowRef 形态,computed 内经 .value 读取建立依赖)
181
+ const injectedFormSlots = inject(InjectionFormSlotsKey, undefined) as
182
+ | { value: Record<string, any> | undefined }
179
183
  | undefined;
180
184
 
181
185
  // 从 ProComponentProvider 注入的自定义组件映射
@@ -186,7 +190,7 @@ const customComponents = inject(INJECT_COMPONENTS, {});
186
190
  * ProForm 插槽 → 自定义组件映射 → 内置组件映射 → 原始 component 值
187
191
  */
188
192
  const is = computed(() => {
189
- const teleportSlot = props.path && formSlots?.[props.path];
193
+ const teleportSlot = props.path && injectedFormSlots?.value?.[props.path];
190
194
  if (teleportSlot) return teleportSlot;
191
195
  if (typeof props.component === 'string') {
192
196
  const resolved =
@@ -33,10 +33,28 @@ import {
33
33
  } from '../../../../shared/ui';
34
34
  import { computed, inject, toRaw, toValue } from 'vue';
35
35
  import type { Fields, Grid } from '../../types';
36
- import { BaseField, SlotComponent, ContainerFragment } from '..';
36
+ import BaseField from '../BaseField/index.vue';
37
+ import SlotComponent from '../SlotComponent/index.vue';
38
+ import ContainerFragment from '../ContainerFragment/index.vue';
37
39
  import { useGroupFieldAttrs } from '../../hooks/useGroupFieldAttrs';
38
40
  import { INJECT_CONFIG } from '../../../component-provider/constants';
39
41
 
42
+ /*
43
+ * 无 path 字段的稳定渲染 key:以字段原始对象为 key 分配自增 id,
44
+ * 字段插删/重排/过滤时保持 key 与对象绑定,不随数组位置漂移
45
+ */
46
+ let fieldKeySeed = 0;
47
+ const fieldKeyMap = new WeakMap<object, number>();
48
+ const getFieldKey = (field: unknown): number => {
49
+ const raw = toRaw(field as object);
50
+ let key = fieldKeyMap.get(raw);
51
+ if (key === undefined) {
52
+ key = ++fieldKeySeed;
53
+ fieldKeyMap.set(raw, key);
54
+ }
55
+ return key;
56
+ };
57
+
40
58
  defineOptions({ name: 'BaseFormItem', inheritAttrs: false });
41
59
 
42
60
  type Props = {
@@ -80,13 +98,41 @@ const computedGridProps = computed<GridProps>(() => {
80
98
  const formItemInstanceMap = new WeakMap<object, any>();
81
99
  const componentInstanceMap = new WeakMap<object, any>();
82
100
 
101
+ /** 已告警过的字段对象(不可写场景去重) */
102
+ const warnedFrozenFields = new WeakSet<object>();
103
+ const defineFieldAccessors = (
104
+ raw: object,
105
+ accessors: Record<string, () => any>
106
+ ) => {
107
+ try {
108
+ for (const [key, getter] of Object.entries(accessors)) {
109
+ // 不可枚举:不进入 Object.keys / spread,不随字段配置透传
110
+ Object.defineProperty(raw, key, {
111
+ value: getter,
112
+ enumerable: false,
113
+ configurable: true,
114
+ writable: true,
115
+ });
116
+ }
117
+ } catch {
118
+ if (!warnedFrozenFields.has(raw)) {
119
+ warnedFrozenFields.add(raw);
120
+ console.warn(
121
+ '[pro-components] 字段配置对象不可写(如被 Object.freeze),getFormItemRef / getComponentRef 等实例访问器挂载失败。'
122
+ );
123
+ }
124
+ }
125
+ };
126
+
83
127
  const setFormItemRef = (field: any, el: any, formItemProps?: any) => {
84
128
  if (!field || typeof field !== 'object') return;
85
129
  const raw = toRaw(field);
86
130
  if (el) {
87
131
  formItemInstanceMap.set(raw, el);
88
- raw.getFormItemRef = () => formItemInstanceMap.get(raw);
89
- raw.getFormItemComputedProps = () => formItemProps;
132
+ defineFieldAccessors(raw, {
133
+ getFormItemRef: () => formItemInstanceMap.get(raw),
134
+ getFormItemComputedProps: () => formItemProps,
135
+ });
90
136
  } else {
91
137
  formItemInstanceMap.delete(raw);
92
138
  delete raw.getFormItemRef;
@@ -99,10 +145,11 @@ const setComponentRef = (field: any, el: any) => {
99
145
  const raw = toRaw(field);
100
146
  if (el) {
101
147
  componentInstanceMap.set(raw, el);
102
- raw.getComponentRef = () =>
103
- componentInstanceMap.get(raw)?.getComponentRef();
104
- raw.getComponentComputedProps = () =>
105
- componentInstanceMap.get(raw)?.getComponentComputedProps();
148
+ defineFieldAccessors(raw, {
149
+ getComponentRef: () => componentInstanceMap.get(raw)?.getComponentRef(),
150
+ getComponentComputedProps: () =>
151
+ componentInstanceMap.get(raw)?.getComponentComputedProps(),
152
+ });
106
153
  } else {
107
154
  componentInstanceMap.delete(raw);
108
155
  delete raw.getComponentRef;
@@ -118,7 +165,10 @@ const groupedFields = useGroupFieldAttrs(validFields);
118
165
  :component="enableGrid ? AGrid : undefined"
119
166
  v-bind="computedGridProps"
120
167
  >
121
- <template v-for="(item, index) of groupedFields" :key="item.path || index">
168
+ <template
169
+ v-for="item of groupedFields"
170
+ :key="item.path || getFieldKey(item.rawField)"
171
+ >
122
172
  <ContainerFragment
123
173
  :component="enableGrid ? AGridItem : undefined"
124
174
  v-bind="item.gridItemProps"
@@ -47,13 +47,16 @@ import {
47
47
  computed,
48
48
  inject,
49
49
  mergeProps,
50
+ onUpdated,
50
51
  provide,
52
+ shallowRef,
51
53
  toValue,
54
+ triggerRef,
52
55
  useAttrs,
53
56
  type Slot,
54
57
  } from 'vue';
55
58
  import { INJECT_CONFIG } from '../../../component-provider/constants';
56
- import { BaseFormItem } from '..';
59
+ import BaseFormItem from '../BaseFormItem/index.vue';
57
60
  import { InjectionFormKey, InjectionFormSlotsKey } from '../../constants';
58
61
  import type { Grid, VModelProps, PathProps } from '../../types';
59
62
  import {
@@ -75,12 +78,12 @@ const props = withDefaults(defineProps<Props>(), {
75
78
 
76
79
  /**
77
80
  * 依赖注入中心:
78
- * 若外部未传 form 实例,则自动初始化内部表单实例;
81
+ * 未传 form 实例(含运行期置空)时惰性初始化内部表单实例;
79
82
  * 将 Form 实例注入到 Vue Context 中,供深层子组件(如 BaseFormItem, BaseField, 自定义插槽)跨层级直接访问数据和方法。
80
83
  */
81
- const fallbackForm = props.form ? undefined : useForm();
84
+ let fallbackForm: F | undefined;
82
85
  const currentForm = computed(
83
- () => props.form ?? (fallbackForm as unknown as F)
86
+ () => props.form ?? (fallbackForm ??= useForm() as unknown as F)
84
87
  );
85
88
 
86
89
  /**
@@ -105,6 +108,7 @@ const setFormRef = (el: any) => currentForm.value?.setFormRef?.(el);
105
108
  let formInstanceCounter = 0;
106
109
  const formInstanceKeyMap = new WeakMap<object, number>();
107
110
  const getFormKey = (f: object) => {
111
+ if (f == null) return 0;
108
112
  if (!formInstanceKeyMap.has(f)) {
109
113
  formInstanceKeyMap.set(f, ++formInstanceCounter);
110
114
  }
@@ -122,7 +126,6 @@ const attrs = useAttrs();
122
126
  */
123
127
  const injectAttrs = computed(() => {
124
128
  const raw = toValue(injectFormConfig);
125
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
126
129
  const { grid: _injectGrid, ...rest } = raw || {};
127
130
  return rest;
128
131
  });
@@ -138,11 +141,15 @@ type FieldSlots = Record<ExtractPath<F>, Slot<FieldSlotProps>>;
138
141
 
139
142
  const slots = defineSlots<Partial<FieldSlots & { default: Slot }>>();
140
143
 
141
- /**
144
+ /*
142
145
  * 动态插槽映射中心 (Slot Teleporting):
143
- * 在 setup 同步期直接提供响应式 slots 上下文容器,供深层 BaseField 按需动态获取插槽
146
+ * slots 以 shallowRef 注入,组件每次更新后触发通知,深层 BaseField 可感知父级运行期增删的具名插槽
144
147
  */
145
- provide(InjectionFormSlotsKey, slots);
148
+ const formSlotsRef = shallowRef<Record<string, any>>(slots);
149
+ onUpdated(() => {
150
+ triggerRef(formSlotsRef);
151
+ });
152
+ provide(InjectionFormSlotsKey, formSlotsRef);
146
153
  </script>
147
154
 
148
155
  <template>
@@ -50,23 +50,11 @@ export function useGroupFieldAttrs(validFields: ComputedRef<Field[]>) {
50
50
 
51
51
  if (isPlainObject(field)) {
52
52
  // prettier-ignore
53
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
54
53
  const { path, name, fields, formItemClass, formItemStyle, hidden, span, getFormItemRef, getComponentRef, getFormItemComputedProps, getComponentComputedProps, slots = {}, formItemDataAttrs = {}, componentDataAttrs = {}, extraProps, formItemContainer, ...rest } =
55
54
  field as any;
56
55
 
57
- const {
58
- class: injectClassName,
59
- style: injectStyle,
60
- span: injectSpan,
61
- xs,
62
- sm,
63
- md,
64
- lg,
65
- xl,
66
- xxl,
67
- formItemContainer: injectFormItemContainer,
68
- ...injectRest
69
- } = rawInject;
56
+ // prettier-ignore
57
+ const { class: injectClassName, style: injectStyle, span: injectSpan, xs, sm, md, lg, xl, xxl, formItemContainer: injectFormItemContainer, ...injectRest } = rawInject;
70
58
 
71
59
  // 字段显式 span 优先,否则回退注入配置的响应式断点
72
60
  const initGridItemProps =
@@ -74,7 +62,10 @@ export function useGroupFieldAttrs(validFields: ComputedRef<Field[]>) {
74
62
  ? { span }
75
63
  : { xs, sm, md, lg, xl, xxl, span: injectSpan };
76
64
 
77
- gridItemProps = fields ? { span: span ?? 24 } : initGridItemProps;
65
+ // 分组字段默认整行(span 兜底 24),注入断点同样生效
66
+ gridItemProps = fields
67
+ ? { ...initGridItemProps, span: span ?? 24 }
68
+ : initGridItemProps;
78
69
  // 字段级容器优先,回退注入级配置
79
70
  const container = formItemContainer ?? injectFormItemContainer;
80
71
  formItemProps = mergeProps(
@@ -80,10 +80,12 @@ const checkedColumnKeys = computed({
80
80
  );
81
81
  },
82
82
  set(val) {
83
+ // 仅写 hidden 发生翻转的列
84
+ const checkedSet = new Set(val);
83
85
  checkedColumnsOptions.value.forEach(item => {
84
- if (item.disabled) return;
86
+ if (item.disabled || item.checked === checkedSet.has(item.value)) return;
85
87
  props.table?.setColumn?.(item.value, {
86
- hidden: !val.includes(item.value),
88
+ hidden: !checkedSet.has(item.value),
87
89
  });
88
90
  });
89
91
  },
@@ -49,7 +49,7 @@ import {
49
49
  type Slot,
50
50
  } from 'vue';
51
51
  import { INJECT_CONFIG } from '../../component-provider/constants';
52
- import { ContainerFragment } from '../../form';
52
+ import ContainerFragment from '../../form/components/ContainerFragment/index.vue';
53
53
  import type { ContainerComponent } from '../../form/types';
54
54
  import SearchForm from './SearchForm.vue';
55
55
  import { SearchFormProps } from './SearchForm.vue';
@@ -64,12 +64,10 @@ import {
64
64
  Path,
65
65
  } from '../../../shared/core';
66
66
  import { ComponentSlots } from 'vue-component-type-helpers';
67
- import {
68
- DefaultSearchFormContainer,
69
- DefaultTableContainer,
70
- SizeControl,
71
- ColumnControl,
72
- } from '.';
67
+ import DefaultSearchFormContainer from './DefaultSearchFormContainer.vue';
68
+ import DefaultTableContainer from './DefaultTableContainer.vue';
69
+ import SizeControl from './SizeControl.vue';
70
+ import ColumnControl from './ColumnControl.vue';
73
71
  import { Column, Columns, ColumnControlConfig } from '../types';
74
72
 
75
73
  defineOptions({ name: 'ProTable', inheritAttrs: false });
@@ -147,10 +145,26 @@ const loading = defineModel<boolean>('loading', { default: false });
147
145
 
148
146
  // 递增序号做请求竞态守卫,仅最新一次请求可变更 loading
149
147
  let searchSequence = 0;
148
+ let warnedSearchConfig = false;
149
+ const warnSearchConfig = (reason: string) => {
150
+ if (warnedSearchConfig) return;
151
+ warnedSearchConfig = true;
152
+ console.warn(`[ProTable] ${reason}`);
153
+ };
150
154
  const _search = async () => {
151
- const seq = ++searchSequence;
155
+ if (props.search && attrs.onSearch) {
156
+ warnSearchConfig(
157
+ '同时配置了 :search prop 与 @search 监听,@search 监听不会被执行,请仅保留其一。'
158
+ );
159
+ }
152
160
  const searchPromise = (props.search || attrs.onSearch)?.();
153
- if (!isPromise(searchPromise)) return;
161
+ if (!isPromise(searchPromise)) {
162
+ warnSearchConfig(
163
+ 'search 未返回 Promise,本次查询不参与 loading 竞态管理(在途请求的 loading 状态保持不变)。'
164
+ );
165
+ return;
166
+ }
167
+ const seq = ++searchSequence;
154
168
  loading.value = true;
155
169
  try {
156
170
  await searchPromise;
@@ -63,8 +63,8 @@ import {
63
63
  type Component,
64
64
  type DefineComponent,
65
65
  } from 'vue';
66
- import ProForm from '../../form';
67
- import { type Form } from '../../form';
66
+ import ProForm from '../../form/components/ProForm/index.vue';
67
+ import { type Form } from '../../form/hooks/useForm';
68
68
  import DownOutlined from './icons/DownOutlined.vue';
69
69
  import { useLocale } from '../../../locale';
70
70
  import { useSearchFormExpand } from '../../../shared/core';
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "strict": true,
8
+ "jsx": "preserve",
9
+ "resolveJsonModule": true,
10
+ "isolatedModules": true,
11
+ "esModuleInterop": true,
12
+ "lib": ["ESNext", "ES2022", "DOM"],
13
+ "baseUrl": ".",
14
+ "types": ["ant-design-vue/typings/global"],
15
+ "declaration": true,
16
+ "declarationMap": true,
17
+ "skipLibCheck": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "noEmit": true
20
+ },
21
+ "include": ["src", "__tests__"],
22
+ "exclude": ["node_modules", "es"]
23
+ }