@longhongguo/form-create-ant-design-vue 3.2.93 → 3.2.95

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": "@longhongguo/form-create-ant-design-vue",
3
- "version": "3.2.93",
3
+ "version": "3.2.95",
4
4
  "description": "AntDesignVue版本低代码表单|FormCreate 是一个可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单生成组件。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。内置20种常用表单组件和自定义组件,再复杂的表单都可以轻松搞定。",
5
5
  "main": "./dist/form-create.min.js",
6
6
  "module": "./dist/form-create.esm.js",
@@ -18,6 +18,84 @@ console.log('[accTable] ✅ accTable.js 文件已加载')
18
18
 
19
19
  export default {
20
20
  name: 'accTable',
21
+ init(ctx) {
22
+ // 在初始化时就设置 beforeFetch 钩子,确保在第一次请求之前就已经添加
23
+ console.log('[accTable] init 被调用')
24
+ const rule = ctx.rule
25
+
26
+ // 如果启用了分页且有远程数据源,在 init 时就添加 beforeFetch 钩子
27
+ if (
28
+ rule.effect?.fetch &&
29
+ rule.props?.pagination &&
30
+ typeof rule.props.pagination === 'object' &&
31
+ rule.props.pagination.current !== undefined
32
+ ) {
33
+ const originalFetch = rule.effect.fetch
34
+ if (typeof originalFetch === 'object') {
35
+ const savedOriginalBeforeFetch = originalFetch.beforeFetch
36
+ const isOurBeforeFetch =
37
+ savedOriginalBeforeFetch &&
38
+ savedOriginalBeforeFetch._accTablePaginationHook === true
39
+
40
+ if (!isOurBeforeFetch) {
41
+ console.log('[accTable] 在 init 中提前设置 beforeFetch 钩子')
42
+ // 获取分页参数配置
43
+ const pageParamName = rule.props?.paginationPageParam || 'page'
44
+ const pageSizeParamName =
45
+ rule.props?.paginationPageSizeParam || 'pageSize'
46
+ const paramType = rule.props?.paginationParamType || 'query'
47
+ const savedRule = rule
48
+
49
+ originalFetch.beforeFetch = (config, { api }) => {
50
+ const currentPagination = savedRule?.props?.pagination
51
+ if (currentPagination && typeof currentPagination === 'object') {
52
+ const currentPage = currentPagination.current || 1
53
+ const currentPageSize = currentPagination.pageSize || 10
54
+
55
+ if (paramType === 'query') {
56
+ config.query = {
57
+ ...(config.query || {}),
58
+ [pageParamName]: currentPage,
59
+ [pageSizeParamName]: currentPageSize
60
+ }
61
+ } else {
62
+ config.data = {
63
+ ...(config.data || {}),
64
+ [pageParamName]: currentPage,
65
+ [pageSizeParamName]: currentPageSize
66
+ }
67
+ }
68
+ }
69
+
70
+ // 调用原始的 beforeFetch 钩子(如果存在)
71
+ if (
72
+ savedOriginalBeforeFetch &&
73
+ typeof savedOriginalBeforeFetch === 'function'
74
+ ) {
75
+ try {
76
+ const result = savedOriginalBeforeFetch(config, { api })
77
+ if (result && typeof result.then === 'function') {
78
+ return result.catch((err) => {
79
+ console.error(
80
+ '[accTable] 原始 beforeFetch 钩子执行出错:',
81
+ err
82
+ )
83
+ return Promise.resolve()
84
+ })
85
+ }
86
+ return result
87
+ } catch (err) {
88
+ console.error('[accTable] 原始 beforeFetch 钩子执行出错:', err)
89
+ }
90
+ }
91
+ }
92
+
93
+ originalFetch.beforeFetch._accTablePaginationHook = true
94
+ console.log('[accTable] ✅ 在 init 中 beforeFetch 钩子已添加')
95
+ }
96
+ }
97
+ }
98
+ },
21
99
  mergeProp(ctx) {
22
100
  console.log('[accTable] ========== mergeProp 被调用 ==========')
23
101
  console.log('[accTable] 调用堆栈:', new Error().stack)
@@ -306,11 +384,11 @@ export default {
306
384
  })
307
385
  }
308
386
 
309
- // 只在首次初始化时添加分页事件处理函数,避免重复设置
310
- if (!paginationInitialized) {
311
- // 添加分页 onChange onShowSizeChange 事件处理(确保事件处理函数存在)
312
- const paginationObj = props.pagination || paginationConfig
313
- if (paginationObj && typeof paginationObj === 'object') {
387
+ // 添加分页 onChange 和 onShowSizeChange 事件处理(确保事件处理函数存在,且只设置一次)
388
+ const paginationObj = props.pagination || paginationConfig
389
+ if (paginationObj && typeof paginationObj === 'object') {
390
+ // 检查是否已经设置过事件处理函数(通过标记判断)
391
+ if (!paginationObj._accTableHandlersSet) {
314
392
  if (!paginationObj.onChange) {
315
393
  paginationObj.onChange = (page, size) => {
316
394
  console.log('[accTable] pagination onChange 被调用:', {
@@ -348,6 +426,9 @@ export default {
348
426
  }
349
427
  }
350
428
 
429
+ // 标记事件处理函数已设置,避免重复设置
430
+ paginationObj._accTableHandlersSet = true
431
+
351
432
  // 如果 props.pagination 不存在,将 paginationObj 赋值给 props.pagination
352
433
  if (!props.pagination) {
353
434
  props.pagination = paginationObj
@@ -110,15 +110,24 @@ export default {
110
110
  ctx.rule.children = []
111
111
  }
112
112
 
113
+ // 读取 childFlex 和 childWidth 配置,用于直接设置到子元素的 style
114
+ const childFlex = props.childFlex ?? ctx.rule.childFlex
115
+ const isVertical =
116
+ flexDirection === 'column' || flexDirection === 'column-reverse'
117
+ const childWidth = isVertical
118
+ ? props.childWidth ?? ctx.rule.childWidth ?? '100%'
119
+ : undefined
120
+
113
121
  // 为 flex 容器的所有子组件设置 col: false,避免被 a-col 包装
122
+ // 同时直接给子元素设置 flex 值和宽度(如果是垂直方向)
114
123
  // 这样可以确保子组件直接作为 flex 子项,而不是占满整行
115
124
  if (ctx.rule.children && Array.isArray(ctx.rule.children)) {
116
125
  ctx.rule.children.forEach((child) => {
117
126
  if (
118
127
  child &&
119
128
  typeof child === 'object' &&
120
- !child.type === 'DragTool' &&
121
- !child.type === 'DragBox'
129
+ child.type !== 'DragTool' &&
130
+ child.type !== 'DragBox'
122
131
  ) {
123
132
  // 只有当 col 未设置或为默认值时才设置
124
133
  if (child.col === undefined || child.col === null) {
@@ -130,6 +139,29 @@ export default {
130
139
  ) {
131
140
  child.col.show = false
132
141
  }
142
+
143
+ // 确保子元素的 style 对象存在(使用响应式的方式)
144
+ if (!child.style) {
145
+ child.style = {}
146
+ }
147
+
148
+ // 如果配置了 childFlex,直接给子元素设置 flex 样式
149
+ // 使用 Object.assign 确保样式对象被正确设置
150
+ if (
151
+ childFlex !== undefined &&
152
+ childFlex !== null &&
153
+ childFlex !== ''
154
+ ) {
155
+ const flexValue = String(childFlex).trim()
156
+ // 直接设置 flex 属性,确保样式能够生效
157
+ Object.assign(child.style, { flex: flexValue })
158
+ }
159
+
160
+ // 如果是垂直方向且配置了 childWidth,直接给子元素设置 width 样式
161
+ if (isVertical && childWidth) {
162
+ const widthValue = String(childWidth).trim()
163
+ Object.assign(child.style, { width: widthValue })
164
+ }
133
165
  }
134
166
  })
135
167
  }
@@ -145,9 +177,10 @@ export default {
145
177
  if (typeof ctx.rule.wrap === 'object' && !ctx.rule.wrap.class) {
146
178
  ctx.rule.wrap.class = ''
147
179
  }
148
- const wrapClass = typeof ctx.rule.wrap === 'object'
149
- ? (ctx.rule.wrap.class || '').split(' ').filter(Boolean)
150
- : []
180
+ const wrapClass =
181
+ typeof ctx.rule.wrap === 'object'
182
+ ? (ctx.rule.wrap.class || '').split(' ').filter(Boolean)
183
+ : []
151
184
  if (!wrapClass.includes('_fc-reset-margin-bottom')) {
152
185
  wrapClass.push('_fc-reset-margin-bottom')
153
186
  if (typeof ctx.rule.wrap === 'object') {
@@ -524,12 +524,22 @@
524
524
  width: auto !important;
525
525
  }
526
526
 
527
- /* Flex 容器子项 flex 样式 */
527
+ /* Flex 容器子项 flex 样式 - 使用通用选择器,匹配所有直接子元素 */
528
+ .ant-flex._fc-flex-container > * {
529
+ flex: var(--fc-child-flex) !important;
530
+ }
531
+
532
+ /* 更具体的选择器,针对被 form-item 包裹的子元素 */
528
533
  .ant-flex._fc-flex-container > .ant-form-item {
529
534
  flex: var(--fc-child-flex) !important;
530
535
  }
531
536
 
532
- /* 垂直方向的 Flex 容器子项宽度样式 */
537
+ /* 垂直方向的 Flex 容器子项宽度样式 - 使用通用选择器 */
538
+ .ant-flex._fc-flex-vertical > * {
539
+ width: var(--fc-child-width, 100%) !important;
540
+ }
541
+
542
+ /* 更具体的选择器,针对被 form-item 包裹的子元素 */
533
543
  .ant-flex._fc-flex-vertical > .ant-form-item {
534
544
  width: var(--fc-child-width, 100%) !important;
535
545
  }