@longhongguo/form-create-ant-design-vue 3.2.93 → 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/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.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",
@@ -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