@longhongguo/form-create-ant-design-vue 3.2.92 → 3.2.94
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 +140 -50
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longhongguo/form-create-ant-design-vue",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.94",
|
|
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
|
@@ -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)
|
|
@@ -133,34 +211,22 @@ export default {
|
|
|
133
211
|
}
|
|
134
212
|
|
|
135
213
|
// 无论 props.pagination 是否已存在,只要满足条件就添加/检查 beforeFetch 钩子
|
|
136
|
-
// 使用标记防止重复初始化,避免重复请求
|
|
137
|
-
const paginationInitialized = rule._accTablePaginationInitialized === true
|
|
138
|
-
|
|
139
214
|
console.log('[accTable] 检查分页钩子添加条件:', {
|
|
140
215
|
hasFetch: !!rule.effect?.fetch,
|
|
141
216
|
hasPaginationConfig: !!paginationConfig,
|
|
142
217
|
paginationConfigType: typeof paginationConfig,
|
|
143
218
|
paginationConfigValue: paginationConfig,
|
|
144
219
|
paginationCurrent: paginationConfig?.current,
|
|
145
|
-
paginationCurrentDefined: paginationConfig?.current !== undefined
|
|
146
|
-
paginationInitialized
|
|
220
|
+
paginationCurrentDefined: paginationConfig?.current !== undefined
|
|
147
221
|
})
|
|
148
222
|
|
|
149
223
|
if (
|
|
150
|
-
!paginationInitialized && // 只初始化一次
|
|
151
224
|
rule.effect?.fetch &&
|
|
152
225
|
paginationConfig &&
|
|
153
226
|
typeof paginationConfig === 'object' &&
|
|
154
227
|
paginationConfig.current !== undefined
|
|
155
228
|
) {
|
|
156
|
-
console.log(
|
|
157
|
-
'[accTable] ✅ 满足条件,进入分页请求参数处理逻辑(首次初始化)'
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
// 标记已初始化,防止重复执行
|
|
161
|
-
rule._accTablePaginationInitialized = true
|
|
162
|
-
|
|
163
|
-
console.log('[accTable] 进入分页请求参数处理逻辑')
|
|
229
|
+
console.log('[accTable] ✅ 满足条件,进入分页请求参数处理逻辑')
|
|
164
230
|
// 获取分页参数配置
|
|
165
231
|
const pageParamName = rule.props?.paginationPageParam || 'page'
|
|
166
232
|
const pageSizeParamName =
|
|
@@ -271,12 +337,30 @@ export default {
|
|
|
271
337
|
|
|
272
338
|
// 调用原始的 beforeFetch 钩子(如果存在)
|
|
273
339
|
// 原始钩子可能也只接收 (config, {api}) 参数
|
|
340
|
+
// 使用 try-catch 包装,避免原始钩子中的错误影响我们的逻辑
|
|
274
341
|
if (
|
|
275
342
|
savedOriginalBeforeFetch &&
|
|
276
343
|
typeof savedOriginalBeforeFetch === 'function'
|
|
277
344
|
) {
|
|
278
345
|
console.log('[accTable] 调用原始 beforeFetch 钩子')
|
|
279
|
-
|
|
346
|
+
try {
|
|
347
|
+
const result = savedOriginalBeforeFetch(config, { api })
|
|
348
|
+
// 如果原始钩子返回了 Promise,处理它
|
|
349
|
+
if (result && typeof result.then === 'function') {
|
|
350
|
+
return result.catch((err) => {
|
|
351
|
+
console.error(
|
|
352
|
+
'[accTable] 原始 beforeFetch 钩子执行出错:',
|
|
353
|
+
err
|
|
354
|
+
)
|
|
355
|
+
// 即使原始钩子出错,也继续执行
|
|
356
|
+
return Promise.resolve()
|
|
357
|
+
})
|
|
358
|
+
}
|
|
359
|
+
return result
|
|
360
|
+
} catch (err) {
|
|
361
|
+
console.error('[accTable] 原始 beforeFetch 钩子执行出错:', err)
|
|
362
|
+
// 即使原始钩子出错,也继续执行,不影响分页参数的添加
|
|
363
|
+
}
|
|
280
364
|
}
|
|
281
365
|
|
|
282
366
|
console.log('[accTable] beforeFetch 完成,最终 config:', {
|
|
@@ -300,49 +384,55 @@ export default {
|
|
|
300
384
|
})
|
|
301
385
|
}
|
|
302
386
|
|
|
303
|
-
// 添加分页 onChange 和 onShowSizeChange
|
|
387
|
+
// 添加分页 onChange 和 onShowSizeChange 事件处理(确保事件处理函数存在,且只设置一次)
|
|
304
388
|
const paginationObj = props.pagination || paginationConfig
|
|
305
389
|
if (paginationObj && typeof paginationObj === 'object') {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
rule.props
|
|
390
|
+
// 检查是否已经设置过事件处理函数(通过标记判断)
|
|
391
|
+
if (!paginationObj._accTableHandlersSet) {
|
|
392
|
+
if (!paginationObj.onChange) {
|
|
393
|
+
paginationObj.onChange = (page, size) => {
|
|
394
|
+
console.log('[accTable] pagination onChange 被调用:', {
|
|
395
|
+
page,
|
|
396
|
+
size
|
|
397
|
+
})
|
|
398
|
+
// 更新分页配置
|
|
399
|
+
if (rule.props?.pagination) {
|
|
400
|
+
rule.props.pagination.current = page
|
|
401
|
+
rule.props.pagination.pageSize = size
|
|
402
|
+
}
|
|
403
|
+
// 分页参数已经通过 beforeFetch 钩子自动添加,只需要触发重新加载
|
|
404
|
+
ctx.api.sync(rule)
|
|
405
|
+
setTimeout(() => {
|
|
406
|
+
ctx.api.refresh()
|
|
407
|
+
}, 0)
|
|
316
408
|
}
|
|
317
|
-
// 分页参数已经通过 beforeFetch 钩子自动添加,只需要触发重新加载
|
|
318
|
-
ctx.api.sync(rule)
|
|
319
|
-
setTimeout(() => {
|
|
320
|
-
ctx.api.refresh()
|
|
321
|
-
}, 0)
|
|
322
409
|
}
|
|
323
|
-
}
|
|
324
410
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
411
|
+
if (!paginationObj.onShowSizeChange) {
|
|
412
|
+
paginationObj.onShowSizeChange = (current, size) => {
|
|
413
|
+
console.log('[accTable] pagination onShowSizeChange 被调用:', {
|
|
414
|
+
current,
|
|
415
|
+
size
|
|
416
|
+
})
|
|
417
|
+
if (rule.props?.pagination) {
|
|
418
|
+
rule.props.pagination.current = 1 // 改变每页条数时重置到第一页
|
|
419
|
+
rule.props.pagination.pageSize = size
|
|
420
|
+
}
|
|
421
|
+
// 分页参数已经通过 beforeFetch 钩子自动添加,只需要触发重新加载
|
|
422
|
+
ctx.api.sync(rule)
|
|
423
|
+
setTimeout(() => {
|
|
424
|
+
ctx.api.refresh()
|
|
425
|
+
}, 0)
|
|
334
426
|
}
|
|
335
|
-
// 分页参数已经通过 beforeFetch 钩子自动添加,只需要触发重新加载
|
|
336
|
-
ctx.api.sync(rule)
|
|
337
|
-
setTimeout(() => {
|
|
338
|
-
ctx.api.refresh()
|
|
339
|
-
}, 0)
|
|
340
427
|
}
|
|
341
|
-
}
|
|
342
428
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
429
|
+
// 标记事件处理函数已设置,避免重复设置
|
|
430
|
+
paginationObj._accTableHandlersSet = true
|
|
431
|
+
|
|
432
|
+
// 如果 props.pagination 不存在,将 paginationObj 赋值给 props.pagination
|
|
433
|
+
if (!props.pagination) {
|
|
434
|
+
props.pagination = paginationObj
|
|
435
|
+
}
|
|
346
436
|
}
|
|
347
437
|
}
|
|
348
438
|
}
|