@longhongguo/form-create-ant-design-vue 3.3.14 → 3.3.15
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/dist/form-create.esm.js +2 -2
- package/dist/form-create.esm.js.map +1 -1
- package/dist/form-create.js +2 -2
- package/dist/form-create.js.map +1 -1
- package/package.json +1 -1
- package/src/parsers/accTable.js +115 -91
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longhongguo/form-create-ant-design-vue",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.15",
|
|
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
|
@@ -154,55 +154,37 @@ export default {
|
|
|
154
154
|
const dataIndex = column.dataIndex
|
|
155
155
|
const cellProps = column.cellProps || {}
|
|
156
156
|
|
|
157
|
-
// 创建 customRender
|
|
158
|
-
column.customRender = (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
value:
|
|
171
|
-
|
|
172
|
-
|
|
157
|
+
// 创建 customRender 函数,通过闭包访问 ctx
|
|
158
|
+
column.customRender = (() => {
|
|
159
|
+
// 在闭包中保存 ctx 的引用
|
|
160
|
+
const renderCtx = ctx
|
|
161
|
+
return ({ text, record, index }) => {
|
|
162
|
+
const cellValue = record && dataIndex ? record[dataIndex] : text
|
|
163
|
+
// 将 cellOptions 转换为数组格式(支持对象和数组两种格式)
|
|
164
|
+
let options = []
|
|
165
|
+
const cellOptions = column.cellOptions
|
|
166
|
+
if (Array.isArray(cellOptions)) {
|
|
167
|
+
// 如果已经是数组,直接使用
|
|
168
|
+
options = cellOptions
|
|
169
|
+
} else if (cellOptions && typeof cellOptions === 'object') {
|
|
170
|
+
// 如果是对象,转换为数组格式 { 是: 1, 否: 0 } => [{label: '是', value: 1}, {label: '否', value: 0}]
|
|
171
|
+
options = Object.keys(cellOptions).map((label) => ({
|
|
172
|
+
label,
|
|
173
|
+
value: cellOptions[label]
|
|
174
|
+
}))
|
|
175
|
+
}
|
|
173
176
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
value: cellValue,
|
|
178
|
-
'onUpdate:value': (val) => {
|
|
179
|
-
// Ant Design Vue 的 Input 使用 value 和 onUpdate:value
|
|
180
|
-
if (record && dataIndex) {
|
|
181
|
-
record[dataIndex] = val
|
|
182
|
-
// 触发表格数据更新
|
|
183
|
-
if (ctx.api && ctx.api.form && rule.field) {
|
|
184
|
-
ctx.api.form[rule.field] = props.dataSource
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
placeholder: cellProps.placeholder || '',
|
|
189
|
-
disabled: cellProps.disabled || false,
|
|
190
|
-
size: cellProps.size || 'small',
|
|
191
|
-
...cellProps
|
|
192
|
-
})
|
|
193
|
-
} else if (cellType === 'select') {
|
|
194
|
-
// 渲染 select 组件
|
|
195
|
-
return h(
|
|
196
|
-
'a-select',
|
|
197
|
-
{
|
|
177
|
+
if (cellType === 'input') {
|
|
178
|
+
// 渲染 input 组件,使用 ctx.$render.vNode 来创建
|
|
179
|
+
return renderCtx.$render.vNode.make('aInput', {
|
|
198
180
|
value: cellValue,
|
|
199
181
|
'onUpdate:value': (val) => {
|
|
200
|
-
// Ant Design Vue 的
|
|
182
|
+
// Ant Design Vue 的 Input 使用 value 和 onUpdate:value
|
|
201
183
|
if (record && dataIndex) {
|
|
202
184
|
record[dataIndex] = val
|
|
203
185
|
// 触发表格数据更新
|
|
204
|
-
if (
|
|
205
|
-
|
|
186
|
+
if (renderCtx.api && renderCtx.api.form && rule.field) {
|
|
187
|
+
renderCtx.api.form[rule.field] = props.dataSource
|
|
206
188
|
}
|
|
207
189
|
}
|
|
208
190
|
},
|
|
@@ -210,59 +192,101 @@ export default {
|
|
|
210
192
|
disabled: cellProps.disabled || false,
|
|
211
193
|
size: cellProps.size || 'small',
|
|
212
194
|
...cellProps
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
'a-radio-group',
|
|
229
|
-
{
|
|
230
|
-
modelValue: cellValue,
|
|
231
|
-
'onUpdate:modelValue': (val) => {
|
|
232
|
-
// Ant Design Vue 的 RadioGroup 使用 modelValue
|
|
233
|
-
if (record && dataIndex) {
|
|
234
|
-
record[dataIndex] = val
|
|
235
|
-
// 触发表格数据更新
|
|
236
|
-
if (ctx.api && ctx.api.form && rule.field) {
|
|
237
|
-
ctx.api.form[rule.field] = props.dataSource
|
|
195
|
+
})
|
|
196
|
+
} else if (cellType === 'select') {
|
|
197
|
+
// 渲染 select 组件
|
|
198
|
+
return renderCtx.$render.vNode.make(
|
|
199
|
+
'aSelect',
|
|
200
|
+
{
|
|
201
|
+
value: cellValue,
|
|
202
|
+
'onUpdate:value': (val) => {
|
|
203
|
+
// Ant Design Vue 的 Select 使用 value 和 onUpdate:value
|
|
204
|
+
if (record && dataIndex) {
|
|
205
|
+
record[dataIndex] = val
|
|
206
|
+
// 触发表格数据更新
|
|
207
|
+
if (renderCtx.api && renderCtx.api.form && rule.field) {
|
|
208
|
+
renderCtx.api.form[rule.field] = props.dataSource
|
|
209
|
+
}
|
|
238
210
|
}
|
|
239
|
-
}
|
|
211
|
+
},
|
|
212
|
+
placeholder: cellProps.placeholder || '',
|
|
213
|
+
disabled: cellProps.disabled || false,
|
|
214
|
+
size: cellProps.size || 'small',
|
|
215
|
+
...cellProps
|
|
240
216
|
},
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
default: () =>
|
|
247
|
-
options.map((opt) => {
|
|
248
|
-
return h(
|
|
249
|
-
'a-radio',
|
|
250
|
-
{
|
|
251
|
-
key: opt.value,
|
|
252
|
-
value: opt.value
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
default: () => opt.label || opt.value
|
|
256
|
-
}
|
|
257
|
-
)
|
|
217
|
+
options.map((opt) => {
|
|
218
|
+
return renderCtx.$render.vNode.make('aSelectOption', {
|
|
219
|
+
key: opt.value,
|
|
220
|
+
value: opt.value,
|
|
221
|
+
label: opt.label
|
|
258
222
|
})
|
|
223
|
+
})
|
|
224
|
+
)
|
|
225
|
+
} else if (cellType === 'radio') {
|
|
226
|
+
// 渲染 radio 组件
|
|
227
|
+
// 当 cellValue 是 null 或 undefined 时,确保 modelValue 是 undefined
|
|
228
|
+
const radioValue =
|
|
229
|
+
cellValue !== null && cellValue !== undefined
|
|
230
|
+
? cellValue
|
|
231
|
+
: undefined
|
|
232
|
+
|
|
233
|
+
// 使用 ctx.$render.vNode.h 创建组件,确保组件名正确解析
|
|
234
|
+
// Radio 的 children 需要作为函数传递,避免警告
|
|
235
|
+
const radioChildren = options.map((opt) => {
|
|
236
|
+
return renderCtx.$render.vNode.h(
|
|
237
|
+
'aRadio',
|
|
238
|
+
{
|
|
239
|
+
key: opt.value,
|
|
240
|
+
value: opt.value
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
default: () => opt.label || opt.value
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
// 统一的值更新处理函数
|
|
249
|
+
const handleValueChange = (val) => {
|
|
250
|
+
if (record && dataIndex) {
|
|
251
|
+
record[dataIndex] = val
|
|
252
|
+
// 触发表格数据更新
|
|
253
|
+
if (renderCtx.api && renderCtx.api.form && rule.field) {
|
|
254
|
+
renderCtx.api.form[rule.field] = props.dataSource
|
|
255
|
+
}
|
|
256
|
+
// 触发同步更新
|
|
257
|
+
if (renderCtx.api && renderCtx.api.sync) {
|
|
258
|
+
renderCtx.api.sync(rule)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
259
261
|
}
|
|
260
|
-
)
|
|
261
|
-
}
|
|
262
262
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
263
|
+
return renderCtx.$render.vNode.h(
|
|
264
|
+
'aRadioGroup',
|
|
265
|
+
{
|
|
266
|
+
value: radioValue,
|
|
267
|
+
onChange: (e) => {
|
|
268
|
+
// Ant Design Vue 的 RadioGroup onChange 直接传递 value 作为参数
|
|
269
|
+
// 但也可能是事件对象,兼容两种方式
|
|
270
|
+
const val =
|
|
271
|
+
typeof e === 'object' && e?.target?.value !== undefined
|
|
272
|
+
? e.target.value
|
|
273
|
+
: e
|
|
274
|
+
handleValueChange(val)
|
|
275
|
+
},
|
|
276
|
+
disabled: cellProps.disabled || false,
|
|
277
|
+
size: cellProps.size || 'small',
|
|
278
|
+
...cellProps
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
default: () => radioChildren
|
|
282
|
+
}
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// 如果没有匹配的类型,返回原始文本
|
|
287
|
+
return text
|
|
288
|
+
}
|
|
289
|
+
})()
|
|
266
290
|
}
|
|
267
291
|
|
|
268
292
|
// 确保其他列属性也被保留(align、fixed、title、dataIndex 等)
|