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

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.85",
3
+ "version": "3.2.86",
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",
@@ -1,4 +1,5 @@
1
1
  import { hasProperty } from '@form-create/utils/lib/type'
2
+ import { deepCopy } from '@form-create/utils/lib/deepextend'
2
3
 
3
4
  // 简单的 getValue 函数,根据路径字符串获取嵌套对象的值
4
5
  function getValue(obj, path) {
@@ -105,66 +106,52 @@ export default {
105
106
  const responseTotalPath =
106
107
  rule.props?.paginationResponseTotalPath || 'total'
107
108
 
108
- // 包装 fetch 配置,添加 beforeFetch 钩子来动态注入分页参数
109
+ // 包装 fetch 配置,将其包装成函数以动态注入分页参数
109
110
  const originalFetch = rule.effect.fetch
110
111
  if (typeof originalFetch === 'object') {
111
- // 保存原始 beforeFetch 钩子和分页参数配置到闭包中
112
- const originalBeforeFetch = originalFetch.beforeFetch
112
+ // 保存原始配置和分页参数配置到闭包中
113
+ const savedOriginalFetch = { ...originalFetch }
113
114
  const savedParamType = paramType
114
115
  const savedPageParamName = pageParamName
115
116
  const savedPageSizeParamName = pageSizeParamName
116
117
 
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 = {}
118
+ // 将整个 fetch 配置包装成函数,使其每次调用时都能获取最新的分页参数
119
+ rule.effect.fetch = (r, a) => {
120
+ // 先调用原始的 action(如果是函数)获取基础配置
121
+ let baseOption = savedOriginalFetch
122
+ if (typeof savedOriginalFetch.action === 'function') {
123
+ const actionResult = savedOriginalFetch.action(r, a)
124
+ if (actionResult && typeof actionResult === 'object') {
125
+ baseOption = { ...savedOriginalFetch, ...actionResult }
126
+ }
130
127
  }
131
- originalFetch.data[savedPageParamName] = currentPage
132
- originalFetch.data[savedPageSizeParamName] = currentPageSize
133
- }
134
128
 
135
- // 添加 beforeFetch 钩子来动态更新分页参数(确保每次请求都使用最新值)
136
- originalFetch.beforeFetch = (config, { rule: r, api: a }) => {
129
+ // 使用扩展运算符创建新配置,保留所有原始属性(包括函数)
130
+ const fetchOption = { ...baseOption }
131
+
137
132
  // 获取当前分页配置
138
133
  const currentPagination = r.props?.pagination
139
134
  if (currentPagination && typeof currentPagination === 'object') {
140
135
  const currentPage = currentPagination.current || 1
141
136
  const currentPageSize = currentPagination.pageSize || 10
142
137
 
143
- // 确保 config 存在 query 和 data
144
- if (!config.query) {
145
- config.query = {}
146
- }
147
- if (!config.data) {
148
- config.data = {}
149
- }
150
-
151
- // 添加分页参数(使用闭包中保存的参数名)
138
+ // 确保 fetchOption 存在 query 和 data,并合并已有值
152
139
  if (savedParamType === 'query') {
153
- config.query[savedPageParamName] = currentPage
154
- config.query[savedPageSizeParamName] = currentPageSize
140
+ fetchOption.query = {
141
+ ...(baseOption.query || {}),
142
+ [savedPageParamName]: currentPage,
143
+ [savedPageSizeParamName]: currentPageSize
144
+ }
155
145
  } else {
156
- config.data[savedPageParamName] = currentPage
157
- config.data[savedPageSizeParamName] = currentPageSize
146
+ fetchOption.data = {
147
+ ...(baseOption.data || {}),
148
+ [savedPageParamName]: currentPage,
149
+ [savedPageSizeParamName]: currentPageSize
150
+ }
158
151
  }
159
152
  }
160
153
 
161
- // 调用原始的 beforeFetch 钩子(如果存在)
162
- if (
163
- originalBeforeFetch &&
164
- typeof originalBeforeFetch === 'function'
165
- ) {
166
- return originalBeforeFetch(config, { rule: r, api: a })
167
- }
154
+ return fetchOption
168
155
  }
169
156
  }
170
157