@xuekl/cli-components 1.8.0 → 1.9.146
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/XklButton.vue +51 -24
- package/XklDatePicker.vue +115 -7
- package/XklDict.vue +121 -24
- package/XklDropdownItem.vue +90 -6
- package/XklForm.vue +416 -57
- package/XklFormInfo.vue +35 -18
- package/XklLink.vue +96 -16
- package/XklSelect.vue +355 -29
- package/XklTable.vue +104 -30
- package/XklTableV2.vue +54 -0
- package/XklVirtualScroll.vue +332 -0
- package/XklVirtualTable.vue +161 -0
- package/package.json +1 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="XklVirtualTable">
|
|
3
|
+
<xkl-virtual-scroll target=".el-scrollbar__wrap" item-target=".el-table__body > tbody > .el-table__row"
|
|
4
|
+
:data="table.list" :height="40" :key-prop="rowKey" @change="render">
|
|
5
|
+
<xkl-table ref="XklTableRefer" :row-key="rowKey" :table="table" @virtual-select="select"
|
|
6
|
+
@virtual-select-all="selectAll">
|
|
7
|
+
<template v-for="slotCol in slotCols" v-slot:[slotCol.prop]="{ row }">
|
|
8
|
+
<slot :name="slotCol.prop" :row="row"></slot>
|
|
9
|
+
</template>
|
|
10
|
+
<template #_operation="{ row }">
|
|
11
|
+
<slot name="_operation" :row="row"></slot>
|
|
12
|
+
</template>
|
|
13
|
+
</xkl-table>
|
|
14
|
+
</xkl-virtual-scroll>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
export default {
|
|
19
|
+
name: 'XklVirtualTable'
|
|
20
|
+
}
|
|
21
|
+
</script>
|
|
22
|
+
<script setup lang="ts">
|
|
23
|
+
import { Ref, computed, onMounted, ref, watch } from 'vue';
|
|
24
|
+
const props = defineProps(['table', 'data', 'rowKey'])
|
|
25
|
+
const emit = defineEmits(['select', 'select-all', 'selection-change'])
|
|
26
|
+
const { table, rowKey } = props
|
|
27
|
+
table.selectionConfig.reserveSelection = true
|
|
28
|
+
table.virtual = true
|
|
29
|
+
|
|
30
|
+
const slotCols = computed(() => table.columns.filter(col => col.slot))
|
|
31
|
+
|
|
32
|
+
const XklVirtualTable = ref(null)
|
|
33
|
+
const XklTableRefer: Ref<any> = ref({})
|
|
34
|
+
|
|
35
|
+
const state = {
|
|
36
|
+
isSelectAll: false,
|
|
37
|
+
isIndeterminate: false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const select = (row) => {
|
|
41
|
+
if (row.selected) {
|
|
42
|
+
table.selectedData = table.selectedData.concat(row)
|
|
43
|
+
} else {
|
|
44
|
+
table.selectedData = table.selectedData.filter(item => item[props.rowKey] !== row[props.rowKey])
|
|
45
|
+
}
|
|
46
|
+
state.isSelectAll = table.selectedData.length === table.list.length
|
|
47
|
+
const checkedCount = table.selectedData.length
|
|
48
|
+
state.isIndeterminate = checkedCount > 0 && checkedCount !== table.list.length
|
|
49
|
+
setCheckboxState(state.isSelectAll, state.isIndeterminate)
|
|
50
|
+
emit('select', table.selectedData, row)
|
|
51
|
+
emit('selection-change', table.selectedData)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let setCheckboxState: (flag1: boolean, flag2: boolean) => void = (flag) => { }
|
|
55
|
+
|
|
56
|
+
const selectAll = (isSelectAll, call) => {
|
|
57
|
+
state.isSelectAll = isSelectAll
|
|
58
|
+
// setCheckboxState = call
|
|
59
|
+
if (state.isSelectAll) {
|
|
60
|
+
table.virtualList.forEach(item => item.selected = true)
|
|
61
|
+
table.selectedData = table.selectedData.concat(table.list)
|
|
62
|
+
let selectedKeys = table.selectedData.map(item => item[props.rowKey])
|
|
63
|
+
selectedKeys = Array.from(new Set(selectedKeys))
|
|
64
|
+
table.selectedData = selectedKeys.map(key => table.selectedData.find(item => item[props.rowKey] === key))
|
|
65
|
+
} else {
|
|
66
|
+
const listKeys = table.list.map(item => item[props.rowKey])
|
|
67
|
+
table.selectedData = table.selectedData.filter(item => !listKeys.includes(item[props.rowKey]))
|
|
68
|
+
table.virtualList.forEach(item => item.selected = false)
|
|
69
|
+
}
|
|
70
|
+
const checkedCount = table.selectedData.length
|
|
71
|
+
state.isIndeterminate = checkedCount > 0 && checkedCount !== table.list.length
|
|
72
|
+
|
|
73
|
+
setCheckboxState(state.isSelectAll, state.isIndeterminate)
|
|
74
|
+
emit('select-all', table.selectedData)
|
|
75
|
+
emit('selection-change', table.selectedData)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
watch(() => table.list, () => {
|
|
79
|
+
const checkedCount = table.selectedData.length
|
|
80
|
+
//这里不是准确的判断,通过key循环判断太耗性能,有需要再做
|
|
81
|
+
const selectedKeys = table.selectedData.map(item => item[props.rowKey])
|
|
82
|
+
const listKeys = table.list.map(item => item[props.rowKey])
|
|
83
|
+
|
|
84
|
+
// state.isSelectAll = checkedCount > 0 && checkedCount >= table.list.length
|
|
85
|
+
state.isSelectAll = checkedCount > 0 && listKeys.every(key => selectedKeys.includes(key))
|
|
86
|
+
state.isIndeterminate = checkedCount > 0 && checkedCount < table.totalCount
|
|
87
|
+
setCheckboxState(state.isSelectAll, state.isIndeterminate)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const render = (list) => {
|
|
91
|
+
table.virtualList = list
|
|
92
|
+
if (state.isSelectAll) {
|
|
93
|
+
table.virtualList.forEach(item => {
|
|
94
|
+
item.selected = true
|
|
95
|
+
})
|
|
96
|
+
} else {
|
|
97
|
+
|
|
98
|
+
table.virtualList.forEach(item => {
|
|
99
|
+
const keys = table.selectedData.map(inner => inner[props.rowKey])
|
|
100
|
+
item.selected = keys.includes(item[props.rowKey])
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const clearSelection = () => {
|
|
107
|
+
state.isSelectAll = false
|
|
108
|
+
state.isIndeterminate = false
|
|
109
|
+
table.selectedData = []
|
|
110
|
+
table.virtualList.forEach(item => item.selected = false)
|
|
111
|
+
setCheckboxState(state.isSelectAll, state.isIndeterminate)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// table.getRef = () => ({
|
|
115
|
+
// ...XklTableRefer.value.getRef(),
|
|
116
|
+
// clearSelection
|
|
117
|
+
// })
|
|
118
|
+
|
|
119
|
+
onMounted(() => {
|
|
120
|
+
const refer = XklTableRefer.value
|
|
121
|
+
setCheckboxState = refer.setCheckboxState
|
|
122
|
+
const getRef = refer.getRef()
|
|
123
|
+
const clearSort = getRef.clearSort
|
|
124
|
+
const getSelectionRows = () => {
|
|
125
|
+
return table.selectedData
|
|
126
|
+
}
|
|
127
|
+
const toggleRowSelection = (row, flag) => {
|
|
128
|
+
if (typeof flag === 'undefined') {
|
|
129
|
+
row.selected = !row.selected
|
|
130
|
+
select(row)
|
|
131
|
+
} else {
|
|
132
|
+
if (row.selected && flag) {
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
//列表更换后,选中的item已经不在list中,此时把list中与之相同id的数据,找出来,取消选中
|
|
136
|
+
if (!table.list.includes(row)) {
|
|
137
|
+
const item = table.list.find(res => res[props.rowKey] === row[props.rowKey])
|
|
138
|
+
if (item) {
|
|
139
|
+
item.selected = flag
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
row.selected = flag
|
|
143
|
+
select(row)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const toggleAllSelection = getRef.toggleAllSelection
|
|
147
|
+
const clearFilter = getRef.clearFilter
|
|
148
|
+
const setCurrentRow = getRef.setCurrentRow
|
|
149
|
+
table.getRef = () => ({
|
|
150
|
+
clearSort,
|
|
151
|
+
clearSelection,
|
|
152
|
+
getSelectionRows,
|
|
153
|
+
toggleRowSelection,
|
|
154
|
+
toggleAllSelection,
|
|
155
|
+
clearFilter,
|
|
156
|
+
setCurrentRow
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
defineExpose({ clearSelection })
|
|
161
|
+
</script>
|