@longhongguo/form-create-ant-design-vue 3.3.12 → 3.3.14
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/dist/form-create.esm.js +2 -2
- package/dist/form-create.esm.js.map +1 -1
- package/dist/form-create.js +2 -2
- package/dist/form-create.js.map +1 -1
- package/package.json +1 -1
- package/src/parsers/accTable.js +25 -125
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longhongguo/form-create-ant-design-vue",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.14",
|
|
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",
|
package/src/parsers/accTable.js
CHANGED
|
@@ -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,24 +152,31 @@ export default {
|
|
|
173
152
|
) {
|
|
174
153
|
const cellType = column.cellType
|
|
175
154
|
const dataIndex = column.dataIndex
|
|
176
|
-
const cellOptions = column.cellOptions || []
|
|
177
155
|
const cellProps = column.cellProps || {}
|
|
178
156
|
|
|
179
157
|
// 创建 customRender 函数
|
|
180
158
|
column.customRender = ({ text, record, index }) => {
|
|
181
159
|
const cellValue = record && dataIndex ? record[dataIndex] : text
|
|
160
|
+
// 将 cellOptions 转换为数组格式(支持对象和数组两种格式)
|
|
161
|
+
let options = []
|
|
162
|
+
const cellOptions = column.cellOptions
|
|
163
|
+
if (Array.isArray(cellOptions)) {
|
|
164
|
+
// 如果已经是数组,直接使用
|
|
165
|
+
options = cellOptions
|
|
166
|
+
} else if (cellOptions && typeof cellOptions === 'object') {
|
|
167
|
+
// 如果是对象,转换为数组格式 { 是: 1, 否: 0 } => [{label: '是', value: 1}, {label: '否', value: 0}]
|
|
168
|
+
options = Object.keys(cellOptions).map((label) => ({
|
|
169
|
+
label,
|
|
170
|
+
value: cellOptions[label]
|
|
171
|
+
}))
|
|
172
|
+
}
|
|
182
173
|
|
|
183
174
|
if (cellType === 'input') {
|
|
184
|
-
// 渲染 input 组件
|
|
175
|
+
// 渲染 input 组件
|
|
185
176
|
return h('a-input', {
|
|
186
177
|
value: cellValue,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
e.target?.value !== undefined
|
|
190
|
-
? e.target.value
|
|
191
|
-
: e?.target?.inputValue !== undefined
|
|
192
|
-
? e.target.inputValue
|
|
193
|
-
: e
|
|
178
|
+
'onUpdate:value': (val) => {
|
|
179
|
+
// Ant Design Vue 的 Input 使用 value 和 onUpdate:value
|
|
194
180
|
if (record && dataIndex) {
|
|
195
181
|
record[dataIndex] = val
|
|
196
182
|
// 触发表格数据更新
|
|
@@ -205,12 +191,13 @@ export default {
|
|
|
205
191
|
...cellProps
|
|
206
192
|
})
|
|
207
193
|
} else if (cellType === 'select') {
|
|
208
|
-
// 渲染 select 组件
|
|
194
|
+
// 渲染 select 组件
|
|
209
195
|
return h(
|
|
210
196
|
'a-select',
|
|
211
197
|
{
|
|
212
198
|
value: cellValue,
|
|
213
|
-
|
|
199
|
+
'onUpdate:value': (val) => {
|
|
200
|
+
// Ant Design Vue 的 Select 使用 value 和 onUpdate:value
|
|
214
201
|
if (record && dataIndex) {
|
|
215
202
|
record[dataIndex] = val
|
|
216
203
|
// 触发表格数据更新
|
|
@@ -226,7 +213,7 @@ export default {
|
|
|
226
213
|
},
|
|
227
214
|
{
|
|
228
215
|
default: () =>
|
|
229
|
-
|
|
216
|
+
options.map((opt) => {
|
|
230
217
|
return h('a-select-option', {
|
|
231
218
|
key: opt.value,
|
|
232
219
|
value: opt.value,
|
|
@@ -236,14 +223,13 @@ export default {
|
|
|
236
223
|
}
|
|
237
224
|
)
|
|
238
225
|
} else if (cellType === 'radio') {
|
|
239
|
-
// 渲染 radio 组件
|
|
226
|
+
// 渲染 radio 组件
|
|
240
227
|
return h(
|
|
241
228
|
'a-radio-group',
|
|
242
229
|
{
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
e.target?.value !== undefined ? e.target.value : e
|
|
230
|
+
modelValue: cellValue,
|
|
231
|
+
'onUpdate:modelValue': (val) => {
|
|
232
|
+
// Ant Design Vue 的 RadioGroup 使用 modelValue
|
|
247
233
|
if (record && dataIndex) {
|
|
248
234
|
record[dataIndex] = val
|
|
249
235
|
// 触发表格数据更新
|
|
@@ -258,7 +244,7 @@ export default {
|
|
|
258
244
|
},
|
|
259
245
|
{
|
|
260
246
|
default: () =>
|
|
261
|
-
|
|
247
|
+
options.map((opt) => {
|
|
262
248
|
return h(
|
|
263
249
|
'a-radio',
|
|
264
250
|
{
|
|
@@ -322,20 +308,9 @@ export default {
|
|
|
322
308
|
|
|
323
309
|
// 处理分页配置
|
|
324
310
|
const paginationConfig = rule.props?.pagination
|
|
325
|
-
console.log('[accTable] 开始处理分页配置:', {
|
|
326
|
-
hasPaginationProp: hasProperty(props, 'pagination'),
|
|
327
|
-
paginationConfig,
|
|
328
|
-
paginationConfigType: typeof paginationConfig
|
|
329
|
-
})
|
|
330
311
|
|
|
331
312
|
// 处理分页 props(只有在 props 中没有 pagination 时才初始化)
|
|
332
313
|
if (!hasProperty(props, 'pagination')) {
|
|
333
|
-
console.log('[accTable] 分页配置检查:', {
|
|
334
|
-
paginationConfig,
|
|
335
|
-
isFalse: paginationConfig === false,
|
|
336
|
-
isObject: paginationConfig && typeof paginationConfig === 'object'
|
|
337
|
-
})
|
|
338
|
-
|
|
339
314
|
if (paginationConfig === false) {
|
|
340
315
|
props.pagination = false
|
|
341
316
|
} else if (paginationConfig && typeof paginationConfig === 'object') {
|
|
@@ -357,22 +332,12 @@ export default {
|
|
|
357
332
|
}
|
|
358
333
|
|
|
359
334
|
// 无论 props.pagination 是否已存在,只要满足条件就添加/检查 beforeFetch 钩子
|
|
360
|
-
console.log('[accTable] 检查分页钩子添加条件:', {
|
|
361
|
-
hasFetch: !!rule.effect?.fetch,
|
|
362
|
-
hasPaginationConfig: !!paginationConfig,
|
|
363
|
-
paginationConfigType: typeof paginationConfig,
|
|
364
|
-
paginationConfigValue: paginationConfig,
|
|
365
|
-
paginationCurrent: paginationConfig?.current,
|
|
366
|
-
paginationCurrentDefined: paginationConfig?.current !== undefined
|
|
367
|
-
})
|
|
368
|
-
|
|
369
335
|
if (
|
|
370
336
|
rule.effect?.fetch &&
|
|
371
337
|
paginationConfig &&
|
|
372
338
|
typeof paginationConfig === 'object' &&
|
|
373
339
|
paginationConfig.current !== undefined
|
|
374
340
|
) {
|
|
375
|
-
console.log('[accTable] ✅ 满足条件,进入分页请求参数处理逻辑')
|
|
376
341
|
// 获取分页参数配置
|
|
377
342
|
const pageParamName = rule.props?.paginationPageParam || 'page'
|
|
378
343
|
const pageSizeParamName =
|
|
@@ -385,24 +350,8 @@ export default {
|
|
|
385
350
|
// 获取当前分页对象(从 props 或 paginationConfig)
|
|
386
351
|
const currentPaginationObj = props.pagination || paginationConfig
|
|
387
352
|
|
|
388
|
-
console.log('[accTable] 分页配置初始化:', {
|
|
389
|
-
hasFetch: !!rule.effect?.fetch,
|
|
390
|
-
paginationConfig,
|
|
391
|
-
pageParamName,
|
|
392
|
-
pageSizeParamName,
|
|
393
|
-
paramType,
|
|
394
|
-
currentPage: currentPaginationObj?.current,
|
|
395
|
-
currentPageSize: currentPaginationObj?.pageSize
|
|
396
|
-
})
|
|
397
|
-
|
|
398
353
|
// 包装 fetch 配置,通过 beforeFetch 钩子动态注入分页参数
|
|
399
354
|
const originalFetch = rule.effect.fetch
|
|
400
|
-
console.log('[accTable] 原始 fetch 配置:', {
|
|
401
|
-
type: typeof originalFetch,
|
|
402
|
-
isObject: typeof originalFetch === 'object',
|
|
403
|
-
originalFetch,
|
|
404
|
-
hasBeforeFetch: typeof originalFetch?.beforeFetch === 'function'
|
|
405
|
-
})
|
|
406
355
|
|
|
407
356
|
if (typeof originalFetch === 'object') {
|
|
408
357
|
// 保存原始配置和分页参数配置到闭包中
|
|
@@ -422,36 +371,13 @@ export default {
|
|
|
422
371
|
// 添加 beforeFetch 钩子来注入分页参数
|
|
423
372
|
// 注意:form-create 的 beforeFetch 只接收 (config, {api}) 参数,没有 rule
|
|
424
373
|
originalFetch.beforeFetch = (config, { api }) => {
|
|
425
|
-
console.log('[accTable] beforeFetch 被调用:', {
|
|
426
|
-
configAction: config?.action,
|
|
427
|
-
hasApi: !!api,
|
|
428
|
-
ruleProps: savedRule?.props,
|
|
429
|
-
pagination: savedRule?.props?.pagination
|
|
430
|
-
})
|
|
431
|
-
|
|
432
374
|
// 从闭包中获取当前分页配置
|
|
433
375
|
const currentPagination = savedRule?.props?.pagination
|
|
434
|
-
console.log('[accTable] 当前分页配置:', {
|
|
435
|
-
currentPagination,
|
|
436
|
-
isObject: typeof currentPagination === 'object',
|
|
437
|
-
currentPage: currentPagination?.current,
|
|
438
|
-
currentPageSize: currentPagination?.pageSize
|
|
439
|
-
})
|
|
440
376
|
|
|
441
377
|
if (currentPagination && typeof currentPagination === 'object') {
|
|
442
378
|
const currentPage = currentPagination.current || 1
|
|
443
379
|
const currentPageSize = currentPagination.pageSize || 10
|
|
444
380
|
|
|
445
|
-
console.log('[accTable] 准备添加分页参数:', {
|
|
446
|
-
savedParamType,
|
|
447
|
-
savedPageParamName,
|
|
448
|
-
savedPageSizeParamName,
|
|
449
|
-
currentPage,
|
|
450
|
-
currentPageSize,
|
|
451
|
-
existingQuery: config.query,
|
|
452
|
-
existingData: config.data
|
|
453
|
-
})
|
|
454
|
-
|
|
455
381
|
// 添加分页参数(使用闭包中保存的参数名)
|
|
456
382
|
if (savedParamType === 'query') {
|
|
457
383
|
// 合并已有的 query 参数,确保不覆盖用户自定义的参数
|
|
@@ -460,9 +386,6 @@ export default {
|
|
|
460
386
|
[savedPageParamName]: currentPage,
|
|
461
387
|
[savedPageSizeParamName]: currentPageSize
|
|
462
388
|
}
|
|
463
|
-
console.log('[accTable] 添加 query 参数后:', {
|
|
464
|
-
query: config.query
|
|
465
|
-
})
|
|
466
389
|
} else {
|
|
467
390
|
// 合并已有的 data 参数,确保不覆盖用户自定义的参数
|
|
468
391
|
config.data = {
|
|
@@ -470,9 +393,6 @@ export default {
|
|
|
470
393
|
[savedPageParamName]: currentPage,
|
|
471
394
|
[savedPageSizeParamName]: currentPageSize
|
|
472
395
|
}
|
|
473
|
-
console.log('[accTable] 添加 data 参数后:', {
|
|
474
|
-
data: config.data
|
|
475
|
-
})
|
|
476
396
|
}
|
|
477
397
|
} else {
|
|
478
398
|
console.warn('[accTable] 分页配置无效,无法添加分页参数:', {
|
|
@@ -488,7 +408,6 @@ export default {
|
|
|
488
408
|
savedOriginalBeforeFetch &&
|
|
489
409
|
typeof savedOriginalBeforeFetch === 'function'
|
|
490
410
|
) {
|
|
491
|
-
console.log('[accTable] 调用原始 beforeFetch 钩子')
|
|
492
411
|
try {
|
|
493
412
|
const result = savedOriginalBeforeFetch(config, { api })
|
|
494
413
|
// 如果原始钩子返回了 Promise,处理它
|
|
@@ -508,21 +427,11 @@ export default {
|
|
|
508
427
|
// 即使原始钩子出错,也继续执行,不影响分页参数的添加
|
|
509
428
|
}
|
|
510
429
|
}
|
|
511
|
-
|
|
512
|
-
console.log('[accTable] beforeFetch 完成,最终 config:', {
|
|
513
|
-
query: config.query,
|
|
514
|
-
data: config.data,
|
|
515
|
-
action: config.action
|
|
516
|
-
})
|
|
517
430
|
}
|
|
518
431
|
|
|
519
432
|
// 标记这是我们添加的钩子,避免重复添加
|
|
520
433
|
originalFetch.beforeFetch._accTablePaginationHook = true
|
|
521
|
-
console.log('[accTable] ✅ beforeFetch 钩子已添加并标记')
|
|
522
|
-
} else {
|
|
523
|
-
console.log('[accTable] ⚠️ beforeFetch 钩子已存在,跳过添加')
|
|
524
434
|
}
|
|
525
|
-
console.log('[accTable] beforeFetch 钩子处理完成')
|
|
526
435
|
} else {
|
|
527
436
|
console.warn('[accTable] fetch 配置不是对象类型:', {
|
|
528
437
|
type: typeof originalFetch,
|
|
@@ -537,10 +446,6 @@ export default {
|
|
|
537
446
|
if (!paginationObj._accTableHandlersSet) {
|
|
538
447
|
if (!paginationObj.onChange) {
|
|
539
448
|
paginationObj.onChange = (page, size) => {
|
|
540
|
-
console.log('[accTable] pagination onChange 被调用:', {
|
|
541
|
-
page,
|
|
542
|
-
size
|
|
543
|
-
})
|
|
544
449
|
// 更新分页配置
|
|
545
450
|
if (rule.props?.pagination) {
|
|
546
451
|
rule.props.pagination.current = page
|
|
@@ -556,10 +461,6 @@ export default {
|
|
|
556
461
|
|
|
557
462
|
if (!paginationObj.onShowSizeChange) {
|
|
558
463
|
paginationObj.onShowSizeChange = (current, size) => {
|
|
559
|
-
console.log('[accTable] pagination onShowSizeChange 被调用:', {
|
|
560
|
-
current,
|
|
561
|
-
size
|
|
562
|
-
})
|
|
563
464
|
if (rule.props?.pagination) {
|
|
564
465
|
rule.props.pagination.current = 1 // 改变每页条数时重置到第一页
|
|
565
466
|
rule.props.pagination.pageSize = size
|
|
@@ -643,7 +544,6 @@ export default {
|
|
|
643
544
|
}
|
|
644
545
|
},
|
|
645
546
|
render(children, ctx) {
|
|
646
|
-
console.log('[accTable] render 方法被调用')
|
|
647
547
|
// 使用默认渲染
|
|
648
548
|
return ctx.$render.defaultRender(ctx, children)
|
|
649
549
|
}
|