@longhongguo/form-create-ant-design-vue 3.3.13 → 3.3.15

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.3.13",
3
+ "version": "3.3.15",
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",
@@ -14,14 +14,10 @@ function getValue(obj, path) {
14
14
  return value
15
15
  }
16
16
 
17
- // 文件加载时立即打印
18
- console.log('[accTable] ✅ accTable.js 文件已加载')
19
-
20
17
  export default {
21
18
  name: 'accTable',
22
19
  init(ctx) {
23
20
  // 在初始化时就设置 beforeFetch 钩子,确保在第一次请求之前就已经添加
24
- console.log('[accTable] init 被调用')
25
21
  const rule = ctx.rule
26
22
 
27
23
  // 如果启用了分页且有远程数据源,在 init 时就添加 beforeFetch 钩子
@@ -39,7 +35,6 @@ export default {
39
35
  savedOriginalBeforeFetch._accTablePaginationHook === true
40
36
 
41
37
  if (!isOurBeforeFetch) {
42
- console.log('[accTable] 在 init 中提前设置 beforeFetch 钩子')
43
38
  // 获取分页参数配置
44
39
  const pageParamName = rule.props?.paginationPageParam || 'page'
45
40
  const pageSizeParamName =
@@ -92,31 +87,15 @@ export default {
92
87
  }
93
88
 
94
89
  originalFetch.beforeFetch._accTablePaginationHook = true
95
- console.log('[accTable] ✅ 在 init 中 beforeFetch 钩子已添加')
96
90
  }
97
91
  }
98
92
  }
99
93
  },
100
94
  mergeProp(ctx) {
101
- console.log('[accTable] ========== mergeProp 被调用 ==========')
102
- console.log('[accTable] 调用堆栈:', new Error().stack)
103
95
  const props = ctx.prop.props || {}
104
96
  const rule = ctx.rule
105
97
  const api = ctx.api
106
98
 
107
- console.log('[accTable] mergeProp 基本信息:', {
108
- ruleType: rule.type,
109
- ruleName: rule.name,
110
- hasEffect: !!rule.effect,
111
- hasFetch: !!rule.effect?.fetch,
112
- fetchValue: rule.effect?.fetch,
113
- fetchType: typeof rule.effect?.fetch,
114
- hasPagination: !!rule.props?.pagination,
115
- paginationConfig: rule.props?.pagination,
116
- paginationType: typeof rule.props?.pagination,
117
- allRuleProps: Object.keys(rule.props || {})
118
- })
119
-
120
99
  // 处理列配置 - 每次都要更新,确保 width 等属性变化时能生效
121
100
  let columns = rule.props?.columns || []
122
101
  // Struct 组件返回的是数组对象,直接使用;如果是字符串,尝试解析为 JSON(向后兼容)
@@ -173,57 +152,39 @@ export default {
173
152
  ) {
174
153
  const cellType = column.cellType
175
154
  const dataIndex = column.dataIndex
176
- // 确保 cellOptions 是数组
177
- let cellOptions = column.cellOptions
178
- if (!Array.isArray(cellOptions)) {
179
- cellOptions = []
180
- }
181
155
  const cellProps = column.cellProps || {}
182
156
 
183
- // 创建 customRender 函数
184
- column.customRender = ({ text, record, index }) => {
185
- const cellValue = record && dataIndex ? record[dataIndex] : text
186
- // render 函数内部再次确保 cellOptions 是数组(因为可能在外部被修改)
187
- const options = Array.isArray(column.cellOptions)
188
- ? column.cellOptions
189
- : []
190
-
191
- if (cellType === 'input') {
192
- // 渲染 input 组件 - 使用组件名字符串
193
- return h('a-input', {
194
- value: cellValue,
195
- onChange: (e) => {
196
- const val =
197
- e.target?.value !== undefined
198
- ? e.target.value
199
- : e?.target?.inputValue !== undefined
200
- ? e.target.inputValue
201
- : e
202
- if (record && dataIndex) {
203
- record[dataIndex] = val
204
- // 触发表格数据更新
205
- if (ctx.api && ctx.api.form && rule.field) {
206
- ctx.api.form[rule.field] = props.dataSource
207
- }
208
- }
209
- },
210
- placeholder: cellProps.placeholder || '',
211
- disabled: cellProps.disabled || false,
212
- size: cellProps.size || 'small',
213
- ...cellProps
214
- })
215
- } else if (cellType === 'select') {
216
- // 渲染 select 组件 - 使用组件名字符串
217
- return h(
218
- 'a-select',
219
- {
157
+ // 创建 customRender 函数,通过闭包访问 ctx
158
+ column.customRender = (() => {
159
+ // 在闭包中保存 ctx 的引用
160
+ const renderCtx = ctx
161
+ return ({ text, record, index }) => {
162
+ const cellValue = record && dataIndex ? record[dataIndex] : text
163
+ // 将 cellOptions 转换为数组格式(支持对象和数组两种格式)
164
+ let options = []
165
+ const cellOptions = column.cellOptions
166
+ if (Array.isArray(cellOptions)) {
167
+ // 如果已经是数组,直接使用
168
+ options = cellOptions
169
+ } else if (cellOptions && typeof cellOptions === 'object') {
170
+ // 如果是对象,转换为数组格式 { 是: 1, 否: 0 } => [{label: '是', value: 1}, {label: '否', value: 0}]
171
+ options = Object.keys(cellOptions).map((label) => ({
172
+ label,
173
+ value: cellOptions[label]
174
+ }))
175
+ }
176
+
177
+ if (cellType === 'input') {
178
+ // 渲染 input 组件,使用 ctx.$render.vNode 来创建
179
+ return renderCtx.$render.vNode.make('aInput', {
220
180
  value: cellValue,
221
- onChange: (val) => {
181
+ 'onUpdate:value': (val) => {
182
+ // Ant Design Vue 的 Input 使用 value 和 onUpdate:value
222
183
  if (record && dataIndex) {
223
184
  record[dataIndex] = val
224
185
  // 触发表格数据更新
225
- if (ctx.api && ctx.api.form && rule.field) {
226
- ctx.api.form[rule.field] = props.dataSource
186
+ if (renderCtx.api && renderCtx.api.form && rule.field) {
187
+ renderCtx.api.form[rule.field] = props.dataSource
227
188
  }
228
189
  }
229
190
  },
@@ -231,60 +192,101 @@ export default {
231
192
  disabled: cellProps.disabled || false,
232
193
  size: cellProps.size || 'small',
233
194
  ...cellProps
234
- },
235
- {
236
- default: () =>
237
- options.map((opt) => {
238
- return h('a-select-option', {
239
- key: opt.value,
240
- value: opt.value,
241
- label: opt.label
242
- })
243
- })
244
- }
245
- )
246
- } else if (cellType === 'radio') {
247
- // 渲染 radio 组件 - 使用组件名字符串
248
- return h(
249
- 'a-radio-group',
250
- {
251
- value: cellValue,
252
- onChange: (e) => {
253
- const val =
254
- e.target?.value !== undefined ? e.target.value : e
255
- if (record && dataIndex) {
256
- record[dataIndex] = val
257
- // 触发表格数据更新
258
- if (ctx.api && ctx.api.form && rule.field) {
259
- ctx.api.form[rule.field] = props.dataSource
195
+ })
196
+ } else if (cellType === 'select') {
197
+ // 渲染 select 组件
198
+ return renderCtx.$render.vNode.make(
199
+ 'aSelect',
200
+ {
201
+ value: cellValue,
202
+ 'onUpdate:value': (val) => {
203
+ // Ant Design Vue 的 Select 使用 value 和 onUpdate:value
204
+ if (record && dataIndex) {
205
+ record[dataIndex] = val
206
+ // 触发表格数据更新
207
+ if (renderCtx.api && renderCtx.api.form && rule.field) {
208
+ renderCtx.api.form[rule.field] = props.dataSource
209
+ }
260
210
  }
261
- }
211
+ },
212
+ placeholder: cellProps.placeholder || '',
213
+ disabled: cellProps.disabled || false,
214
+ size: cellProps.size || 'small',
215
+ ...cellProps
262
216
  },
263
- disabled: cellProps.disabled || false,
264
- size: cellProps.size || 'small',
265
- ...cellProps
266
- },
267
- {
268
- default: () =>
269
- options.map((opt) => {
270
- return h(
271
- 'a-radio',
272
- {
273
- key: opt.value,
274
- value: opt.value
275
- },
276
- {
277
- default: () => opt.label || opt.value
278
- }
279
- )
217
+ options.map((opt) => {
218
+ return renderCtx.$render.vNode.make('aSelectOption', {
219
+ key: opt.value,
220
+ value: opt.value,
221
+ label: opt.label
280
222
  })
223
+ })
224
+ )
225
+ } else if (cellType === 'radio') {
226
+ // 渲染 radio 组件
227
+ // 当 cellValue 是 null 或 undefined 时,确保 modelValue 是 undefined
228
+ const radioValue =
229
+ cellValue !== null && cellValue !== undefined
230
+ ? cellValue
231
+ : undefined
232
+
233
+ // 使用 ctx.$render.vNode.h 创建组件,确保组件名正确解析
234
+ // Radio 的 children 需要作为函数传递,避免警告
235
+ const radioChildren = options.map((opt) => {
236
+ return renderCtx.$render.vNode.h(
237
+ 'aRadio',
238
+ {
239
+ key: opt.value,
240
+ value: opt.value
241
+ },
242
+ {
243
+ default: () => opt.label || opt.value
244
+ }
245
+ )
246
+ })
247
+
248
+ // 统一的值更新处理函数
249
+ const handleValueChange = (val) => {
250
+ if (record && dataIndex) {
251
+ record[dataIndex] = val
252
+ // 触发表格数据更新
253
+ if (renderCtx.api && renderCtx.api.form && rule.field) {
254
+ renderCtx.api.form[rule.field] = props.dataSource
255
+ }
256
+ // 触发同步更新
257
+ if (renderCtx.api && renderCtx.api.sync) {
258
+ renderCtx.api.sync(rule)
259
+ }
260
+ }
281
261
  }
282
- )
283
- }
284
262
 
285
- // 如果没有匹配的类型,返回原始文本
286
- return text
287
- }
263
+ return renderCtx.$render.vNode.h(
264
+ 'aRadioGroup',
265
+ {
266
+ value: radioValue,
267
+ onChange: (e) => {
268
+ // Ant Design Vue 的 RadioGroup onChange 直接传递 value 作为参数
269
+ // 但也可能是事件对象,兼容两种方式
270
+ const val =
271
+ typeof e === 'object' && e?.target?.value !== undefined
272
+ ? e.target.value
273
+ : e
274
+ handleValueChange(val)
275
+ },
276
+ disabled: cellProps.disabled || false,
277
+ size: cellProps.size || 'small',
278
+ ...cellProps
279
+ },
280
+ {
281
+ default: () => radioChildren
282
+ }
283
+ )
284
+ }
285
+
286
+ // 如果没有匹配的类型,返回原始文本
287
+ return text
288
+ }
289
+ })()
288
290
  }
289
291
 
290
292
  // 确保其他列属性也被保留(align、fixed、title、dataIndex 等)
@@ -330,20 +332,9 @@ export default {
330
332
 
331
333
  // 处理分页配置
332
334
  const paginationConfig = rule.props?.pagination
333
- console.log('[accTable] 开始处理分页配置:', {
334
- hasPaginationProp: hasProperty(props, 'pagination'),
335
- paginationConfig,
336
- paginationConfigType: typeof paginationConfig
337
- })
338
335
 
339
336
  // 处理分页 props(只有在 props 中没有 pagination 时才初始化)
340
337
  if (!hasProperty(props, 'pagination')) {
341
- console.log('[accTable] 分页配置检查:', {
342
- paginationConfig,
343
- isFalse: paginationConfig === false,
344
- isObject: paginationConfig && typeof paginationConfig === 'object'
345
- })
346
-
347
338
  if (paginationConfig === false) {
348
339
  props.pagination = false
349
340
  } else if (paginationConfig && typeof paginationConfig === 'object') {
@@ -365,22 +356,12 @@ export default {
365
356
  }
366
357
 
367
358
  // 无论 props.pagination 是否已存在,只要满足条件就添加/检查 beforeFetch 钩子
368
- console.log('[accTable] 检查分页钩子添加条件:', {
369
- hasFetch: !!rule.effect?.fetch,
370
- hasPaginationConfig: !!paginationConfig,
371
- paginationConfigType: typeof paginationConfig,
372
- paginationConfigValue: paginationConfig,
373
- paginationCurrent: paginationConfig?.current,
374
- paginationCurrentDefined: paginationConfig?.current !== undefined
375
- })
376
-
377
359
  if (
378
360
  rule.effect?.fetch &&
379
361
  paginationConfig &&
380
362
  typeof paginationConfig === 'object' &&
381
363
  paginationConfig.current !== undefined
382
364
  ) {
383
- console.log('[accTable] ✅ 满足条件,进入分页请求参数处理逻辑')
384
365
  // 获取分页参数配置
385
366
  const pageParamName = rule.props?.paginationPageParam || 'page'
386
367
  const pageSizeParamName =
@@ -393,24 +374,8 @@ export default {
393
374
  // 获取当前分页对象(从 props 或 paginationConfig)
394
375
  const currentPaginationObj = props.pagination || paginationConfig
395
376
 
396
- console.log('[accTable] 分页配置初始化:', {
397
- hasFetch: !!rule.effect?.fetch,
398
- paginationConfig,
399
- pageParamName,
400
- pageSizeParamName,
401
- paramType,
402
- currentPage: currentPaginationObj?.current,
403
- currentPageSize: currentPaginationObj?.pageSize
404
- })
405
-
406
377
  // 包装 fetch 配置,通过 beforeFetch 钩子动态注入分页参数
407
378
  const originalFetch = rule.effect.fetch
408
- console.log('[accTable] 原始 fetch 配置:', {
409
- type: typeof originalFetch,
410
- isObject: typeof originalFetch === 'object',
411
- originalFetch,
412
- hasBeforeFetch: typeof originalFetch?.beforeFetch === 'function'
413
- })
414
379
 
415
380
  if (typeof originalFetch === 'object') {
416
381
  // 保存原始配置和分页参数配置到闭包中
@@ -430,36 +395,13 @@ export default {
430
395
  // 添加 beforeFetch 钩子来注入分页参数
431
396
  // 注意:form-create 的 beforeFetch 只接收 (config, {api}) 参数,没有 rule
432
397
  originalFetch.beforeFetch = (config, { api }) => {
433
- console.log('[accTable] beforeFetch 被调用:', {
434
- configAction: config?.action,
435
- hasApi: !!api,
436
- ruleProps: savedRule?.props,
437
- pagination: savedRule?.props?.pagination
438
- })
439
-
440
398
  // 从闭包中获取当前分页配置
441
399
  const currentPagination = savedRule?.props?.pagination
442
- console.log('[accTable] 当前分页配置:', {
443
- currentPagination,
444
- isObject: typeof currentPagination === 'object',
445
- currentPage: currentPagination?.current,
446
- currentPageSize: currentPagination?.pageSize
447
- })
448
400
 
449
401
  if (currentPagination && typeof currentPagination === 'object') {
450
402
  const currentPage = currentPagination.current || 1
451
403
  const currentPageSize = currentPagination.pageSize || 10
452
404
 
453
- console.log('[accTable] 准备添加分页参数:', {
454
- savedParamType,
455
- savedPageParamName,
456
- savedPageSizeParamName,
457
- currentPage,
458
- currentPageSize,
459
- existingQuery: config.query,
460
- existingData: config.data
461
- })
462
-
463
405
  // 添加分页参数(使用闭包中保存的参数名)
464
406
  if (savedParamType === 'query') {
465
407
  // 合并已有的 query 参数,确保不覆盖用户自定义的参数
@@ -468,9 +410,6 @@ export default {
468
410
  [savedPageParamName]: currentPage,
469
411
  [savedPageSizeParamName]: currentPageSize
470
412
  }
471
- console.log('[accTable] 添加 query 参数后:', {
472
- query: config.query
473
- })
474
413
  } else {
475
414
  // 合并已有的 data 参数,确保不覆盖用户自定义的参数
476
415
  config.data = {
@@ -478,9 +417,6 @@ export default {
478
417
  [savedPageParamName]: currentPage,
479
418
  [savedPageSizeParamName]: currentPageSize
480
419
  }
481
- console.log('[accTable] 添加 data 参数后:', {
482
- data: config.data
483
- })
484
420
  }
485
421
  } else {
486
422
  console.warn('[accTable] 分页配置无效,无法添加分页参数:', {
@@ -496,7 +432,6 @@ export default {
496
432
  savedOriginalBeforeFetch &&
497
433
  typeof savedOriginalBeforeFetch === 'function'
498
434
  ) {
499
- console.log('[accTable] 调用原始 beforeFetch 钩子')
500
435
  try {
501
436
  const result = savedOriginalBeforeFetch(config, { api })
502
437
  // 如果原始钩子返回了 Promise,处理它
@@ -516,21 +451,11 @@ export default {
516
451
  // 即使原始钩子出错,也继续执行,不影响分页参数的添加
517
452
  }
518
453
  }
519
-
520
- console.log('[accTable] beforeFetch 完成,最终 config:', {
521
- query: config.query,
522
- data: config.data,
523
- action: config.action
524
- })
525
454
  }
526
455
 
527
456
  // 标记这是我们添加的钩子,避免重复添加
528
457
  originalFetch.beforeFetch._accTablePaginationHook = true
529
- console.log('[accTable] ✅ beforeFetch 钩子已添加并标记')
530
- } else {
531
- console.log('[accTable] ⚠️ beforeFetch 钩子已存在,跳过添加')
532
458
  }
533
- console.log('[accTable] beforeFetch 钩子处理完成')
534
459
  } else {
535
460
  console.warn('[accTable] fetch 配置不是对象类型:', {
536
461
  type: typeof originalFetch,
@@ -545,10 +470,6 @@ export default {
545
470
  if (!paginationObj._accTableHandlersSet) {
546
471
  if (!paginationObj.onChange) {
547
472
  paginationObj.onChange = (page, size) => {
548
- console.log('[accTable] pagination onChange 被调用:', {
549
- page,
550
- size
551
- })
552
473
  // 更新分页配置
553
474
  if (rule.props?.pagination) {
554
475
  rule.props.pagination.current = page
@@ -564,10 +485,6 @@ export default {
564
485
 
565
486
  if (!paginationObj.onShowSizeChange) {
566
487
  paginationObj.onShowSizeChange = (current, size) => {
567
- console.log('[accTable] pagination onShowSizeChange 被调用:', {
568
- current,
569
- size
570
- })
571
488
  if (rule.props?.pagination) {
572
489
  rule.props.pagination.current = 1 // 改变每页条数时重置到第一页
573
490
  rule.props.pagination.pageSize = size
@@ -651,7 +568,6 @@ export default {
651
568
  }
652
569
  },
653
570
  render(children, ctx) {
654
- console.log('[accTable] render 方法被调用')
655
571
  // 使用默认渲染
656
572
  return ctx.$render.defaultRender(ctx, children)
657
573
  }