n20-common-lib 2.22.2 → 2.22.4
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
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
iconNone: 'n20-icon-xiala-moren',
|
|
43
43
|
iconMatch: 'n20-icon-xiala-moren'
|
|
44
44
|
}"
|
|
45
|
-
|
|
45
|
+
:merge-cells="mergeCells"
|
|
46
|
+
v-bind="Object.assign({ size: size }, $attrs, sizeBind, $attrs.small)"
|
|
46
47
|
v-on="$listeners"
|
|
47
48
|
@sort-change="(val) => customSortMethod(val)"
|
|
48
49
|
@filter-change="filterChange"
|
|
@@ -77,16 +78,26 @@
|
|
|
77
78
|
>
|
|
78
79
|
<template #header="{ $table, checked, indeterminate, disabled }">
|
|
79
80
|
<span class="custom-checkbox" @click.stop="toggleAll($table, disabled)">
|
|
80
|
-
<el-checkbox
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
<el-checkbox
|
|
82
|
+
v-if="indeterminate"
|
|
83
|
+
:key="key + '-header-indeterminate'"
|
|
84
|
+
:indeterminate="indeterminate"
|
|
85
|
+
:disabled="disabled"
|
|
86
|
+
/>
|
|
87
|
+
<el-checkbox v-else-if="checked" :key="key + '-header-checked'" :value="checked" :disabled="disabled" />
|
|
88
|
+
<el-checkbox v-else :key="key + '-header-unchecked'" :value="checked" :disabled="disabled" />
|
|
83
89
|
</span>
|
|
84
90
|
</template>
|
|
85
91
|
<template #checkbox="{ $table, row, checked, indeterminate, disabled }">
|
|
86
92
|
<span class="custom-checkbox" @click.stop="toggleChecked($table, row, disabled)">
|
|
87
|
-
<el-checkbox
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
<el-checkbox
|
|
94
|
+
v-if="indeterminate"
|
|
95
|
+
:key="key + '-row-indeterminate'"
|
|
96
|
+
:indeterminate="indeterminate"
|
|
97
|
+
:disabled="disabled"
|
|
98
|
+
/>
|
|
99
|
+
<el-checkbox v-else-if="checked" :key="key + '-row-checked'" :value="checked" :disabled="disabled" />
|
|
100
|
+
<el-checkbox v-else :key="key + '-row-unchecked'" :value="checked" :disabled="disabled" />
|
|
90
101
|
</span>
|
|
91
102
|
</template>
|
|
92
103
|
</vxe-column>
|
|
@@ -109,7 +120,7 @@
|
|
|
109
120
|
</vxe-colgroup>
|
|
110
121
|
<vxe-column
|
|
111
122
|
v-else
|
|
112
|
-
:key="'vxe-table-' + i"
|
|
123
|
+
:key="'vxe-table-column' + i"
|
|
113
124
|
:class-name="`${item.wrap && `vxe-table-custom-wrap`} ${item.bold && `font-w600`}`"
|
|
114
125
|
:formatter="item.formatter ? item.formatter : 'formatName'"
|
|
115
126
|
:filters="item.filters"
|
|
@@ -210,6 +221,16 @@ export default {
|
|
|
210
221
|
isAutoWidth: {
|
|
211
222
|
type: Boolean,
|
|
212
223
|
default: true
|
|
224
|
+
},
|
|
225
|
+
// 合并单元格配置,格式: [{ row: 0, col: 0, rowspan: 2, colspan: 0 }]
|
|
226
|
+
mergeCells: {
|
|
227
|
+
type: Array,
|
|
228
|
+
default: () => []
|
|
229
|
+
},
|
|
230
|
+
// 全选时是否排除被合并的行(从属行)
|
|
231
|
+
excludeMergedRows: {
|
|
232
|
+
type: Boolean,
|
|
233
|
+
default: false
|
|
213
234
|
}
|
|
214
235
|
},
|
|
215
236
|
data() {
|
|
@@ -250,14 +271,53 @@ export default {
|
|
|
250
271
|
},
|
|
251
272
|
mounted() {},
|
|
252
273
|
methods: {
|
|
253
|
-
//
|
|
274
|
+
// 全选/反选
|
|
254
275
|
toggleAllSelection() {
|
|
255
|
-
if (this.$refs.vxeTable)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
276
|
+
if (!this.$refs.vxeTable) return
|
|
277
|
+
const allData = this.data || []
|
|
278
|
+
// 获取合并行索引集合
|
|
279
|
+
const mergedIndexes =
|
|
280
|
+
this.excludeMergedRows && this.mergeCells && this.mergeCells.length > 0 ? this.getMergedRowIndexes() : new Set()
|
|
281
|
+
// 筛选出可选择的行(排除合并从属行 + 排除禁止选择的行)
|
|
282
|
+
const selectableRows = allData.filter((row, index) => {
|
|
283
|
+
if (mergedIndexes.has(index)) return false
|
|
284
|
+
if (typeof this.forbidSelect === 'function' && this.forbidSelect({ row }) === true) return false
|
|
285
|
+
return true
|
|
286
|
+
})
|
|
287
|
+
// 判断当前可选行是否已全部选中
|
|
288
|
+
const checkedRows = this.$refs.vxeTable.getCheckboxRecords(false)
|
|
289
|
+
const checkedSet = new Set(checkedRows)
|
|
290
|
+
const isAllChecked = selectableRows.length > 0 && selectableRows.every((row) => checkedSet.has(row))
|
|
291
|
+
if (isAllChecked) {
|
|
292
|
+
// 已全选,则取消可选行的选中状态
|
|
293
|
+
selectableRows.forEach((row) => {
|
|
294
|
+
this.$refs.vxeTable.setCheckboxRow(row, false)
|
|
295
|
+
})
|
|
296
|
+
} else {
|
|
297
|
+
// 未全选,则选中所有可选行
|
|
298
|
+
selectableRows.forEach((row) => {
|
|
299
|
+
this.$refs.vxeTable.setCheckboxRow(row, true)
|
|
300
|
+
})
|
|
301
|
+
}
|
|
302
|
+
// 得手动触发
|
|
303
|
+
this.handleSelectionChange()
|
|
304
|
+
},
|
|
305
|
+
// 获取被合并的从属行索引集合
|
|
306
|
+
getMergedRowIndexes() {
|
|
307
|
+
const mergedIndexes = new Set()
|
|
308
|
+
if (this.mergeCells && this.mergeCells.length > 0) {
|
|
309
|
+
this.mergeCells.forEach((cell) => {
|
|
310
|
+
if (cell.rowspan > 1) {
|
|
311
|
+
// 从 row+1 到 row+rowspan-1 都是被合并的从属行
|
|
312
|
+
for (let i = 1; i < cell.rowspan; i++) {
|
|
313
|
+
mergedIndexes.add(cell.row + i)
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
})
|
|
259
317
|
}
|
|
318
|
+
return mergedIndexes
|
|
260
319
|
},
|
|
320
|
+
|
|
261
321
|
// 清空选择
|
|
262
322
|
clearSelection() {
|
|
263
323
|
if (this.$refs.vxeTable) {
|
|
@@ -276,7 +336,35 @@ export default {
|
|
|
276
336
|
if (disabled) {
|
|
277
337
|
return false
|
|
278
338
|
}
|
|
279
|
-
|
|
339
|
+
// 如果配置了排除合并行,则手动处理非合并行的选中状态
|
|
340
|
+
if (this.excludeMergedRows && this.mergeCells && this.mergeCells.length > 0) {
|
|
341
|
+
const mergedIndexes = this.getMergedRowIndexes()
|
|
342
|
+
const allData = this.data || []
|
|
343
|
+
// 筛选出可选择的行(排除合并从属行 + 排除禁止选择的行)
|
|
344
|
+
const selectableRows = allData.filter((row, index) => {
|
|
345
|
+
if (mergedIndexes.has(index)) return false
|
|
346
|
+
if (typeof this.forbidSelect === 'function' && this.forbidSelect({ row }) === true) return false
|
|
347
|
+
return true
|
|
348
|
+
})
|
|
349
|
+
// 判断当前可选行是否已全部选中
|
|
350
|
+
const checkedRows = $table.getCheckboxRecords(false)
|
|
351
|
+
const checkedSet = new Set(checkedRows)
|
|
352
|
+
const isAllChecked = selectableRows.length > 0 && selectableRows.every((row) => checkedSet.has(row))
|
|
353
|
+
if (isAllChecked) {
|
|
354
|
+
// 已全选,则取消可选行的选中状态
|
|
355
|
+
selectableRows.forEach((row) => {
|
|
356
|
+
$table.setCheckboxRow(row, false)
|
|
357
|
+
})
|
|
358
|
+
} else {
|
|
359
|
+
// 未全选,则选中所有可选行
|
|
360
|
+
selectableRows.forEach((row) => {
|
|
361
|
+
$table.setCheckboxRow(row, true)
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
// 默认行为:全选/取消全选所有行
|
|
366
|
+
$table.toggleAllCheckboxRow()
|
|
367
|
+
}
|
|
280
368
|
this.key++
|
|
281
369
|
this.handleSelectionChange()
|
|
282
370
|
},
|