@longhongguo/form-create-ant-design-vue 3.2.84 → 3.2.85

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.84",
3
+ "version": "3.2.85",
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",
@@ -93,7 +93,7 @@ export default {
93
93
  ...paginationConfig
94
94
  }
95
95
 
96
- // 如果启用了分页且有远程数据源(fetch effect),添加 onChange 事件处理
96
+ // 如果启用了分页且有远程数据源(fetch effect),添加 onChange 事件处理和初始化分页参数
97
97
  if (rule.effect?.fetch && paginationConfig.current !== undefined) {
98
98
  // 获取分页参数配置
99
99
  const pageParamName = rule.props?.paginationPageParam || 'page'
@@ -105,6 +105,69 @@ export default {
105
105
  const responseTotalPath =
106
106
  rule.props?.paginationResponseTotalPath || 'total'
107
107
 
108
+ // 包装 fetch 配置,添加 beforeFetch 钩子来动态注入分页参数
109
+ const originalFetch = rule.effect.fetch
110
+ if (typeof originalFetch === 'object') {
111
+ // 保存原始 beforeFetch 钩子和分页参数配置到闭包中
112
+ const originalBeforeFetch = originalFetch.beforeFetch
113
+ const savedParamType = paramType
114
+ const savedPageParamName = pageParamName
115
+ const savedPageSizeParamName = pageSizeParamName
116
+
117
+ // 先将初始分页参数添加到配置中(用于首次加载)
118
+ const currentPage = pagination.current || 1
119
+ const currentPageSize = pagination.pageSize || 10
120
+
121
+ if (savedParamType === 'query') {
122
+ if (!originalFetch.query) {
123
+ originalFetch.query = {}
124
+ }
125
+ originalFetch.query[savedPageParamName] = currentPage
126
+ originalFetch.query[savedPageSizeParamName] = currentPageSize
127
+ } else {
128
+ if (!originalFetch.data) {
129
+ originalFetch.data = {}
130
+ }
131
+ originalFetch.data[savedPageParamName] = currentPage
132
+ originalFetch.data[savedPageSizeParamName] = currentPageSize
133
+ }
134
+
135
+ // 添加 beforeFetch 钩子来动态更新分页参数(确保每次请求都使用最新值)
136
+ originalFetch.beforeFetch = (config, { rule: r, api: a }) => {
137
+ // 获取当前分页配置
138
+ const currentPagination = r.props?.pagination
139
+ if (currentPagination && typeof currentPagination === 'object') {
140
+ const currentPage = currentPagination.current || 1
141
+ const currentPageSize = currentPagination.pageSize || 10
142
+
143
+ // 确保 config 存在 query 和 data
144
+ if (!config.query) {
145
+ config.query = {}
146
+ }
147
+ if (!config.data) {
148
+ config.data = {}
149
+ }
150
+
151
+ // 添加分页参数(使用闭包中保存的参数名)
152
+ if (savedParamType === 'query') {
153
+ config.query[savedPageParamName] = currentPage
154
+ config.query[savedPageSizeParamName] = currentPageSize
155
+ } else {
156
+ config.data[savedPageParamName] = currentPage
157
+ config.data[savedPageSizeParamName] = currentPageSize
158
+ }
159
+ }
160
+
161
+ // 调用原始的 beforeFetch 钩子(如果存在)
162
+ if (
163
+ originalBeforeFetch &&
164
+ typeof originalBeforeFetch === 'function'
165
+ ) {
166
+ return originalBeforeFetch(config, { rule: r, api: a })
167
+ }
168
+ }
169
+ }
170
+
108
171
  // 添加分页 onChange 事件处理
109
172
  pagination.onChange = (page, size) => {
110
173
  // 更新分页配置
@@ -113,34 +176,11 @@ export default {
113
176
  rule.props.pagination.pageSize = size
114
177
  }
115
178
 
116
- // 更新 fetch 参数
117
- if (rule.effect?.fetch) {
118
- const fetchConfig = rule.effect.fetch
119
- if (typeof fetchConfig === 'object') {
120
- if (paramType === 'query') {
121
- // 通过 query 参数传递
122
- if (!fetchConfig.query) {
123
- fetchConfig.query = {}
124
- }
125
- fetchConfig.query[pageParamName] = page
126
- fetchConfig.query[pageSizeParamName] = size
127
- } else {
128
- // 通过 data 参数传递
129
- if (!fetchConfig.data) {
130
- fetchConfig.data = {}
131
- }
132
- fetchConfig.data[pageParamName] = page
133
- fetchConfig.data[pageSizeParamName] = size
134
- }
135
-
136
- // 触发 fetch 重新加载:通过触发 effect 来重新运行 fetch
137
- ctx.api.sync(rule)
138
- // 延迟触发 refresh 以确保配置已更新
139
- setTimeout(() => {
140
- ctx.api.refresh()
141
- }, 0)
142
- }
143
- }
179
+ // 分页参数已经通过包装的 fetch 函数自动添加,只需要触发重新加载
180
+ ctx.api.sync(rule)
181
+ setTimeout(() => {
182
+ ctx.api.refresh()
183
+ }, 0)
144
184
  }
145
185
 
146
186
  // 添加 onShowSizeChange 事件处理(改变每页条数时)
@@ -150,29 +190,11 @@ export default {
150
190
  rule.props.pagination.pageSize = size
151
191
  }
152
192
 
153
- if (rule.effect?.fetch) {
154
- const fetchConfig = rule.effect.fetch
155
- if (typeof fetchConfig === 'object') {
156
- if (paramType === 'query') {
157
- if (!fetchConfig.query) {
158
- fetchConfig.query = {}
159
- }
160
- fetchConfig.query[pageParamName] = 1
161
- fetchConfig.query[pageSizeParamName] = size
162
- } else {
163
- if (!fetchConfig.data) {
164
- fetchConfig.data = {}
165
- }
166
- fetchConfig.data[pageParamName] = 1
167
- fetchConfig.data[pageSizeParamName] = size
168
- }
169
-
170
- ctx.api.sync(rule)
171
- setTimeout(() => {
172
- ctx.api.refresh()
173
- }, 0)
174
- }
175
- }
193
+ // 分页参数已经通过包装的 fetch 函数自动添加,只需要触发重新加载
194
+ ctx.api.sync(rule)
195
+ setTimeout(() => {
196
+ ctx.api.refresh()
197
+ }, 0)
176
198
  }
177
199
  }
178
200