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

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.82",
3
+ "version": "3.2.84",
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,15 +1,28 @@
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')) {
11
24
  let columns = rule.props?.columns || []
12
- // 如果 columns 是字符串,尝试解析为 JSON
25
+ // Struct 组件返回的是数组对象,直接使用;如果是字符串,尝试解析为 JSON(向后兼容)
13
26
  if (typeof columns === 'string') {
14
27
  try {
15
28
  const parsed = JSON.parse(columns)
@@ -21,13 +34,19 @@ export default {
21
34
  columns = []
22
35
  }
23
36
  }
37
+ // 确保 columns 是数组
38
+ if (!Array.isArray(columns)) {
39
+ columns = []
40
+ }
41
+ // 过滤掉 hidden 为 true 的列
42
+ columns = columns.filter((col) => !col.hidden)
24
43
  props.columns = columns
25
44
  }
26
45
 
27
46
  // 初始化数据源
28
47
  if (!hasProperty(props, 'dataSource')) {
29
48
  let dataSource = rule.value || rule.props?.dataSource || []
30
- // 如果 dataSource 是字符串,尝试解析为 JSON(仅静态数据模式)
49
+ // Struct 组件返回的是数组对象,直接使用;如果是字符串,尝试解析为 JSON(向后兼容)
31
50
  if (typeof dataSource === 'string' && !rule.effect?.fetch) {
32
51
  try {
33
52
  const parsed = JSON.parse(dataSource)
@@ -39,6 +58,10 @@ export default {
39
58
  dataSource = []
40
59
  }
41
60
  }
61
+ // 确保 dataSource 是数组
62
+ if (!Array.isArray(dataSource)) {
63
+ dataSource = []
64
+ }
42
65
  props.dataSource = dataSource
43
66
  }
44
67
 
@@ -60,7 +83,7 @@ export default {
60
83
  if (paginationConfig === false) {
61
84
  props.pagination = false
62
85
  } else if (paginationConfig && typeof paginationConfig === 'object') {
63
- props.pagination = {
86
+ const pagination = {
64
87
  current: paginationConfig.current || 1,
65
88
  pageSize: paginationConfig.pageSize || 10,
66
89
  total: paginationConfig.total || 0,
@@ -69,12 +92,133 @@ export default {
69
92
  showTotal: paginationConfig.showTotal,
70
93
  ...paginationConfig
71
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
+ // 添加分页 onChange 事件处理
109
+ pagination.onChange = (page, size) => {
110
+ // 更新分页配置
111
+ if (rule.props?.pagination) {
112
+ rule.props.pagination.current = page
113
+ rule.props.pagination.pageSize = size
114
+ }
115
+
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
+ }
144
+ }
145
+
146
+ // 添加 onShowSizeChange 事件处理(改变每页条数时)
147
+ pagination.onShowSizeChange = (current, size) => {
148
+ if (rule.props?.pagination) {
149
+ rule.props.pagination.current = 1 // 改变每页条数时重置到第一页
150
+ rule.props.pagination.pageSize = size
151
+ }
152
+
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
+ }
176
+ }
177
+ }
178
+
179
+ props.pagination = pagination
72
180
  } else {
73
181
  // 默认不启用分页
74
182
  props.pagination = false
75
183
  }
76
184
  }
77
185
 
186
+ // 处理远程数据响应,解析总记录数和数据列表
187
+ if (rule.effect?.fetch && rule.props?.pagination) {
188
+ const fetchData = ctx.effectData('fetch')
189
+ if (fetchData && fetchData.value) {
190
+ const responseDataPath =
191
+ rule.props?.paginationResponseDataPath || 'data'
192
+ const responseTotalPath =
193
+ rule.props?.paginationResponseTotalPath || 'total'
194
+
195
+ try {
196
+ // 解析数据列表
197
+ const dataList = getValue(fetchData.value, responseDataPath)
198
+ if (Array.isArray(dataList)) {
199
+ props.dataSource = dataList
200
+ rule.value = dataList
201
+ rule.props.dataSource = dataList
202
+ }
203
+
204
+ // 解析总记录数
205
+ const total = getValue(fetchData.value, responseTotalPath)
206
+ if (
207
+ typeof total === 'number' &&
208
+ rule.props.pagination &&
209
+ typeof rule.props.pagination === 'object'
210
+ ) {
211
+ rule.props.pagination.total = total
212
+ if (props.pagination && typeof props.pagination === 'object') {
213
+ props.pagination.total = total
214
+ }
215
+ }
216
+ } catch (e) {
217
+ console.warn('accTable parse response error:', e)
218
+ }
219
+ }
220
+ }
221
+
78
222
  // 设置其他常用配置
79
223
  if (hasProperty(rule.props, 'bordered')) {
80
224
  props.bordered = rule.props.bordered