@longhongguo/form-create-ant-design-vue 3.2.83 → 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.
|
|
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",
|
package/src/parsers/accTable.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { hasProperty } from '@form-create/utils/lib/type'
|
|
2
2
|
|
|
3
|
+
// 简单的 getValue 函数,根据路径字符串获取嵌套对象的值
|
|
4
|
+
function getValue(obj, path) {
|
|
5
|
+
if (!obj || !path) return undefined
|
|
6
|
+
const keys = path.split('.')
|
|
7
|
+
let value = obj
|
|
8
|
+
for (const key of keys) {
|
|
9
|
+
if (value == null) return undefined
|
|
10
|
+
value = value[key]
|
|
11
|
+
}
|
|
12
|
+
return value
|
|
13
|
+
}
|
|
14
|
+
|
|
3
15
|
export default {
|
|
4
16
|
name: 'accTable',
|
|
5
17
|
mergeProp(ctx) {
|
|
6
18
|
const props = ctx.prop.props || {}
|
|
7
19
|
const rule = ctx.rule
|
|
20
|
+
const api = ctx.api
|
|
8
21
|
|
|
9
22
|
// 初始化列配置
|
|
10
23
|
if (!hasProperty(props, 'columns')) {
|
|
@@ -70,7 +83,7 @@ export default {
|
|
|
70
83
|
if (paginationConfig === false) {
|
|
71
84
|
props.pagination = false
|
|
72
85
|
} else if (paginationConfig && typeof paginationConfig === 'object') {
|
|
73
|
-
|
|
86
|
+
const pagination = {
|
|
74
87
|
current: paginationConfig.current || 1,
|
|
75
88
|
pageSize: paginationConfig.pageSize || 10,
|
|
76
89
|
total: paginationConfig.total || 0,
|
|
@@ -79,12 +92,155 @@ export default {
|
|
|
79
92
|
showTotal: paginationConfig.showTotal,
|
|
80
93
|
...paginationConfig
|
|
81
94
|
}
|
|
95
|
+
|
|
96
|
+
// 如果启用了分页且有远程数据源(fetch effect),添加 onChange 事件处理和初始化分页参数
|
|
97
|
+
if (rule.effect?.fetch && paginationConfig.current !== undefined) {
|
|
98
|
+
// 获取分页参数配置
|
|
99
|
+
const pageParamName = rule.props?.paginationPageParam || 'page'
|
|
100
|
+
const pageSizeParamName =
|
|
101
|
+
rule.props?.paginationPageSizeParam || 'pageSize'
|
|
102
|
+
const paramType = rule.props?.paginationParamType || 'query' // 'query' 或 'data'
|
|
103
|
+
const responseDataPath =
|
|
104
|
+
rule.props?.paginationResponseDataPath || 'data'
|
|
105
|
+
const responseTotalPath =
|
|
106
|
+
rule.props?.paginationResponseTotalPath || 'total'
|
|
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
|
+
|
|
171
|
+
// 添加分页 onChange 事件处理
|
|
172
|
+
pagination.onChange = (page, size) => {
|
|
173
|
+
// 更新分页配置
|
|
174
|
+
if (rule.props?.pagination) {
|
|
175
|
+
rule.props.pagination.current = page
|
|
176
|
+
rule.props.pagination.pageSize = size
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 分页参数已经通过包装的 fetch 函数自动添加,只需要触发重新加载
|
|
180
|
+
ctx.api.sync(rule)
|
|
181
|
+
setTimeout(() => {
|
|
182
|
+
ctx.api.refresh()
|
|
183
|
+
}, 0)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 添加 onShowSizeChange 事件处理(改变每页条数时)
|
|
187
|
+
pagination.onShowSizeChange = (current, size) => {
|
|
188
|
+
if (rule.props?.pagination) {
|
|
189
|
+
rule.props.pagination.current = 1 // 改变每页条数时重置到第一页
|
|
190
|
+
rule.props.pagination.pageSize = size
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 分页参数已经通过包装的 fetch 函数自动添加,只需要触发重新加载
|
|
194
|
+
ctx.api.sync(rule)
|
|
195
|
+
setTimeout(() => {
|
|
196
|
+
ctx.api.refresh()
|
|
197
|
+
}, 0)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
props.pagination = pagination
|
|
82
202
|
} else {
|
|
83
203
|
// 默认不启用分页
|
|
84
204
|
props.pagination = false
|
|
85
205
|
}
|
|
86
206
|
}
|
|
87
207
|
|
|
208
|
+
// 处理远程数据响应,解析总记录数和数据列表
|
|
209
|
+
if (rule.effect?.fetch && rule.props?.pagination) {
|
|
210
|
+
const fetchData = ctx.effectData('fetch')
|
|
211
|
+
if (fetchData && fetchData.value) {
|
|
212
|
+
const responseDataPath =
|
|
213
|
+
rule.props?.paginationResponseDataPath || 'data'
|
|
214
|
+
const responseTotalPath =
|
|
215
|
+
rule.props?.paginationResponseTotalPath || 'total'
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
// 解析数据列表
|
|
219
|
+
const dataList = getValue(fetchData.value, responseDataPath)
|
|
220
|
+
if (Array.isArray(dataList)) {
|
|
221
|
+
props.dataSource = dataList
|
|
222
|
+
rule.value = dataList
|
|
223
|
+
rule.props.dataSource = dataList
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 解析总记录数
|
|
227
|
+
const total = getValue(fetchData.value, responseTotalPath)
|
|
228
|
+
if (
|
|
229
|
+
typeof total === 'number' &&
|
|
230
|
+
rule.props.pagination &&
|
|
231
|
+
typeof rule.props.pagination === 'object'
|
|
232
|
+
) {
|
|
233
|
+
rule.props.pagination.total = total
|
|
234
|
+
if (props.pagination && typeof props.pagination === 'object') {
|
|
235
|
+
props.pagination.total = total
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
} catch (e) {
|
|
239
|
+
console.warn('accTable parse response error:', e)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
88
244
|
// 设置其他常用配置
|
|
89
245
|
if (hasProperty(rule.props, 'bordered')) {
|
|
90
246
|
props.bordered = rule.props.bordered
|