@longhongguo/form-create-ant-design-vue 3.3.13 → 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 +23 -131
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,32 +152,31 @@ 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
157
|
// 创建 customRender 函数
|
|
184
158
|
column.customRender = ({ text, record, index }) => {
|
|
185
159
|
const cellValue = record && dataIndex ? record[dataIndex] : text
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
+
}
|
|
190
173
|
|
|
191
174
|
if (cellType === 'input') {
|
|
192
|
-
// 渲染 input 组件
|
|
175
|
+
// 渲染 input 组件
|
|
193
176
|
return h('a-input', {
|
|
194
177
|
value: cellValue,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
e.target?.value !== undefined
|
|
198
|
-
? e.target.value
|
|
199
|
-
: e?.target?.inputValue !== undefined
|
|
200
|
-
? e.target.inputValue
|
|
201
|
-
: e
|
|
178
|
+
'onUpdate:value': (val) => {
|
|
179
|
+
// Ant Design Vue 的 Input 使用 value 和 onUpdate:value
|
|
202
180
|
if (record && dataIndex) {
|
|
203
181
|
record[dataIndex] = val
|
|
204
182
|
// 触发表格数据更新
|
|
@@ -213,12 +191,13 @@ export default {
|
|
|
213
191
|
...cellProps
|
|
214
192
|
})
|
|
215
193
|
} else if (cellType === 'select') {
|
|
216
|
-
// 渲染 select 组件
|
|
194
|
+
// 渲染 select 组件
|
|
217
195
|
return h(
|
|
218
196
|
'a-select',
|
|
219
197
|
{
|
|
220
198
|
value: cellValue,
|
|
221
|
-
|
|
199
|
+
'onUpdate:value': (val) => {
|
|
200
|
+
// Ant Design Vue 的 Select 使用 value 和 onUpdate:value
|
|
222
201
|
if (record && dataIndex) {
|
|
223
202
|
record[dataIndex] = val
|
|
224
203
|
// 触发表格数据更新
|
|
@@ -244,14 +223,13 @@ export default {
|
|
|
244
223
|
}
|
|
245
224
|
)
|
|
246
225
|
} else if (cellType === 'radio') {
|
|
247
|
-
// 渲染 radio 组件
|
|
226
|
+
// 渲染 radio 组件
|
|
248
227
|
return h(
|
|
249
228
|
'a-radio-group',
|
|
250
229
|
{
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
e.target?.value !== undefined ? e.target.value : e
|
|
230
|
+
modelValue: cellValue,
|
|
231
|
+
'onUpdate:modelValue': (val) => {
|
|
232
|
+
// Ant Design Vue 的 RadioGroup 使用 modelValue
|
|
255
233
|
if (record && dataIndex) {
|
|
256
234
|
record[dataIndex] = val
|
|
257
235
|
// 触发表格数据更新
|
|
@@ -330,20 +308,9 @@ export default {
|
|
|
330
308
|
|
|
331
309
|
// 处理分页配置
|
|
332
310
|
const paginationConfig = rule.props?.pagination
|
|
333
|
-
console.log('[accTable] 开始处理分页配置:', {
|
|
334
|
-
hasPaginationProp: hasProperty(props, 'pagination'),
|
|
335
|
-
paginationConfig,
|
|
336
|
-
paginationConfigType: typeof paginationConfig
|
|
337
|
-
})
|
|
338
311
|
|
|
339
312
|
// 处理分页 props(只有在 props 中没有 pagination 时才初始化)
|
|
340
313
|
if (!hasProperty(props, 'pagination')) {
|
|
341
|
-
console.log('[accTable] 分页配置检查:', {
|
|
342
|
-
paginationConfig,
|
|
343
|
-
isFalse: paginationConfig === false,
|
|
344
|
-
isObject: paginationConfig && typeof paginationConfig === 'object'
|
|
345
|
-
})
|
|
346
|
-
|
|
347
314
|
if (paginationConfig === false) {
|
|
348
315
|
props.pagination = false
|
|
349
316
|
} else if (paginationConfig && typeof paginationConfig === 'object') {
|
|
@@ -365,22 +332,12 @@ export default {
|
|
|
365
332
|
}
|
|
366
333
|
|
|
367
334
|
// 无论 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
335
|
if (
|
|
378
336
|
rule.effect?.fetch &&
|
|
379
337
|
paginationConfig &&
|
|
380
338
|
typeof paginationConfig === 'object' &&
|
|
381
339
|
paginationConfig.current !== undefined
|
|
382
340
|
) {
|
|
383
|
-
console.log('[accTable] ✅ 满足条件,进入分页请求参数处理逻辑')
|
|
384
341
|
// 获取分页参数配置
|
|
385
342
|
const pageParamName = rule.props?.paginationPageParam || 'page'
|
|
386
343
|
const pageSizeParamName =
|
|
@@ -393,24 +350,8 @@ export default {
|
|
|
393
350
|
// 获取当前分页对象(从 props 或 paginationConfig)
|
|
394
351
|
const currentPaginationObj = props.pagination || paginationConfig
|
|
395
352
|
|
|
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
353
|
// 包装 fetch 配置,通过 beforeFetch 钩子动态注入分页参数
|
|
407
354
|
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
355
|
|
|
415
356
|
if (typeof originalFetch === 'object') {
|
|
416
357
|
// 保存原始配置和分页参数配置到闭包中
|
|
@@ -430,36 +371,13 @@ export default {
|
|
|
430
371
|
// 添加 beforeFetch 钩子来注入分页参数
|
|
431
372
|
// 注意:form-create 的 beforeFetch 只接收 (config, {api}) 参数,没有 rule
|
|
432
373
|
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
374
|
// 从闭包中获取当前分页配置
|
|
441
375
|
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
376
|
|
|
449
377
|
if (currentPagination && typeof currentPagination === 'object') {
|
|
450
378
|
const currentPage = currentPagination.current || 1
|
|
451
379
|
const currentPageSize = currentPagination.pageSize || 10
|
|
452
380
|
|
|
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
381
|
// 添加分页参数(使用闭包中保存的参数名)
|
|
464
382
|
if (savedParamType === 'query') {
|
|
465
383
|
// 合并已有的 query 参数,确保不覆盖用户自定义的参数
|
|
@@ -468,9 +386,6 @@ export default {
|
|
|
468
386
|
[savedPageParamName]: currentPage,
|
|
469
387
|
[savedPageSizeParamName]: currentPageSize
|
|
470
388
|
}
|
|
471
|
-
console.log('[accTable] 添加 query 参数后:', {
|
|
472
|
-
query: config.query
|
|
473
|
-
})
|
|
474
389
|
} else {
|
|
475
390
|
// 合并已有的 data 参数,确保不覆盖用户自定义的参数
|
|
476
391
|
config.data = {
|
|
@@ -478,9 +393,6 @@ export default {
|
|
|
478
393
|
[savedPageParamName]: currentPage,
|
|
479
394
|
[savedPageSizeParamName]: currentPageSize
|
|
480
395
|
}
|
|
481
|
-
console.log('[accTable] 添加 data 参数后:', {
|
|
482
|
-
data: config.data
|
|
483
|
-
})
|
|
484
396
|
}
|
|
485
397
|
} else {
|
|
486
398
|
console.warn('[accTable] 分页配置无效,无法添加分页参数:', {
|
|
@@ -496,7 +408,6 @@ export default {
|
|
|
496
408
|
savedOriginalBeforeFetch &&
|
|
497
409
|
typeof savedOriginalBeforeFetch === 'function'
|
|
498
410
|
) {
|
|
499
|
-
console.log('[accTable] 调用原始 beforeFetch 钩子')
|
|
500
411
|
try {
|
|
501
412
|
const result = savedOriginalBeforeFetch(config, { api })
|
|
502
413
|
// 如果原始钩子返回了 Promise,处理它
|
|
@@ -516,21 +427,11 @@ export default {
|
|
|
516
427
|
// 即使原始钩子出错,也继续执行,不影响分页参数的添加
|
|
517
428
|
}
|
|
518
429
|
}
|
|
519
|
-
|
|
520
|
-
console.log('[accTable] beforeFetch 完成,最终 config:', {
|
|
521
|
-
query: config.query,
|
|
522
|
-
data: config.data,
|
|
523
|
-
action: config.action
|
|
524
|
-
})
|
|
525
430
|
}
|
|
526
431
|
|
|
527
432
|
// 标记这是我们添加的钩子,避免重复添加
|
|
528
433
|
originalFetch.beforeFetch._accTablePaginationHook = true
|
|
529
|
-
console.log('[accTable] ✅ beforeFetch 钩子已添加并标记')
|
|
530
|
-
} else {
|
|
531
|
-
console.log('[accTable] ⚠️ beforeFetch 钩子已存在,跳过添加')
|
|
532
434
|
}
|
|
533
|
-
console.log('[accTable] beforeFetch 钩子处理完成')
|
|
534
435
|
} else {
|
|
535
436
|
console.warn('[accTable] fetch 配置不是对象类型:', {
|
|
536
437
|
type: typeof originalFetch,
|
|
@@ -545,10 +446,6 @@ export default {
|
|
|
545
446
|
if (!paginationObj._accTableHandlersSet) {
|
|
546
447
|
if (!paginationObj.onChange) {
|
|
547
448
|
paginationObj.onChange = (page, size) => {
|
|
548
|
-
console.log('[accTable] pagination onChange 被调用:', {
|
|
549
|
-
page,
|
|
550
|
-
size
|
|
551
|
-
})
|
|
552
449
|
// 更新分页配置
|
|
553
450
|
if (rule.props?.pagination) {
|
|
554
451
|
rule.props.pagination.current = page
|
|
@@ -564,10 +461,6 @@ export default {
|
|
|
564
461
|
|
|
565
462
|
if (!paginationObj.onShowSizeChange) {
|
|
566
463
|
paginationObj.onShowSizeChange = (current, size) => {
|
|
567
|
-
console.log('[accTable] pagination onShowSizeChange 被调用:', {
|
|
568
|
-
current,
|
|
569
|
-
size
|
|
570
|
-
})
|
|
571
464
|
if (rule.props?.pagination) {
|
|
572
465
|
rule.props.pagination.current = 1 // 改变每页条数时重置到第一页
|
|
573
466
|
rule.props.pagination.pageSize = size
|
|
@@ -651,7 +544,6 @@ export default {
|
|
|
651
544
|
}
|
|
652
545
|
},
|
|
653
546
|
render(children, ctx) {
|
|
654
|
-
console.log('[accTable] render 方法被调用')
|
|
655
547
|
// 使用默认渲染
|
|
656
548
|
return ctx.$render.defaultRender(ctx, children)
|
|
657
549
|
}
|