@longhongguo/form-create-ant-design-vue 3.3.39 → 3.3.40
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.3.
|
|
3
|
+
"version": "3.3.40",
|
|
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",
|
|
@@ -88,6 +88,16 @@ export default {
|
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
watch: {
|
|
91
|
+
columns: {
|
|
92
|
+
handler() {
|
|
93
|
+
// 当 columns 变化时,重新解析 optionsFn
|
|
94
|
+
this.parseColumnsOptionsFn()
|
|
95
|
+
this.loadRule()
|
|
96
|
+
this.updateTable()
|
|
97
|
+
},
|
|
98
|
+
deep: true,
|
|
99
|
+
immediate: false
|
|
100
|
+
},
|
|
91
101
|
modelValue: {
|
|
92
102
|
handler() {
|
|
93
103
|
this.updateTable()
|
|
@@ -125,6 +135,7 @@ export default {
|
|
|
125
135
|
copyTrs: '',
|
|
126
136
|
oldValue: '',
|
|
127
137
|
selectedRows: new Set(), // 存储选中行的索引
|
|
138
|
+
parsedColumns: [], // 存储解析后的 columns(包含解析后的 optionsFn)
|
|
128
139
|
emptyRule: {
|
|
129
140
|
type: 'tr',
|
|
130
141
|
_isEmpty: true,
|
|
@@ -152,9 +163,56 @@ export default {
|
|
|
152
163
|
}
|
|
153
164
|
},
|
|
154
165
|
methods: {
|
|
166
|
+
parseColumnsOptionsFn() {
|
|
167
|
+
// 使用 formCreate 的 parseFn 来解析 optionsFn 字符串为函数
|
|
168
|
+
let parseFn
|
|
169
|
+
if (this.formCreateInject?.form?.parseFn) {
|
|
170
|
+
parseFn = this.formCreateInject.form.parseFn
|
|
171
|
+
} else {
|
|
172
|
+
// 如果 formCreateInject 中没有 parseFn,尝试动态 require
|
|
173
|
+
try {
|
|
174
|
+
const jsonUtils = require('@form-create/utils/lib/json')
|
|
175
|
+
parseFn = jsonUtils.parseFn
|
|
176
|
+
} catch (e) {
|
|
177
|
+
// 如果 require 失败,创建一个简单的解析函数
|
|
178
|
+
parseFn = (fn) => {
|
|
179
|
+
if (typeof fn !== 'string') return fn
|
|
180
|
+
// 尝试解析 [[FORM-CREATE-PREFIX-...-FORM-CREATE-SUFFIX]] 格式
|
|
181
|
+
const PREFIX = '[[FORM-CREATE-PREFIX-'
|
|
182
|
+
const SUFFIX = '-FORM-CREATE-SUFFIX]]'
|
|
183
|
+
if (fn.indexOf(PREFIX) === 0 && fn.indexOf(SUFFIX) > 0) {
|
|
184
|
+
const funcStr = fn.replace(SUFFIX, '').replace(PREFIX, '')
|
|
185
|
+
try {
|
|
186
|
+
return new Function('return ' + funcStr)()
|
|
187
|
+
} catch (err) {
|
|
188
|
+
console.warn('Failed to parse optionsFn:', err)
|
|
189
|
+
return fn
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return fn
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
this.parsedColumns = (this.columns || []).map((column) => {
|
|
198
|
+
const parsedColumn = { ...column }
|
|
199
|
+
// 如果 optionsFn 是字符串,解析为函数
|
|
200
|
+
if (column.optionsFn) {
|
|
201
|
+
if (typeof column.optionsFn === 'string') {
|
|
202
|
+
parsedColumn.optionsFn = parseFn(column.optionsFn)
|
|
203
|
+
} else if (typeof column.optionsFn === 'function') {
|
|
204
|
+
// 如果已经是函数,直接使用
|
|
205
|
+
parsedColumn.optionsFn = column.optionsFn
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return parsedColumn
|
|
209
|
+
})
|
|
210
|
+
},
|
|
155
211
|
getEmptyColspan() {
|
|
212
|
+
const columnsToUse =
|
|
213
|
+
this.parsedColumns.length > 0 ? this.parsedColumns : this.columns
|
|
156
214
|
return (
|
|
157
|
-
|
|
215
|
+
columnsToUse.length +
|
|
158
216
|
(this.showIndexColumn ? 1 : 0) +
|
|
159
217
|
(this.showSelectColumn ? 1 : 0) +
|
|
160
218
|
(this.showOperationColumn ? (this.formCreateInject.preview ? 0 : 1) : 0)
|
|
@@ -201,7 +259,7 @@ export default {
|
|
|
201
259
|
return
|
|
202
260
|
}
|
|
203
261
|
this.oldValue = str
|
|
204
|
-
|
|
262
|
+
|
|
205
263
|
// 从数据中读取选中状态,初始化 selectedRows
|
|
206
264
|
if (this.showSelectColumn) {
|
|
207
265
|
this.selectedRows.clear()
|
|
@@ -211,7 +269,7 @@ export default {
|
|
|
211
269
|
}
|
|
212
270
|
})
|
|
213
271
|
}
|
|
214
|
-
|
|
272
|
+
|
|
215
273
|
this.trs = this.trs.splice(0, this.modelValue.length)
|
|
216
274
|
if (!this.modelValue.length) {
|
|
217
275
|
this.addEmpty()
|
|
@@ -276,7 +334,7 @@ export default {
|
|
|
276
334
|
// 更新 selectedRows,删除当前索引,后续索引前移
|
|
277
335
|
this.selectedRows.delete(idx)
|
|
278
336
|
const newSelectedRows = new Set()
|
|
279
|
-
this.selectedRows.forEach(selectedIdx => {
|
|
337
|
+
this.selectedRows.forEach((selectedIdx) => {
|
|
280
338
|
if (selectedIdx < idx) {
|
|
281
339
|
newSelectedRows.add(selectedIdx)
|
|
282
340
|
} else if (selectedIdx > idx) {
|
|
@@ -284,7 +342,7 @@ export default {
|
|
|
284
342
|
}
|
|
285
343
|
})
|
|
286
344
|
this.selectedRows = newSelectedRows
|
|
287
|
-
|
|
345
|
+
|
|
288
346
|
this.updateValue()
|
|
289
347
|
if (this.trs.length) {
|
|
290
348
|
this.trs.forEach((tr) => this.updateRaw(tr))
|
|
@@ -316,13 +374,13 @@ export default {
|
|
|
316
374
|
const idx = this.trs.indexOf(tr)
|
|
317
375
|
const rowData = this.modelValue[idx] || {}
|
|
318
376
|
let colOffset = 0
|
|
319
|
-
|
|
377
|
+
|
|
320
378
|
// 更新序号列
|
|
321
379
|
if (this.showIndexColumn && tr.children[colOffset]) {
|
|
322
380
|
tr.children[colOffset].props.innerText = idx + 1
|
|
323
381
|
colOffset++
|
|
324
382
|
}
|
|
325
|
-
|
|
383
|
+
|
|
326
384
|
// 更新选择列
|
|
327
385
|
if (this.showSelectColumn && tr.children[colOffset]) {
|
|
328
386
|
const selectCell = tr.children[colOffset]
|
|
@@ -342,7 +400,9 @@ export default {
|
|
|
342
400
|
if (tableEl) {
|
|
343
401
|
const rows = tableEl.querySelectorAll('tbody tr')
|
|
344
402
|
if (rows[idx]) {
|
|
345
|
-
const checkbox = rows[idx].querySelector(
|
|
403
|
+
const checkbox = rows[idx].querySelector(
|
|
404
|
+
'._fc-tf-select input[type="checkbox"]'
|
|
405
|
+
)
|
|
346
406
|
if (checkbox) {
|
|
347
407
|
checkbox.checked = isSelected
|
|
348
408
|
}
|
|
@@ -351,15 +411,24 @@ export default {
|
|
|
351
411
|
})
|
|
352
412
|
colOffset++
|
|
353
413
|
}
|
|
354
|
-
|
|
414
|
+
|
|
355
415
|
// 更新数据列的动态 options(如 checkbox)
|
|
356
|
-
|
|
416
|
+
// 使用 parsedColumns 而不是原始的 columns,确保 optionsFn 已被解析
|
|
417
|
+
const columnsToUse =
|
|
418
|
+
this.parsedColumns.length > 0 ? this.parsedColumns : this.columns
|
|
419
|
+
columnsToUse.forEach((column, colIdx) => {
|
|
357
420
|
const cellIdx = colOffset + colIdx
|
|
358
421
|
if (tr.children[cellIdx] && tr.children[cellIdx].children) {
|
|
359
422
|
const cellChildren = tr.children[cellIdx].children
|
|
360
|
-
// 查找 checkbox 类型的规则
|
|
361
|
-
const checkboxRule = cellChildren.find(
|
|
362
|
-
|
|
423
|
+
// 查找 checkbox 或 radio 类型的规则
|
|
424
|
+
const checkboxRule = cellChildren.find(
|
|
425
|
+
(rule) => rule.type === 'checkbox' || rule.type === 'radio'
|
|
426
|
+
)
|
|
427
|
+
if (
|
|
428
|
+
checkboxRule &&
|
|
429
|
+
column.optionsFn &&
|
|
430
|
+
typeof column.optionsFn === 'function'
|
|
431
|
+
) {
|
|
363
432
|
// 调用 optionsFn 获取该行的 options
|
|
364
433
|
const dynamicOptions = column.optionsFn(rowData, idx)
|
|
365
434
|
if (Array.isArray(dynamicOptions)) {
|
|
@@ -373,7 +442,7 @@ export default {
|
|
|
373
442
|
}
|
|
374
443
|
}
|
|
375
444
|
})
|
|
376
|
-
|
|
445
|
+
|
|
377
446
|
// 更新操作列的删除按钮
|
|
378
447
|
if (this.showOperationColumn && tr.children[tr.children.length - 1]) {
|
|
379
448
|
const operationCell = tr.children[tr.children.length - 1]
|
|
@@ -429,13 +498,13 @@ export default {
|
|
|
429
498
|
},
|
|
430
499
|
updateSelectAllState() {
|
|
431
500
|
if (!this.showSelectColumn) return
|
|
432
|
-
|
|
501
|
+
|
|
433
502
|
const validRows = this.modelValue.filter((rowData, idx) => {
|
|
434
503
|
const tr = this.trs[idx]
|
|
435
504
|
return tr && !tr._isEmpty
|
|
436
505
|
})
|
|
437
506
|
if (validRows.length === 0) return
|
|
438
|
-
|
|
507
|
+
|
|
439
508
|
// 从数据对象中读取选中状态
|
|
440
509
|
const allSelected = validRows.every((rowData) => {
|
|
441
510
|
return rowData && rowData[this.selectField] === true
|
|
@@ -443,12 +512,14 @@ export default {
|
|
|
443
512
|
const someSelected = validRows.some((rowData) => {
|
|
444
513
|
return rowData && rowData[this.selectField] === true
|
|
445
514
|
})
|
|
446
|
-
|
|
515
|
+
|
|
447
516
|
// 更新表头的全选checkbox(通过 DOM 操作)
|
|
448
517
|
this.$nextTick(() => {
|
|
449
518
|
const tableEl = this.$el?.querySelector('._fc-tf-table')
|
|
450
519
|
if (tableEl) {
|
|
451
|
-
const headerCheckbox = tableEl.querySelector(
|
|
520
|
+
const headerCheckbox = tableEl.querySelector(
|
|
521
|
+
'._fc-tf-head-select input[type="checkbox"]'
|
|
522
|
+
)
|
|
452
523
|
if (headerCheckbox) {
|
|
453
524
|
headerCheckbox.checked = allSelected
|
|
454
525
|
headerCheckbox.indeterminate = !allSelected && someSelected
|
|
@@ -542,7 +613,10 @@ export default {
|
|
|
542
613
|
}
|
|
543
614
|
|
|
544
615
|
// 数据列
|
|
545
|
-
|
|
616
|
+
// 使用 parsedColumns 而不是原始的 columns,确保 optionsFn 已被解析
|
|
617
|
+
const columnsToUse =
|
|
618
|
+
this.parsedColumns.length > 0 ? this.parsedColumns : this.columns
|
|
619
|
+
columnsToUse.forEach((column) => {
|
|
546
620
|
header.push({
|
|
547
621
|
type: 'th',
|
|
548
622
|
native: true,
|
|
@@ -637,6 +711,8 @@ export default {
|
|
|
637
711
|
}
|
|
638
712
|
},
|
|
639
713
|
created() {
|
|
714
|
+
// 解析 columns 中的 optionsFn(从字符串解析为函数)
|
|
715
|
+
this.parseColumnsOptionsFn()
|
|
640
716
|
this.loadRule()
|
|
641
717
|
},
|
|
642
718
|
mounted() {
|