@longhongguo/form-create-ant-design-vue 3.3.40 → 3.3.41
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.41",
|
|
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,16 +88,6 @@ 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
|
-
},
|
|
101
91
|
modelValue: {
|
|
102
92
|
handler() {
|
|
103
93
|
this.updateTable()
|
|
@@ -135,7 +125,6 @@ export default {
|
|
|
135
125
|
copyTrs: '',
|
|
136
126
|
oldValue: '',
|
|
137
127
|
selectedRows: new Set(), // 存储选中行的索引
|
|
138
|
-
parsedColumns: [], // 存储解析后的 columns(包含解析后的 optionsFn)
|
|
139
128
|
emptyRule: {
|
|
140
129
|
type: 'tr',
|
|
141
130
|
_isEmpty: true,
|
|
@@ -163,56 +152,9 @@ export default {
|
|
|
163
152
|
}
|
|
164
153
|
},
|
|
165
154
|
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
|
-
},
|
|
211
155
|
getEmptyColspan() {
|
|
212
|
-
const columnsToUse =
|
|
213
|
-
this.parsedColumns.length > 0 ? this.parsedColumns : this.columns
|
|
214
156
|
return (
|
|
215
|
-
|
|
157
|
+
this.columns.length +
|
|
216
158
|
(this.showIndexColumn ? 1 : 0) +
|
|
217
159
|
(this.showSelectColumn ? 1 : 0) +
|
|
218
160
|
(this.showOperationColumn ? (this.formCreateInject.preview ? 0 : 1) : 0)
|
|
@@ -259,7 +201,7 @@ export default {
|
|
|
259
201
|
return
|
|
260
202
|
}
|
|
261
203
|
this.oldValue = str
|
|
262
|
-
|
|
204
|
+
|
|
263
205
|
// 从数据中读取选中状态,初始化 selectedRows
|
|
264
206
|
if (this.showSelectColumn) {
|
|
265
207
|
this.selectedRows.clear()
|
|
@@ -269,7 +211,7 @@ export default {
|
|
|
269
211
|
}
|
|
270
212
|
})
|
|
271
213
|
}
|
|
272
|
-
|
|
214
|
+
|
|
273
215
|
this.trs = this.trs.splice(0, this.modelValue.length)
|
|
274
216
|
if (!this.modelValue.length) {
|
|
275
217
|
this.addEmpty()
|
|
@@ -334,7 +276,7 @@ export default {
|
|
|
334
276
|
// 更新 selectedRows,删除当前索引,后续索引前移
|
|
335
277
|
this.selectedRows.delete(idx)
|
|
336
278
|
const newSelectedRows = new Set()
|
|
337
|
-
this.selectedRows.forEach(
|
|
279
|
+
this.selectedRows.forEach(selectedIdx => {
|
|
338
280
|
if (selectedIdx < idx) {
|
|
339
281
|
newSelectedRows.add(selectedIdx)
|
|
340
282
|
} else if (selectedIdx > idx) {
|
|
@@ -342,7 +284,7 @@ export default {
|
|
|
342
284
|
}
|
|
343
285
|
})
|
|
344
286
|
this.selectedRows = newSelectedRows
|
|
345
|
-
|
|
287
|
+
|
|
346
288
|
this.updateValue()
|
|
347
289
|
if (this.trs.length) {
|
|
348
290
|
this.trs.forEach((tr) => this.updateRaw(tr))
|
|
@@ -374,13 +316,13 @@ export default {
|
|
|
374
316
|
const idx = this.trs.indexOf(tr)
|
|
375
317
|
const rowData = this.modelValue[idx] || {}
|
|
376
318
|
let colOffset = 0
|
|
377
|
-
|
|
319
|
+
|
|
378
320
|
// 更新序号列
|
|
379
321
|
if (this.showIndexColumn && tr.children[colOffset]) {
|
|
380
322
|
tr.children[colOffset].props.innerText = idx + 1
|
|
381
323
|
colOffset++
|
|
382
324
|
}
|
|
383
|
-
|
|
325
|
+
|
|
384
326
|
// 更新选择列
|
|
385
327
|
if (this.showSelectColumn && tr.children[colOffset]) {
|
|
386
328
|
const selectCell = tr.children[colOffset]
|
|
@@ -400,9 +342,7 @@ export default {
|
|
|
400
342
|
if (tableEl) {
|
|
401
343
|
const rows = tableEl.querySelectorAll('tbody tr')
|
|
402
344
|
if (rows[idx]) {
|
|
403
|
-
const checkbox = rows[idx].querySelector(
|
|
404
|
-
'._fc-tf-select input[type="checkbox"]'
|
|
405
|
-
)
|
|
345
|
+
const checkbox = rows[idx].querySelector('._fc-tf-select input[type="checkbox"]')
|
|
406
346
|
if (checkbox) {
|
|
407
347
|
checkbox.checked = isSelected
|
|
408
348
|
}
|
|
@@ -411,24 +351,15 @@ export default {
|
|
|
411
351
|
})
|
|
412
352
|
colOffset++
|
|
413
353
|
}
|
|
414
|
-
|
|
354
|
+
|
|
415
355
|
// 更新数据列的动态 options(如 checkbox)
|
|
416
|
-
|
|
417
|
-
const columnsToUse =
|
|
418
|
-
this.parsedColumns.length > 0 ? this.parsedColumns : this.columns
|
|
419
|
-
columnsToUse.forEach((column, colIdx) => {
|
|
356
|
+
this.columns.forEach((column, colIdx) => {
|
|
420
357
|
const cellIdx = colOffset + colIdx
|
|
421
358
|
if (tr.children[cellIdx] && tr.children[cellIdx].children) {
|
|
422
359
|
const cellChildren = tr.children[cellIdx].children
|
|
423
|
-
// 查找 checkbox
|
|
424
|
-
const checkboxRule = cellChildren.find(
|
|
425
|
-
|
|
426
|
-
)
|
|
427
|
-
if (
|
|
428
|
-
checkboxRule &&
|
|
429
|
-
column.optionsFn &&
|
|
430
|
-
typeof column.optionsFn === 'function'
|
|
431
|
-
) {
|
|
360
|
+
// 查找 checkbox 类型的规则
|
|
361
|
+
const checkboxRule = cellChildren.find((rule) => rule.type === 'checkbox')
|
|
362
|
+
if (checkboxRule && column.optionsFn && typeof column.optionsFn === 'function') {
|
|
432
363
|
// 调用 optionsFn 获取该行的 options
|
|
433
364
|
const dynamicOptions = column.optionsFn(rowData, idx)
|
|
434
365
|
if (Array.isArray(dynamicOptions)) {
|
|
@@ -442,7 +373,7 @@ export default {
|
|
|
442
373
|
}
|
|
443
374
|
}
|
|
444
375
|
})
|
|
445
|
-
|
|
376
|
+
|
|
446
377
|
// 更新操作列的删除按钮
|
|
447
378
|
if (this.showOperationColumn && tr.children[tr.children.length - 1]) {
|
|
448
379
|
const operationCell = tr.children[tr.children.length - 1]
|
|
@@ -498,13 +429,13 @@ export default {
|
|
|
498
429
|
},
|
|
499
430
|
updateSelectAllState() {
|
|
500
431
|
if (!this.showSelectColumn) return
|
|
501
|
-
|
|
432
|
+
|
|
502
433
|
const validRows = this.modelValue.filter((rowData, idx) => {
|
|
503
434
|
const tr = this.trs[idx]
|
|
504
435
|
return tr && !tr._isEmpty
|
|
505
436
|
})
|
|
506
437
|
if (validRows.length === 0) return
|
|
507
|
-
|
|
438
|
+
|
|
508
439
|
// 从数据对象中读取选中状态
|
|
509
440
|
const allSelected = validRows.every((rowData) => {
|
|
510
441
|
return rowData && rowData[this.selectField] === true
|
|
@@ -512,14 +443,12 @@ export default {
|
|
|
512
443
|
const someSelected = validRows.some((rowData) => {
|
|
513
444
|
return rowData && rowData[this.selectField] === true
|
|
514
445
|
})
|
|
515
|
-
|
|
446
|
+
|
|
516
447
|
// 更新表头的全选checkbox(通过 DOM 操作)
|
|
517
448
|
this.$nextTick(() => {
|
|
518
449
|
const tableEl = this.$el?.querySelector('._fc-tf-table')
|
|
519
450
|
if (tableEl) {
|
|
520
|
-
const headerCheckbox = tableEl.querySelector(
|
|
521
|
-
'._fc-tf-head-select input[type="checkbox"]'
|
|
522
|
-
)
|
|
451
|
+
const headerCheckbox = tableEl.querySelector('._fc-tf-head-select input[type="checkbox"]')
|
|
523
452
|
if (headerCheckbox) {
|
|
524
453
|
headerCheckbox.checked = allSelected
|
|
525
454
|
headerCheckbox.indeterminate = !allSelected && someSelected
|
|
@@ -613,10 +542,7 @@ export default {
|
|
|
613
542
|
}
|
|
614
543
|
|
|
615
544
|
// 数据列
|
|
616
|
-
|
|
617
|
-
const columnsToUse =
|
|
618
|
-
this.parsedColumns.length > 0 ? this.parsedColumns : this.columns
|
|
619
|
-
columnsToUse.forEach((column) => {
|
|
545
|
+
this.columns.forEach((column) => {
|
|
620
546
|
header.push({
|
|
621
547
|
type: 'th',
|
|
622
548
|
native: true,
|
|
@@ -711,8 +637,6 @@ export default {
|
|
|
711
637
|
}
|
|
712
638
|
},
|
|
713
639
|
created() {
|
|
714
|
-
// 解析 columns 中的 optionsFn(从字符串解析为函数)
|
|
715
|
-
this.parseColumnsOptionsFn()
|
|
716
640
|
this.loadRule()
|
|
717
641
|
},
|
|
718
642
|
mounted() {
|