vxe-table 4.18.7 → 4.18.8
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/LICENSE +20 -20
- package/README.en.md +118 -118
- package/README.ja-JP.md +117 -117
- package/README.md +268 -268
- package/README.zh-TW.md +117 -117
- package/es/style.css +1 -1
- package/es/table/src/table.js +85 -78
- package/es/table/src/util.js +6 -0
- package/es/table/style.css +18 -48
- package/es/ui/index.js +1 -1
- package/es/ui/src/dom.js +21 -0
- package/es/ui/src/log.js +1 -1
- package/es/vxe-table/style.css +18 -48
- package/lib/index.common.js +2 -1
- package/lib/index.umd.js +2762 -2833
- package/lib/index.umd.min.js +1 -1
- package/lib/style.css +1 -1
- package/lib/table/src/table.js +14 -11
- package/lib/table/src/table.min.js +1 -1
- package/lib/table/src/util.js +6 -0
- package/lib/table/src/util.min.js +1 -1
- package/lib/table/style/style.css +18 -48
- package/lib/ui/index.js +1 -1
- package/lib/ui/index.min.js +1 -1
- package/lib/ui/src/dom.js +23 -0
- package/lib/ui/src/dom.min.js +1 -1
- package/lib/ui/src/log.js +1 -1
- package/lib/ui/src/log.min.js +1 -1
- package/lib/v-x-e-table/index.js +2 -1
- package/lib/v-x-e-table/index.min.js +1 -1
- package/lib/vxe-colgroup/index.js +2 -1
- package/lib/vxe-colgroup/index.min.js +1 -1
- package/lib/vxe-column/index.js +2 -1
- package/lib/vxe-column/index.min.js +1 -1
- package/lib/vxe-grid/index.js +2 -1
- package/lib/vxe-grid/index.min.js +1 -1
- package/lib/vxe-table/index.js +2 -1
- package/lib/vxe-table/index.min.js +1 -1
- package/lib/vxe-table/style/style.css +18 -48
- package/lib/vxe-toolbar/index.js +2 -1
- package/lib/vxe-toolbar/index.min.js +1 -1
- package/lib/vxe-ui/index.js +2 -1
- package/lib/vxe-ui/index.min.js +1 -1
- package/lib/vxe-v-x-e-table/index.js +2 -1
- package/lib/vxe-v-x-e-table/index.min.js +1 -1
- package/package.json +91 -91
- package/packages/colgroup/index.ts +22 -22
- package/packages/column/index.ts +22 -22
- package/packages/components.ts +43 -43
- package/packages/grid/index.ts +18 -18
- package/packages/grid/src/emits.ts +19 -19
- package/packages/grid/src/grid.ts +1768 -1768
- package/packages/grid/src/props.ts +23 -23
- package/packages/index.ts +4 -4
- package/packages/locale/lang/ar-EG.ts +832 -832
- package/packages/locale/lang/de-DE.ts +832 -832
- package/packages/locale/lang/en-US.ts +832 -832
- package/packages/locale/lang/es-ES.ts +832 -832
- package/packages/locale/lang/fr-FR.ts +832 -832
- package/packages/locale/lang/hu-HU.ts +832 -832
- package/packages/locale/lang/hy-AM.ts +832 -832
- package/packages/locale/lang/id-ID.ts +832 -832
- package/packages/locale/lang/it-IT.ts +832 -832
- package/packages/locale/lang/ja-JP.ts +832 -832
- package/packages/locale/lang/ko-KR.ts +832 -832
- package/packages/locale/lang/ms-MY.ts +832 -832
- package/packages/locale/lang/nb-NO.ts +832 -832
- package/packages/locale/lang/pt-BR.ts +832 -832
- package/packages/locale/lang/ru-RU.ts +832 -832
- package/packages/locale/lang/th-TH.ts +832 -832
- package/packages/locale/lang/ug-CN.ts +832 -832
- package/packages/locale/lang/uk-UA.ts +832 -832
- package/packages/locale/lang/uz-UZ.ts +832 -832
- package/packages/locale/lang/vi-VN.ts +832 -832
- package/packages/locale/lang/zh-CHT.ts +832 -832
- package/packages/locale/lang/zh-CN.ts +832 -832
- package/packages/locale/lang/zh-HK.ts +3 -3
- package/packages/locale/lang/zh-MO.ts +3 -3
- package/packages/locale/lang/zh-TC.ts +3 -3
- package/packages/locale/lang/zh-TW.ts +3 -3
- package/packages/table/index.ts +26 -26
- package/packages/table/module/custom/hook.ts +359 -359
- package/packages/table/module/custom/panel.ts +1331 -1331
- package/packages/table/module/edit/hook.ts +1032 -1032
- package/packages/table/module/export/export-panel.ts +567 -567
- package/packages/table/module/export/hook.ts +1654 -1654
- package/packages/table/module/export/import-panel.ts +266 -266
- package/packages/table/module/export/util.ts +24 -24
- package/packages/table/module/filter/hook.ts +468 -468
- package/packages/table/module/filter/panel.ts +301 -301
- package/packages/table/module/keyboard/hook.ts +495 -495
- package/packages/table/module/menu/hook.ts +325 -325
- package/packages/table/module/menu/panel.ts +201 -201
- package/packages/table/module/validator/hook.ts +631 -631
- package/packages/table/render/index.ts +1440 -1440
- package/packages/table/src/body.ts +932 -932
- package/packages/table/src/cell.ts +1290 -1290
- package/packages/table/src/column.ts +190 -190
- package/packages/table/src/columnInfo.ts +225 -225
- package/packages/table/src/emits.ts +123 -123
- package/packages/table/src/footer.ts +368 -368
- package/packages/table/src/group.ts +59 -59
- package/packages/table/src/header.ts +559 -559
- package/packages/table/src/props.ts +324 -324
- package/packages/table/src/store.ts +14 -14
- package/packages/table/src/table.ts +14010 -14004
- package/packages/table/src/use/cell-view.ts +44 -44
- package/packages/table/src/use/index.ts +1 -1
- package/packages/table/src/util.ts +1070 -1064
- package/packages/toolbar/index.ts +18 -18
- package/packages/toolbar/src/toolbar.ts +701 -701
- package/packages/ui/index.ts +530 -530
- package/packages/ui/src/anime.ts +52 -52
- package/packages/ui/src/comp.ts +3 -3
- package/packages/ui/src/dom.ts +259 -236
- package/packages/ui/src/log.ts +8 -8
- package/packages/ui/src/utils.ts +56 -56
- package/packages/ui/src/vn.ts +55 -55
- package/packages/v-x-e-table/index.d.ts +4 -4
- package/packages/v-x-e-table/index.ts +4 -4
- package/styles/all.scss +7 -7
- package/styles/base.scss +16 -16
- package/styles/components/grid.scss +89 -89
- package/styles/components/icon.scss +225 -225
- package/styles/components/old-icon.scss +715 -715
- package/styles/components/table-module/all.scss +6 -6
- package/styles/components/table-module/custom.scss +527 -527
- package/styles/components/table-module/export.scss +130 -130
- package/styles/components/table-module/filter.scss +130 -130
- package/styles/components/table-module/menu.scss +81 -81
- package/styles/components/table.scss +2679 -2679
- package/styles/components/toolbar.scss +119 -119
- package/styles/default.scss +2 -2
- package/styles/helpers/baseMixin.scss +95 -95
- package/styles/index.scss +4 -4
- package/styles/modules.scss +5 -5
- package/styles/theme/base.scss +93 -93
- package/styles/theme/dark.scss +49 -49
- package/styles/theme/light.scss +44 -44
- package/styles/variable.scss +43 -43
- package/types/all.d.ts +37 -37
- package/types/index.d.ts +4 -4
- /package/es/{iconfont.1773991907408.ttf → iconfont.1774240404046.ttf} +0 -0
- /package/es/{iconfont.1773991907408.woff → iconfont.1774240404046.woff} +0 -0
- /package/es/{iconfont.1773991907408.woff2 → iconfont.1774240404046.woff2} +0 -0
- /package/lib/{iconfont.1773991907408.ttf → iconfont.1774240404046.ttf} +0 -0
- /package/lib/{iconfont.1773991907408.woff → iconfont.1774240404046.woff} +0 -0
- /package/lib/{iconfont.1773991907408.woff2 → iconfont.1774240404046.woff2} +0 -0
|
@@ -1,495 +1,495 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import { VxeUI } from '../../../ui'
|
|
3
|
-
import { getRefElem } from '../../src/util'
|
|
4
|
-
import { getAbsolutePos, addClass, removeClass, hasControlKey } from '../../../ui/src/dom'
|
|
5
|
-
|
|
6
|
-
import type { TableKeyboardPrivateMethods, VxeTableDefines } from '../../../../types'
|
|
7
|
-
|
|
8
|
-
const { hooks } = VxeUI
|
|
9
|
-
|
|
10
|
-
hooks.add('tableKeyboardModule', {
|
|
11
|
-
setupTable ($xeTable) {
|
|
12
|
-
const { props, reactData, internalData } = $xeTable
|
|
13
|
-
const { refElem, refTableBody } = $xeTable.getRefMaps()
|
|
14
|
-
const { computeEditOpts, computeCheckboxOpts, computeMouseOpts, computeTreeOpts, computeRowOpts, computeColumnOpts, computeCellOpts, computeDefaultRowHeight, computeCurrentRowOpts, computeCurrentColumnOpts } = $xeTable.getComputeMaps()
|
|
15
|
-
|
|
16
|
-
function getCheckboxRangeRows (evnt: MouseEvent, params: any, targetTrElem: HTMLElement, trRect: DOMRect, offsetClientTop: number, moveRange: number) {
|
|
17
|
-
const { showOverflow } = props
|
|
18
|
-
const { fullAllDataRowIdData, isResizeCellHeight } = internalData
|
|
19
|
-
const rowOpts = computeRowOpts.value
|
|
20
|
-
const cellOpts = computeCellOpts.value
|
|
21
|
-
const defaultRowHeight = computeDefaultRowHeight.value
|
|
22
|
-
const { row } = params
|
|
23
|
-
let countHeight = 0
|
|
24
|
-
let rangeRows: any[] = []
|
|
25
|
-
let moveSize = 0
|
|
26
|
-
const isDown = moveRange > 0
|
|
27
|
-
const { scrollYLoad } = reactData
|
|
28
|
-
const { afterFullData } = internalData
|
|
29
|
-
if (isDown) {
|
|
30
|
-
moveSize = offsetClientTop + moveRange
|
|
31
|
-
} else {
|
|
32
|
-
moveSize = (trRect.height - offsetClientTop) + Math.abs(moveRange)
|
|
33
|
-
}
|
|
34
|
-
if (scrollYLoad) {
|
|
35
|
-
const _rowIndex = $xeTable.getVTRowIndex(row)
|
|
36
|
-
const isCustomCellHeight = isResizeCellHeight || cellOpts.height || rowOpts.height
|
|
37
|
-
if (!isCustomCellHeight && showOverflow) {
|
|
38
|
-
if (isDown) {
|
|
39
|
-
rangeRows = afterFullData.slice(_rowIndex, _rowIndex + Math.ceil(moveSize / defaultRowHeight))
|
|
40
|
-
} else {
|
|
41
|
-
rangeRows = afterFullData.slice(_rowIndex - Math.floor(moveSize / defaultRowHeight), _rowIndex + 1)
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
if (isDown) {
|
|
45
|
-
for (let i = _rowIndex; i < afterFullData.length; i++) {
|
|
46
|
-
const item = afterFullData[i]
|
|
47
|
-
const rowid = $xeTable.getRowid(item)
|
|
48
|
-
const rowRest = fullAllDataRowIdData[rowid] || {}
|
|
49
|
-
countHeight += rowRest.resizeHeight || cellOpts.height || rowOpts.height || rowRest.height || defaultRowHeight
|
|
50
|
-
rangeRows.push(item)
|
|
51
|
-
if (countHeight > moveSize) {
|
|
52
|
-
return rangeRows
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
for (let len = _rowIndex; len >= 0; len--) {
|
|
57
|
-
const item = afterFullData[len]
|
|
58
|
-
const rowid = $xeTable.getRowid(item)
|
|
59
|
-
const rowRest = fullAllDataRowIdData[rowid] || {}
|
|
60
|
-
countHeight += rowRest.resizeHeight || cellOpts.height || rowOpts.height || rowRest.height || defaultRowHeight
|
|
61
|
-
rangeRows.push(item)
|
|
62
|
-
if (countHeight > moveSize) {
|
|
63
|
-
return rangeRows
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
const siblingProp = isDown ? 'next' : 'previous'
|
|
70
|
-
while (targetTrElem && countHeight < moveSize) {
|
|
71
|
-
const rowNodeRest = $xeTable.getRowNode(targetTrElem)
|
|
72
|
-
if (rowNodeRest) {
|
|
73
|
-
rangeRows.push(rowNodeRest.item)
|
|
74
|
-
countHeight += targetTrElem.offsetHeight
|
|
75
|
-
targetTrElem = targetTrElem[`${siblingProp}ElementSibling`] as HTMLElement
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return rangeRows
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const handleCheckboxRangeEvent = (evnt: any, params: any) => {
|
|
83
|
-
const { elemStore } = internalData
|
|
84
|
-
const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
|
|
85
|
-
const leftScrollElem = getRefElem(elemStore['left-body-scroll'])
|
|
86
|
-
const rightScrollElem = getRefElem(elemStore['right-body-scroll'])
|
|
87
|
-
const { column, cell } = params
|
|
88
|
-
if (column.type === 'checkbox') {
|
|
89
|
-
let bodyWrapperElem = bodyScrollElem as HTMLElement
|
|
90
|
-
if (leftScrollElem && column.fixed === 'left') {
|
|
91
|
-
bodyWrapperElem = leftScrollElem
|
|
92
|
-
} else if (rightScrollElem && column.fixed === 'right') {
|
|
93
|
-
bodyWrapperElem = rightScrollElem
|
|
94
|
-
}
|
|
95
|
-
if (!bodyWrapperElem) {
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
const bodyRect = bodyWrapperElem.getBoundingClientRect()
|
|
99
|
-
const el = refElem.value
|
|
100
|
-
const disX = evnt.clientX
|
|
101
|
-
const disY = evnt.clientY
|
|
102
|
-
const checkboxRangeElem = bodyWrapperElem.querySelector('.vxe-table--checkbox-range') as HTMLElement
|
|
103
|
-
const trElem = cell.parentElement as HTMLElement
|
|
104
|
-
const selectRecords = $xeTable.getCheckboxRecords()
|
|
105
|
-
let lastRangeRows: any[] = []
|
|
106
|
-
const marginSize = 1
|
|
107
|
-
const startTop = evnt.clientY - bodyRect.y + bodyWrapperElem.scrollTop
|
|
108
|
-
const startLeft = evnt.clientX - bodyRect.x + bodyWrapperElem.scrollLeft
|
|
109
|
-
const startScrollTop = bodyWrapperElem.scrollTop
|
|
110
|
-
const rowHeight = trElem.offsetHeight
|
|
111
|
-
const trRect = trElem.getBoundingClientRect()
|
|
112
|
-
const offsetClientTop = disY - trRect.y
|
|
113
|
-
let mouseScrollTimeout: any = null
|
|
114
|
-
let isMouseScrollDown: any = false
|
|
115
|
-
let mouseScrollSpaceSize = 1
|
|
116
|
-
const triggerEvent = (type: 'change' | 'start' | 'end', evnt: MouseEvent) => {
|
|
117
|
-
$xeTable.dispatchEvent(`checkbox-range-${type}` as 'checkbox-range-change' | 'checkbox-range-start' | 'checkbox-range-end', {
|
|
118
|
-
records: () => $xeTable.getCheckboxRecords(),
|
|
119
|
-
reserves: () => $xeTable.getCheckboxReserveRecords()
|
|
120
|
-
}, evnt)
|
|
121
|
-
}
|
|
122
|
-
const handleChecked = (evnt: MouseEvent) => {
|
|
123
|
-
const { clientX, clientY } = evnt
|
|
124
|
-
const offsetLeft = clientX - disX
|
|
125
|
-
const offsetTop = clientY - disY + (bodyWrapperElem.scrollTop - startScrollTop)
|
|
126
|
-
let rangeHeight = Math.abs(offsetTop)
|
|
127
|
-
let rangeWidth = Math.abs(offsetLeft)
|
|
128
|
-
let rangeTop = startTop
|
|
129
|
-
let rangeLeft = startLeft
|
|
130
|
-
|
|
131
|
-
if (offsetTop < marginSize) {
|
|
132
|
-
// 向上
|
|
133
|
-
rangeTop += offsetTop
|
|
134
|
-
if (rangeTop < marginSize) {
|
|
135
|
-
rangeTop = marginSize
|
|
136
|
-
rangeHeight = startTop
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
// 向下
|
|
140
|
-
rangeHeight = Math.min(rangeHeight, bodyWrapperElem.scrollHeight - startTop - marginSize)
|
|
141
|
-
}
|
|
142
|
-
if (offsetLeft < marginSize) {
|
|
143
|
-
// 向左
|
|
144
|
-
rangeLeft += offsetLeft
|
|
145
|
-
if (rangeWidth > startLeft) {
|
|
146
|
-
rangeLeft = marginSize
|
|
147
|
-
rangeWidth = startLeft
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
// 向右
|
|
151
|
-
rangeWidth = Math.min(rangeWidth, bodyWrapperElem.clientWidth - startLeft - marginSize)
|
|
152
|
-
}
|
|
153
|
-
checkboxRangeElem.style.height = `${rangeHeight}px`
|
|
154
|
-
checkboxRangeElem.style.width = `${rangeWidth}px`
|
|
155
|
-
checkboxRangeElem.style.left = `${rangeLeft}px`
|
|
156
|
-
checkboxRangeElem.style.top = `${rangeTop}px`
|
|
157
|
-
checkboxRangeElem.style.display = 'block'
|
|
158
|
-
const rangeRows = getCheckboxRangeRows(evnt, params, trElem, trRect, offsetClientTop, offsetTop < marginSize ? -rangeHeight : rangeHeight)
|
|
159
|
-
// 至少滑动 10px 才能有效匹配
|
|
160
|
-
if (rangeHeight > 10 && rangeRows.length !== lastRangeRows.length) {
|
|
161
|
-
const isControlKey = hasControlKey(evnt)
|
|
162
|
-
lastRangeRows = rangeRows
|
|
163
|
-
if (isControlKey) {
|
|
164
|
-
rangeRows.forEach((row: any) => {
|
|
165
|
-
$xeTable.handleBatchSelectRows([row], selectRecords.indexOf(row) === -1)
|
|
166
|
-
})
|
|
167
|
-
} else {
|
|
168
|
-
$xeTable.setAllCheckboxRow(false)
|
|
169
|
-
$xeTable.handleCheckedCheckboxRow(rangeRows, true, false)
|
|
170
|
-
}
|
|
171
|
-
triggerEvent('change', evnt)
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
// 停止鼠标滚动
|
|
175
|
-
const stopMouseScroll = () => {
|
|
176
|
-
clearTimeout(mouseScrollTimeout)
|
|
177
|
-
mouseScrollTimeout = null
|
|
178
|
-
}
|
|
179
|
-
// 开始鼠标滚动
|
|
180
|
-
const startMouseScroll = (evnt: MouseEvent) => {
|
|
181
|
-
stopMouseScroll()
|
|
182
|
-
mouseScrollTimeout = setTimeout(() => {
|
|
183
|
-
if (mouseScrollTimeout) {
|
|
184
|
-
const { scrollLeft, scrollTop, clientHeight, scrollHeight } = bodyWrapperElem
|
|
185
|
-
const topSize = Math.ceil(mouseScrollSpaceSize * 50 / rowHeight)
|
|
186
|
-
if (isMouseScrollDown) {
|
|
187
|
-
if (scrollTop + clientHeight < scrollHeight) {
|
|
188
|
-
$xeTable.scrollTo(scrollLeft, scrollTop + topSize)
|
|
189
|
-
startMouseScroll(evnt)
|
|
190
|
-
handleChecked(evnt)
|
|
191
|
-
} else {
|
|
192
|
-
stopMouseScroll()
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
if (scrollTop) {
|
|
196
|
-
$xeTable.scrollTo(scrollLeft, scrollTop - topSize)
|
|
197
|
-
startMouseScroll(evnt)
|
|
198
|
-
handleChecked(evnt)
|
|
199
|
-
} else {
|
|
200
|
-
stopMouseScroll()
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}, 50)
|
|
205
|
-
}
|
|
206
|
-
addClass(el, 'drag--range')
|
|
207
|
-
document.onmousemove = evnt => {
|
|
208
|
-
evnt.preventDefault()
|
|
209
|
-
evnt.stopPropagation()
|
|
210
|
-
const { clientY } = evnt
|
|
211
|
-
const { boundingTop } = getAbsolutePos(bodyWrapperElem)
|
|
212
|
-
// 如果超过可视区,触发滚动
|
|
213
|
-
if (clientY < boundingTop) {
|
|
214
|
-
isMouseScrollDown = false
|
|
215
|
-
mouseScrollSpaceSize = boundingTop - clientY
|
|
216
|
-
if (!mouseScrollTimeout) {
|
|
217
|
-
startMouseScroll(evnt)
|
|
218
|
-
}
|
|
219
|
-
} else if (clientY > boundingTop + bodyWrapperElem.clientHeight) {
|
|
220
|
-
isMouseScrollDown = true
|
|
221
|
-
mouseScrollSpaceSize = clientY - boundingTop - bodyWrapperElem.clientHeight
|
|
222
|
-
if (!mouseScrollTimeout) {
|
|
223
|
-
startMouseScroll(evnt)
|
|
224
|
-
}
|
|
225
|
-
} else if (mouseScrollTimeout) {
|
|
226
|
-
stopMouseScroll()
|
|
227
|
-
}
|
|
228
|
-
handleChecked(evnt)
|
|
229
|
-
}
|
|
230
|
-
document.onmouseup = (evnt) => {
|
|
231
|
-
stopMouseScroll()
|
|
232
|
-
removeClass(el, 'drag--range')
|
|
233
|
-
checkboxRangeElem.removeAttribute('style')
|
|
234
|
-
document.onmousemove = null
|
|
235
|
-
document.onmouseup = null
|
|
236
|
-
triggerEvent('end', evnt)
|
|
237
|
-
}
|
|
238
|
-
triggerEvent('start', evnt)
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const handleCellMousedownEvent = (evnt: any, params: any) => {
|
|
243
|
-
const { editConfig, checkboxConfig, mouseConfig } = props
|
|
244
|
-
const checkboxOpts = computeCheckboxOpts.value
|
|
245
|
-
const mouseOpts = computeMouseOpts.value
|
|
246
|
-
const editOpts = computeEditOpts.value
|
|
247
|
-
if (mouseConfig && mouseOpts.area && $xeTable.triggerClAreaModnEvent) {
|
|
248
|
-
return $xeTable.triggerClAreaModnEvent(evnt, params)
|
|
249
|
-
} else {
|
|
250
|
-
if (checkboxConfig && checkboxOpts.range) {
|
|
251
|
-
handleCheckboxRangeEvent(evnt, params)
|
|
252
|
-
}
|
|
253
|
-
if (mouseConfig && mouseOpts.selected) {
|
|
254
|
-
if (!editConfig || editOpts.mode === 'cell') {
|
|
255
|
-
$xeTable.handleSelected(params, evnt)
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const handleMoveSelected = (evnt: any, args: any, isLeftArrow: boolean, isUpArrow: boolean, isRightArrow: boolean, isDwArrow: boolean) => {
|
|
262
|
-
const { afterFullData, visibleColumn } = internalData
|
|
263
|
-
const params = Object.assign({}, args)
|
|
264
|
-
const { row, column } = params
|
|
265
|
-
const _rowIndex = $xeTable.getVTRowIndex(row)
|
|
266
|
-
const _columnIndex = $xeTable.getVTColumnIndex(column)
|
|
267
|
-
const tableBody = refTableBody.value
|
|
268
|
-
const tableBodyElem = tableBody ? tableBody.$el as HTMLDivElement : null
|
|
269
|
-
const tableWidth = tableBodyElem ? tableBodyElem.clientWidth : 0
|
|
270
|
-
let colAlign = isLeftArrow || isRightArrow || (column.renderWidth < tableWidth)
|
|
271
|
-
if ((isLeftArrow && _columnIndex >= 0) || (isRightArrow && _columnIndex <= visibleColumn.length - 1)) {
|
|
272
|
-
colAlign = false
|
|
273
|
-
} else {
|
|
274
|
-
evnt.preventDefault()
|
|
275
|
-
}
|
|
276
|
-
if (isUpArrow && _rowIndex > 0) {
|
|
277
|
-
// 移动到上一行
|
|
278
|
-
params.rowIndex = _rowIndex - 1
|
|
279
|
-
params.row = afterFullData[params.rowIndex]
|
|
280
|
-
} else if (isDwArrow && _rowIndex < afterFullData.length - 1) {
|
|
281
|
-
// 移动到下一行
|
|
282
|
-
params.rowIndex = _rowIndex + 1
|
|
283
|
-
params.row = afterFullData[params.rowIndex]
|
|
284
|
-
} else if (isLeftArrow && _columnIndex) {
|
|
285
|
-
// 移动到左侧单元格
|
|
286
|
-
params.columnIndex = _columnIndex - 1
|
|
287
|
-
params.column = visibleColumn[params.columnIndex]
|
|
288
|
-
} else if (isRightArrow && _columnIndex < visibleColumn.length - 1) {
|
|
289
|
-
// 移动到右侧单元格
|
|
290
|
-
params.columnIndex = _columnIndex + 1
|
|
291
|
-
params.column = visibleColumn[params.columnIndex]
|
|
292
|
-
}
|
|
293
|
-
$xeTable.scrollToRow(params.row, params.column, {
|
|
294
|
-
colAlign
|
|
295
|
-
}).then(() => {
|
|
296
|
-
params.cell = $xeTable.getCellElement(params.row, params.column)
|
|
297
|
-
$xeTable.handleSelected(params, evnt)
|
|
298
|
-
})
|
|
299
|
-
return params
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const keyboardMethods: TableKeyboardPrivateMethods = {
|
|
303
|
-
// 处理 Tab 键移动
|
|
304
|
-
moveTabSelected (args, isLeft, evnt) {
|
|
305
|
-
const { editConfig } = props
|
|
306
|
-
const { afterFullData, visibleColumn } = internalData
|
|
307
|
-
const editOpts = computeEditOpts.value
|
|
308
|
-
const rowOpts = computeRowOpts.value
|
|
309
|
-
const currentRowOpts = computeCurrentRowOpts.value
|
|
310
|
-
const columnOpts = computeColumnOpts.value
|
|
311
|
-
const currentColumnOpts = computeCurrentColumnOpts.value
|
|
312
|
-
let targetRow: any
|
|
313
|
-
let targetRowIndex: any
|
|
314
|
-
let targetColumnIndex: any
|
|
315
|
-
const params = Object.assign({}, args)
|
|
316
|
-
const _rowIndex = $xeTable.getVTRowIndex(params.row)
|
|
317
|
-
const _columnIndex = $xeTable.getVTColumnIndex(params.column)
|
|
318
|
-
evnt.preventDefault()
|
|
319
|
-
if (isLeft) {
|
|
320
|
-
// 向左
|
|
321
|
-
if (_columnIndex <= 0) {
|
|
322
|
-
// 如果已经是第一列,则移动到上一行
|
|
323
|
-
if (_rowIndex > 0) {
|
|
324
|
-
targetRowIndex = _rowIndex - 1
|
|
325
|
-
targetRow = afterFullData[targetRowIndex]
|
|
326
|
-
targetColumnIndex = visibleColumn.length - 1
|
|
327
|
-
}
|
|
328
|
-
} else {
|
|
329
|
-
targetColumnIndex = _columnIndex - 1
|
|
330
|
-
}
|
|
331
|
-
} else {
|
|
332
|
-
if (_columnIndex >= visibleColumn.length - 1) {
|
|
333
|
-
// 如果已经是第一列,则移动到上一行
|
|
334
|
-
if (_rowIndex < afterFullData.length - 1) {
|
|
335
|
-
targetRowIndex = _rowIndex + 1
|
|
336
|
-
targetRow = afterFullData[targetRowIndex]
|
|
337
|
-
targetColumnIndex = 0
|
|
338
|
-
}
|
|
339
|
-
} else {
|
|
340
|
-
targetColumnIndex = _columnIndex + 1
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
const targetColumn = visibleColumn[targetColumnIndex]
|
|
344
|
-
if (targetColumn) {
|
|
345
|
-
if (targetRow) {
|
|
346
|
-
params.rowIndex = targetRowIndex
|
|
347
|
-
params.row = targetRow
|
|
348
|
-
} else {
|
|
349
|
-
params.rowIndex = _rowIndex
|
|
350
|
-
}
|
|
351
|
-
params.columnIndex = targetColumnIndex
|
|
352
|
-
params.column = targetColumn
|
|
353
|
-
params.cell = $xeTable.getCellElement(params.row, params.column)
|
|
354
|
-
if (rowOpts.isCurrent && currentRowOpts.isFollowSelected) {
|
|
355
|
-
$xeTable.triggerCurrentRowEvent(evnt, params)
|
|
356
|
-
}
|
|
357
|
-
if (columnOpts.isCurrent && currentColumnOpts.isFollowSelected) {
|
|
358
|
-
$xeTable.triggerCurrentColumnEvent(evnt, params)
|
|
359
|
-
}
|
|
360
|
-
if (editConfig) {
|
|
361
|
-
if (editOpts.trigger === 'click' || editOpts.trigger === 'dblclick') {
|
|
362
|
-
if (editOpts.mode === 'row') {
|
|
363
|
-
$xeTable.handleEdit(params, evnt)
|
|
364
|
-
} else {
|
|
365
|
-
$xeTable.scrollToRow(params.row, params.column).then(() => {
|
|
366
|
-
$xeTable.handleSelected(params, evnt)
|
|
367
|
-
})
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
} else {
|
|
371
|
-
$xeTable.scrollToRow(params.row, params.column).then(() => {
|
|
372
|
-
$xeTable.handleSelected(params, evnt)
|
|
373
|
-
})
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
// 处理当前行方向键移动
|
|
378
|
-
moveCurrentRow (isUpArrow, isDwArrow, evnt) {
|
|
379
|
-
const { treeConfig } = props
|
|
380
|
-
const { currentRow } = reactData
|
|
381
|
-
const { afterFullData } = internalData
|
|
382
|
-
const treeOpts = computeTreeOpts.value
|
|
383
|
-
const childrenField = treeOpts.children || treeOpts.childrenField
|
|
384
|
-
let targetRow
|
|
385
|
-
if (currentRow) {
|
|
386
|
-
if (treeConfig) {
|
|
387
|
-
const { index, items } = XEUtils.findTree(afterFullData, item => item === currentRow, { children: childrenField })
|
|
388
|
-
if (isUpArrow && index > 0) {
|
|
389
|
-
targetRow = items[index - 1]
|
|
390
|
-
} else if (isDwArrow && index < items.length - 1) {
|
|
391
|
-
targetRow = items[index + 1]
|
|
392
|
-
}
|
|
393
|
-
} else {
|
|
394
|
-
const _rowIndex = $xeTable.getVTRowIndex(currentRow)
|
|
395
|
-
if (isUpArrow && _rowIndex > 0) {
|
|
396
|
-
targetRow = afterFullData[_rowIndex - 1]
|
|
397
|
-
} else if (isDwArrow && _rowIndex < afterFullData.length - 1) {
|
|
398
|
-
targetRow = afterFullData[_rowIndex + 1]
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
} else {
|
|
402
|
-
targetRow = afterFullData[0]
|
|
403
|
-
}
|
|
404
|
-
if (targetRow) {
|
|
405
|
-
evnt.preventDefault()
|
|
406
|
-
const params = {
|
|
407
|
-
$table: $xeTable,
|
|
408
|
-
row: targetRow,
|
|
409
|
-
rowIndex: $xeTable.getRowIndex(targetRow),
|
|
410
|
-
$rowIndex: $xeTable.getVMRowIndex(targetRow)
|
|
411
|
-
}
|
|
412
|
-
$xeTable.scrollToRow(targetRow)
|
|
413
|
-
.then(() => $xeTable.triggerCurrentRowEvent(evnt, params))
|
|
414
|
-
}
|
|
415
|
-
},
|
|
416
|
-
// 处理当前列方向键移动
|
|
417
|
-
moveCurrentColumn (isLeftArrow, isRightArrow, evnt) {
|
|
418
|
-
const { currentColumn } = reactData
|
|
419
|
-
const { visibleColumn } = internalData
|
|
420
|
-
let targetCol: VxeTableDefines.ColumnInfo | null = null
|
|
421
|
-
if (currentColumn) {
|
|
422
|
-
const _columnIndex = $xeTable.getVTColumnIndex(currentColumn)
|
|
423
|
-
if (isLeftArrow && _columnIndex > 0) {
|
|
424
|
-
targetCol = visibleColumn[_columnIndex - 1]
|
|
425
|
-
} else if (isRightArrow && _columnIndex < visibleColumn.length - 1) {
|
|
426
|
-
targetCol = visibleColumn[_columnIndex + 1]
|
|
427
|
-
}
|
|
428
|
-
} else {
|
|
429
|
-
targetCol = visibleColumn[0]
|
|
430
|
-
}
|
|
431
|
-
if (targetCol) {
|
|
432
|
-
evnt.preventDefault()
|
|
433
|
-
const params = {
|
|
434
|
-
$table: $xeTable,
|
|
435
|
-
column: targetCol,
|
|
436
|
-
columnIndex: $xeTable.getColumnIndex(targetCol),
|
|
437
|
-
$columnIndex: $xeTable.getVMColumnIndex(targetCol)
|
|
438
|
-
}
|
|
439
|
-
$xeTable.scrollToColumn(targetCol)
|
|
440
|
-
.then(() => $xeTable.triggerCurrentColumnEvent(evnt, params))
|
|
441
|
-
}
|
|
442
|
-
},
|
|
443
|
-
// 处理可编辑方向键移动
|
|
444
|
-
moveArrowSelected (args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt) {
|
|
445
|
-
const { highlightCurrentRow, highlightCurrentColumn } = props
|
|
446
|
-
const rowOpts = computeRowOpts.value
|
|
447
|
-
const currentRowOpts = computeCurrentRowOpts.value
|
|
448
|
-
const columnOpts = computeColumnOpts.value
|
|
449
|
-
const currentColumnOpts = computeCurrentColumnOpts.value
|
|
450
|
-
const params = handleMoveSelected(evnt, args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow)
|
|
451
|
-
if (rowOpts.isCurrent || highlightCurrentRow) {
|
|
452
|
-
if (currentRowOpts.isFollowSelected) {
|
|
453
|
-
$xeTable.triggerCurrentRowEvent(evnt, params)
|
|
454
|
-
} else {
|
|
455
|
-
// 当前行按键上下移动
|
|
456
|
-
if ((isUpArrow || isDwArrow) && (rowOpts.isCurrent || highlightCurrentRow)) {
|
|
457
|
-
$xeTable.moveCurrentRow(isUpArrow, isDwArrow, evnt)
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
if (columnOpts.isCurrent || highlightCurrentColumn) {
|
|
462
|
-
if (currentColumnOpts.isFollowSelected) {
|
|
463
|
-
$xeTable.triggerCurrentColumnEvent(evnt, params)
|
|
464
|
-
} else {
|
|
465
|
-
// 当前行按键左右移动
|
|
466
|
-
if ((isLeftArrow || isRightArrow) && (columnOpts.isCurrent || highlightCurrentColumn)) {
|
|
467
|
-
$xeTable.moveCurrentColumn(isLeftArrow, isRightArrow, evnt)
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
},
|
|
472
|
-
moveEnterSelected (args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt) {
|
|
473
|
-
const { highlightCurrentRow, highlightCurrentColumn } = props
|
|
474
|
-
const rowOpts = computeRowOpts.value
|
|
475
|
-
const currentRowOpts = computeCurrentRowOpts.value
|
|
476
|
-
const columnOpts = computeColumnOpts.value
|
|
477
|
-
const currentColumnOpts = computeCurrentColumnOpts.value
|
|
478
|
-
const params = handleMoveSelected(evnt, args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow)
|
|
479
|
-
if (((rowOpts.isCurrent || highlightCurrentRow) && currentRowOpts.isFollowSelected)) {
|
|
480
|
-
$xeTable.triggerCurrentRowEvent(evnt, params)
|
|
481
|
-
}
|
|
482
|
-
if ((columnOpts.isCurrent || highlightCurrentColumn) && currentColumnOpts.isFollowSelected) {
|
|
483
|
-
$xeTable.triggerCurrentColumnEvent(evnt, params)
|
|
484
|
-
}
|
|
485
|
-
},
|
|
486
|
-
// 已废弃,待删除
|
|
487
|
-
moveSelected (args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt) {
|
|
488
|
-
handleMoveSelected(evnt, args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow)
|
|
489
|
-
},
|
|
490
|
-
handleCellMousedownEvent
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
return keyboardMethods
|
|
494
|
-
}
|
|
495
|
-
})
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import { VxeUI } from '../../../ui'
|
|
3
|
+
import { getRefElem } from '../../src/util'
|
|
4
|
+
import { getAbsolutePos, addClass, removeClass, hasControlKey } from '../../../ui/src/dom'
|
|
5
|
+
|
|
6
|
+
import type { TableKeyboardPrivateMethods, VxeTableDefines } from '../../../../types'
|
|
7
|
+
|
|
8
|
+
const { hooks } = VxeUI
|
|
9
|
+
|
|
10
|
+
hooks.add('tableKeyboardModule', {
|
|
11
|
+
setupTable ($xeTable) {
|
|
12
|
+
const { props, reactData, internalData } = $xeTable
|
|
13
|
+
const { refElem, refTableBody } = $xeTable.getRefMaps()
|
|
14
|
+
const { computeEditOpts, computeCheckboxOpts, computeMouseOpts, computeTreeOpts, computeRowOpts, computeColumnOpts, computeCellOpts, computeDefaultRowHeight, computeCurrentRowOpts, computeCurrentColumnOpts } = $xeTable.getComputeMaps()
|
|
15
|
+
|
|
16
|
+
function getCheckboxRangeRows (evnt: MouseEvent, params: any, targetTrElem: HTMLElement, trRect: DOMRect, offsetClientTop: number, moveRange: number) {
|
|
17
|
+
const { showOverflow } = props
|
|
18
|
+
const { fullAllDataRowIdData, isResizeCellHeight } = internalData
|
|
19
|
+
const rowOpts = computeRowOpts.value
|
|
20
|
+
const cellOpts = computeCellOpts.value
|
|
21
|
+
const defaultRowHeight = computeDefaultRowHeight.value
|
|
22
|
+
const { row } = params
|
|
23
|
+
let countHeight = 0
|
|
24
|
+
let rangeRows: any[] = []
|
|
25
|
+
let moveSize = 0
|
|
26
|
+
const isDown = moveRange > 0
|
|
27
|
+
const { scrollYLoad } = reactData
|
|
28
|
+
const { afterFullData } = internalData
|
|
29
|
+
if (isDown) {
|
|
30
|
+
moveSize = offsetClientTop + moveRange
|
|
31
|
+
} else {
|
|
32
|
+
moveSize = (trRect.height - offsetClientTop) + Math.abs(moveRange)
|
|
33
|
+
}
|
|
34
|
+
if (scrollYLoad) {
|
|
35
|
+
const _rowIndex = $xeTable.getVTRowIndex(row)
|
|
36
|
+
const isCustomCellHeight = isResizeCellHeight || cellOpts.height || rowOpts.height
|
|
37
|
+
if (!isCustomCellHeight && showOverflow) {
|
|
38
|
+
if (isDown) {
|
|
39
|
+
rangeRows = afterFullData.slice(_rowIndex, _rowIndex + Math.ceil(moveSize / defaultRowHeight))
|
|
40
|
+
} else {
|
|
41
|
+
rangeRows = afterFullData.slice(_rowIndex - Math.floor(moveSize / defaultRowHeight), _rowIndex + 1)
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
if (isDown) {
|
|
45
|
+
for (let i = _rowIndex; i < afterFullData.length; i++) {
|
|
46
|
+
const item = afterFullData[i]
|
|
47
|
+
const rowid = $xeTable.getRowid(item)
|
|
48
|
+
const rowRest = fullAllDataRowIdData[rowid] || {}
|
|
49
|
+
countHeight += rowRest.resizeHeight || cellOpts.height || rowOpts.height || rowRest.height || defaultRowHeight
|
|
50
|
+
rangeRows.push(item)
|
|
51
|
+
if (countHeight > moveSize) {
|
|
52
|
+
return rangeRows
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
for (let len = _rowIndex; len >= 0; len--) {
|
|
57
|
+
const item = afterFullData[len]
|
|
58
|
+
const rowid = $xeTable.getRowid(item)
|
|
59
|
+
const rowRest = fullAllDataRowIdData[rowid] || {}
|
|
60
|
+
countHeight += rowRest.resizeHeight || cellOpts.height || rowOpts.height || rowRest.height || defaultRowHeight
|
|
61
|
+
rangeRows.push(item)
|
|
62
|
+
if (countHeight > moveSize) {
|
|
63
|
+
return rangeRows
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
const siblingProp = isDown ? 'next' : 'previous'
|
|
70
|
+
while (targetTrElem && countHeight < moveSize) {
|
|
71
|
+
const rowNodeRest = $xeTable.getRowNode(targetTrElem)
|
|
72
|
+
if (rowNodeRest) {
|
|
73
|
+
rangeRows.push(rowNodeRest.item)
|
|
74
|
+
countHeight += targetTrElem.offsetHeight
|
|
75
|
+
targetTrElem = targetTrElem[`${siblingProp}ElementSibling`] as HTMLElement
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return rangeRows
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const handleCheckboxRangeEvent = (evnt: any, params: any) => {
|
|
83
|
+
const { elemStore } = internalData
|
|
84
|
+
const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
|
|
85
|
+
const leftScrollElem = getRefElem(elemStore['left-body-scroll'])
|
|
86
|
+
const rightScrollElem = getRefElem(elemStore['right-body-scroll'])
|
|
87
|
+
const { column, cell } = params
|
|
88
|
+
if (column.type === 'checkbox') {
|
|
89
|
+
let bodyWrapperElem = bodyScrollElem as HTMLElement
|
|
90
|
+
if (leftScrollElem && column.fixed === 'left') {
|
|
91
|
+
bodyWrapperElem = leftScrollElem
|
|
92
|
+
} else if (rightScrollElem && column.fixed === 'right') {
|
|
93
|
+
bodyWrapperElem = rightScrollElem
|
|
94
|
+
}
|
|
95
|
+
if (!bodyWrapperElem) {
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
const bodyRect = bodyWrapperElem.getBoundingClientRect()
|
|
99
|
+
const el = refElem.value
|
|
100
|
+
const disX = evnt.clientX
|
|
101
|
+
const disY = evnt.clientY
|
|
102
|
+
const checkboxRangeElem = bodyWrapperElem.querySelector('.vxe-table--checkbox-range') as HTMLElement
|
|
103
|
+
const trElem = cell.parentElement as HTMLElement
|
|
104
|
+
const selectRecords = $xeTable.getCheckboxRecords()
|
|
105
|
+
let lastRangeRows: any[] = []
|
|
106
|
+
const marginSize = 1
|
|
107
|
+
const startTop = evnt.clientY - bodyRect.y + bodyWrapperElem.scrollTop
|
|
108
|
+
const startLeft = evnt.clientX - bodyRect.x + bodyWrapperElem.scrollLeft
|
|
109
|
+
const startScrollTop = bodyWrapperElem.scrollTop
|
|
110
|
+
const rowHeight = trElem.offsetHeight
|
|
111
|
+
const trRect = trElem.getBoundingClientRect()
|
|
112
|
+
const offsetClientTop = disY - trRect.y
|
|
113
|
+
let mouseScrollTimeout: any = null
|
|
114
|
+
let isMouseScrollDown: any = false
|
|
115
|
+
let mouseScrollSpaceSize = 1
|
|
116
|
+
const triggerEvent = (type: 'change' | 'start' | 'end', evnt: MouseEvent) => {
|
|
117
|
+
$xeTable.dispatchEvent(`checkbox-range-${type}` as 'checkbox-range-change' | 'checkbox-range-start' | 'checkbox-range-end', {
|
|
118
|
+
records: () => $xeTable.getCheckboxRecords(),
|
|
119
|
+
reserves: () => $xeTable.getCheckboxReserveRecords()
|
|
120
|
+
}, evnt)
|
|
121
|
+
}
|
|
122
|
+
const handleChecked = (evnt: MouseEvent) => {
|
|
123
|
+
const { clientX, clientY } = evnt
|
|
124
|
+
const offsetLeft = clientX - disX
|
|
125
|
+
const offsetTop = clientY - disY + (bodyWrapperElem.scrollTop - startScrollTop)
|
|
126
|
+
let rangeHeight = Math.abs(offsetTop)
|
|
127
|
+
let rangeWidth = Math.abs(offsetLeft)
|
|
128
|
+
let rangeTop = startTop
|
|
129
|
+
let rangeLeft = startLeft
|
|
130
|
+
|
|
131
|
+
if (offsetTop < marginSize) {
|
|
132
|
+
// 向上
|
|
133
|
+
rangeTop += offsetTop
|
|
134
|
+
if (rangeTop < marginSize) {
|
|
135
|
+
rangeTop = marginSize
|
|
136
|
+
rangeHeight = startTop
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
// 向下
|
|
140
|
+
rangeHeight = Math.min(rangeHeight, bodyWrapperElem.scrollHeight - startTop - marginSize)
|
|
141
|
+
}
|
|
142
|
+
if (offsetLeft < marginSize) {
|
|
143
|
+
// 向左
|
|
144
|
+
rangeLeft += offsetLeft
|
|
145
|
+
if (rangeWidth > startLeft) {
|
|
146
|
+
rangeLeft = marginSize
|
|
147
|
+
rangeWidth = startLeft
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
// 向右
|
|
151
|
+
rangeWidth = Math.min(rangeWidth, bodyWrapperElem.clientWidth - startLeft - marginSize)
|
|
152
|
+
}
|
|
153
|
+
checkboxRangeElem.style.height = `${rangeHeight}px`
|
|
154
|
+
checkboxRangeElem.style.width = `${rangeWidth}px`
|
|
155
|
+
checkboxRangeElem.style.left = `${rangeLeft}px`
|
|
156
|
+
checkboxRangeElem.style.top = `${rangeTop}px`
|
|
157
|
+
checkboxRangeElem.style.display = 'block'
|
|
158
|
+
const rangeRows = getCheckboxRangeRows(evnt, params, trElem, trRect, offsetClientTop, offsetTop < marginSize ? -rangeHeight : rangeHeight)
|
|
159
|
+
// 至少滑动 10px 才能有效匹配
|
|
160
|
+
if (rangeHeight > 10 && rangeRows.length !== lastRangeRows.length) {
|
|
161
|
+
const isControlKey = hasControlKey(evnt)
|
|
162
|
+
lastRangeRows = rangeRows
|
|
163
|
+
if (isControlKey) {
|
|
164
|
+
rangeRows.forEach((row: any) => {
|
|
165
|
+
$xeTable.handleBatchSelectRows([row], selectRecords.indexOf(row) === -1)
|
|
166
|
+
})
|
|
167
|
+
} else {
|
|
168
|
+
$xeTable.setAllCheckboxRow(false)
|
|
169
|
+
$xeTable.handleCheckedCheckboxRow(rangeRows, true, false)
|
|
170
|
+
}
|
|
171
|
+
triggerEvent('change', evnt)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// 停止鼠标滚动
|
|
175
|
+
const stopMouseScroll = () => {
|
|
176
|
+
clearTimeout(mouseScrollTimeout)
|
|
177
|
+
mouseScrollTimeout = null
|
|
178
|
+
}
|
|
179
|
+
// 开始鼠标滚动
|
|
180
|
+
const startMouseScroll = (evnt: MouseEvent) => {
|
|
181
|
+
stopMouseScroll()
|
|
182
|
+
mouseScrollTimeout = setTimeout(() => {
|
|
183
|
+
if (mouseScrollTimeout) {
|
|
184
|
+
const { scrollLeft, scrollTop, clientHeight, scrollHeight } = bodyWrapperElem
|
|
185
|
+
const topSize = Math.ceil(mouseScrollSpaceSize * 50 / rowHeight)
|
|
186
|
+
if (isMouseScrollDown) {
|
|
187
|
+
if (scrollTop + clientHeight < scrollHeight) {
|
|
188
|
+
$xeTable.scrollTo(scrollLeft, scrollTop + topSize)
|
|
189
|
+
startMouseScroll(evnt)
|
|
190
|
+
handleChecked(evnt)
|
|
191
|
+
} else {
|
|
192
|
+
stopMouseScroll()
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
if (scrollTop) {
|
|
196
|
+
$xeTable.scrollTo(scrollLeft, scrollTop - topSize)
|
|
197
|
+
startMouseScroll(evnt)
|
|
198
|
+
handleChecked(evnt)
|
|
199
|
+
} else {
|
|
200
|
+
stopMouseScroll()
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}, 50)
|
|
205
|
+
}
|
|
206
|
+
addClass(el, 'drag--range')
|
|
207
|
+
document.onmousemove = evnt => {
|
|
208
|
+
evnt.preventDefault()
|
|
209
|
+
evnt.stopPropagation()
|
|
210
|
+
const { clientY } = evnt
|
|
211
|
+
const { boundingTop } = getAbsolutePos(bodyWrapperElem)
|
|
212
|
+
// 如果超过可视区,触发滚动
|
|
213
|
+
if (clientY < boundingTop) {
|
|
214
|
+
isMouseScrollDown = false
|
|
215
|
+
mouseScrollSpaceSize = boundingTop - clientY
|
|
216
|
+
if (!mouseScrollTimeout) {
|
|
217
|
+
startMouseScroll(evnt)
|
|
218
|
+
}
|
|
219
|
+
} else if (clientY > boundingTop + bodyWrapperElem.clientHeight) {
|
|
220
|
+
isMouseScrollDown = true
|
|
221
|
+
mouseScrollSpaceSize = clientY - boundingTop - bodyWrapperElem.clientHeight
|
|
222
|
+
if (!mouseScrollTimeout) {
|
|
223
|
+
startMouseScroll(evnt)
|
|
224
|
+
}
|
|
225
|
+
} else if (mouseScrollTimeout) {
|
|
226
|
+
stopMouseScroll()
|
|
227
|
+
}
|
|
228
|
+
handleChecked(evnt)
|
|
229
|
+
}
|
|
230
|
+
document.onmouseup = (evnt) => {
|
|
231
|
+
stopMouseScroll()
|
|
232
|
+
removeClass(el, 'drag--range')
|
|
233
|
+
checkboxRangeElem.removeAttribute('style')
|
|
234
|
+
document.onmousemove = null
|
|
235
|
+
document.onmouseup = null
|
|
236
|
+
triggerEvent('end', evnt)
|
|
237
|
+
}
|
|
238
|
+
triggerEvent('start', evnt)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const handleCellMousedownEvent = (evnt: any, params: any) => {
|
|
243
|
+
const { editConfig, checkboxConfig, mouseConfig } = props
|
|
244
|
+
const checkboxOpts = computeCheckboxOpts.value
|
|
245
|
+
const mouseOpts = computeMouseOpts.value
|
|
246
|
+
const editOpts = computeEditOpts.value
|
|
247
|
+
if (mouseConfig && mouseOpts.area && $xeTable.triggerClAreaModnEvent) {
|
|
248
|
+
return $xeTable.triggerClAreaModnEvent(evnt, params)
|
|
249
|
+
} else {
|
|
250
|
+
if (checkboxConfig && checkboxOpts.range) {
|
|
251
|
+
handleCheckboxRangeEvent(evnt, params)
|
|
252
|
+
}
|
|
253
|
+
if (mouseConfig && mouseOpts.selected) {
|
|
254
|
+
if (!editConfig || editOpts.mode === 'cell') {
|
|
255
|
+
$xeTable.handleSelected(params, evnt)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const handleMoveSelected = (evnt: any, args: any, isLeftArrow: boolean, isUpArrow: boolean, isRightArrow: boolean, isDwArrow: boolean) => {
|
|
262
|
+
const { afterFullData, visibleColumn } = internalData
|
|
263
|
+
const params = Object.assign({}, args)
|
|
264
|
+
const { row, column } = params
|
|
265
|
+
const _rowIndex = $xeTable.getVTRowIndex(row)
|
|
266
|
+
const _columnIndex = $xeTable.getVTColumnIndex(column)
|
|
267
|
+
const tableBody = refTableBody.value
|
|
268
|
+
const tableBodyElem = tableBody ? tableBody.$el as HTMLDivElement : null
|
|
269
|
+
const tableWidth = tableBodyElem ? tableBodyElem.clientWidth : 0
|
|
270
|
+
let colAlign = isLeftArrow || isRightArrow || (column.renderWidth < tableWidth)
|
|
271
|
+
if ((isLeftArrow && _columnIndex >= 0) || (isRightArrow && _columnIndex <= visibleColumn.length - 1)) {
|
|
272
|
+
colAlign = false
|
|
273
|
+
} else {
|
|
274
|
+
evnt.preventDefault()
|
|
275
|
+
}
|
|
276
|
+
if (isUpArrow && _rowIndex > 0) {
|
|
277
|
+
// 移动到上一行
|
|
278
|
+
params.rowIndex = _rowIndex - 1
|
|
279
|
+
params.row = afterFullData[params.rowIndex]
|
|
280
|
+
} else if (isDwArrow && _rowIndex < afterFullData.length - 1) {
|
|
281
|
+
// 移动到下一行
|
|
282
|
+
params.rowIndex = _rowIndex + 1
|
|
283
|
+
params.row = afterFullData[params.rowIndex]
|
|
284
|
+
} else if (isLeftArrow && _columnIndex) {
|
|
285
|
+
// 移动到左侧单元格
|
|
286
|
+
params.columnIndex = _columnIndex - 1
|
|
287
|
+
params.column = visibleColumn[params.columnIndex]
|
|
288
|
+
} else if (isRightArrow && _columnIndex < visibleColumn.length - 1) {
|
|
289
|
+
// 移动到右侧单元格
|
|
290
|
+
params.columnIndex = _columnIndex + 1
|
|
291
|
+
params.column = visibleColumn[params.columnIndex]
|
|
292
|
+
}
|
|
293
|
+
$xeTable.scrollToRow(params.row, params.column, {
|
|
294
|
+
colAlign
|
|
295
|
+
}).then(() => {
|
|
296
|
+
params.cell = $xeTable.getCellElement(params.row, params.column)
|
|
297
|
+
$xeTable.handleSelected(params, evnt)
|
|
298
|
+
})
|
|
299
|
+
return params
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const keyboardMethods: TableKeyboardPrivateMethods = {
|
|
303
|
+
// 处理 Tab 键移动
|
|
304
|
+
moveTabSelected (args, isLeft, evnt) {
|
|
305
|
+
const { editConfig } = props
|
|
306
|
+
const { afterFullData, visibleColumn } = internalData
|
|
307
|
+
const editOpts = computeEditOpts.value
|
|
308
|
+
const rowOpts = computeRowOpts.value
|
|
309
|
+
const currentRowOpts = computeCurrentRowOpts.value
|
|
310
|
+
const columnOpts = computeColumnOpts.value
|
|
311
|
+
const currentColumnOpts = computeCurrentColumnOpts.value
|
|
312
|
+
let targetRow: any
|
|
313
|
+
let targetRowIndex: any
|
|
314
|
+
let targetColumnIndex: any
|
|
315
|
+
const params = Object.assign({}, args)
|
|
316
|
+
const _rowIndex = $xeTable.getVTRowIndex(params.row)
|
|
317
|
+
const _columnIndex = $xeTable.getVTColumnIndex(params.column)
|
|
318
|
+
evnt.preventDefault()
|
|
319
|
+
if (isLeft) {
|
|
320
|
+
// 向左
|
|
321
|
+
if (_columnIndex <= 0) {
|
|
322
|
+
// 如果已经是第一列,则移动到上一行
|
|
323
|
+
if (_rowIndex > 0) {
|
|
324
|
+
targetRowIndex = _rowIndex - 1
|
|
325
|
+
targetRow = afterFullData[targetRowIndex]
|
|
326
|
+
targetColumnIndex = visibleColumn.length - 1
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
targetColumnIndex = _columnIndex - 1
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
if (_columnIndex >= visibleColumn.length - 1) {
|
|
333
|
+
// 如果已经是第一列,则移动到上一行
|
|
334
|
+
if (_rowIndex < afterFullData.length - 1) {
|
|
335
|
+
targetRowIndex = _rowIndex + 1
|
|
336
|
+
targetRow = afterFullData[targetRowIndex]
|
|
337
|
+
targetColumnIndex = 0
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
targetColumnIndex = _columnIndex + 1
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const targetColumn = visibleColumn[targetColumnIndex]
|
|
344
|
+
if (targetColumn) {
|
|
345
|
+
if (targetRow) {
|
|
346
|
+
params.rowIndex = targetRowIndex
|
|
347
|
+
params.row = targetRow
|
|
348
|
+
} else {
|
|
349
|
+
params.rowIndex = _rowIndex
|
|
350
|
+
}
|
|
351
|
+
params.columnIndex = targetColumnIndex
|
|
352
|
+
params.column = targetColumn
|
|
353
|
+
params.cell = $xeTable.getCellElement(params.row, params.column)
|
|
354
|
+
if (rowOpts.isCurrent && currentRowOpts.isFollowSelected) {
|
|
355
|
+
$xeTable.triggerCurrentRowEvent(evnt, params)
|
|
356
|
+
}
|
|
357
|
+
if (columnOpts.isCurrent && currentColumnOpts.isFollowSelected) {
|
|
358
|
+
$xeTable.triggerCurrentColumnEvent(evnt, params)
|
|
359
|
+
}
|
|
360
|
+
if (editConfig) {
|
|
361
|
+
if (editOpts.trigger === 'click' || editOpts.trigger === 'dblclick') {
|
|
362
|
+
if (editOpts.mode === 'row') {
|
|
363
|
+
$xeTable.handleEdit(params, evnt)
|
|
364
|
+
} else {
|
|
365
|
+
$xeTable.scrollToRow(params.row, params.column).then(() => {
|
|
366
|
+
$xeTable.handleSelected(params, evnt)
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
} else {
|
|
371
|
+
$xeTable.scrollToRow(params.row, params.column).then(() => {
|
|
372
|
+
$xeTable.handleSelected(params, evnt)
|
|
373
|
+
})
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
// 处理当前行方向键移动
|
|
378
|
+
moveCurrentRow (isUpArrow, isDwArrow, evnt) {
|
|
379
|
+
const { treeConfig } = props
|
|
380
|
+
const { currentRow } = reactData
|
|
381
|
+
const { afterFullData } = internalData
|
|
382
|
+
const treeOpts = computeTreeOpts.value
|
|
383
|
+
const childrenField = treeOpts.children || treeOpts.childrenField
|
|
384
|
+
let targetRow
|
|
385
|
+
if (currentRow) {
|
|
386
|
+
if (treeConfig) {
|
|
387
|
+
const { index, items } = XEUtils.findTree(afterFullData, item => item === currentRow, { children: childrenField })
|
|
388
|
+
if (isUpArrow && index > 0) {
|
|
389
|
+
targetRow = items[index - 1]
|
|
390
|
+
} else if (isDwArrow && index < items.length - 1) {
|
|
391
|
+
targetRow = items[index + 1]
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
const _rowIndex = $xeTable.getVTRowIndex(currentRow)
|
|
395
|
+
if (isUpArrow && _rowIndex > 0) {
|
|
396
|
+
targetRow = afterFullData[_rowIndex - 1]
|
|
397
|
+
} else if (isDwArrow && _rowIndex < afterFullData.length - 1) {
|
|
398
|
+
targetRow = afterFullData[_rowIndex + 1]
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
targetRow = afterFullData[0]
|
|
403
|
+
}
|
|
404
|
+
if (targetRow) {
|
|
405
|
+
evnt.preventDefault()
|
|
406
|
+
const params = {
|
|
407
|
+
$table: $xeTable,
|
|
408
|
+
row: targetRow,
|
|
409
|
+
rowIndex: $xeTable.getRowIndex(targetRow),
|
|
410
|
+
$rowIndex: $xeTable.getVMRowIndex(targetRow)
|
|
411
|
+
}
|
|
412
|
+
$xeTable.scrollToRow(targetRow)
|
|
413
|
+
.then(() => $xeTable.triggerCurrentRowEvent(evnt, params))
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
// 处理当前列方向键移动
|
|
417
|
+
moveCurrentColumn (isLeftArrow, isRightArrow, evnt) {
|
|
418
|
+
const { currentColumn } = reactData
|
|
419
|
+
const { visibleColumn } = internalData
|
|
420
|
+
let targetCol: VxeTableDefines.ColumnInfo | null = null
|
|
421
|
+
if (currentColumn) {
|
|
422
|
+
const _columnIndex = $xeTable.getVTColumnIndex(currentColumn)
|
|
423
|
+
if (isLeftArrow && _columnIndex > 0) {
|
|
424
|
+
targetCol = visibleColumn[_columnIndex - 1]
|
|
425
|
+
} else if (isRightArrow && _columnIndex < visibleColumn.length - 1) {
|
|
426
|
+
targetCol = visibleColumn[_columnIndex + 1]
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
targetCol = visibleColumn[0]
|
|
430
|
+
}
|
|
431
|
+
if (targetCol) {
|
|
432
|
+
evnt.preventDefault()
|
|
433
|
+
const params = {
|
|
434
|
+
$table: $xeTable,
|
|
435
|
+
column: targetCol,
|
|
436
|
+
columnIndex: $xeTable.getColumnIndex(targetCol),
|
|
437
|
+
$columnIndex: $xeTable.getVMColumnIndex(targetCol)
|
|
438
|
+
}
|
|
439
|
+
$xeTable.scrollToColumn(targetCol)
|
|
440
|
+
.then(() => $xeTable.triggerCurrentColumnEvent(evnt, params))
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
// 处理可编辑方向键移动
|
|
444
|
+
moveArrowSelected (args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt) {
|
|
445
|
+
const { highlightCurrentRow, highlightCurrentColumn } = props
|
|
446
|
+
const rowOpts = computeRowOpts.value
|
|
447
|
+
const currentRowOpts = computeCurrentRowOpts.value
|
|
448
|
+
const columnOpts = computeColumnOpts.value
|
|
449
|
+
const currentColumnOpts = computeCurrentColumnOpts.value
|
|
450
|
+
const params = handleMoveSelected(evnt, args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow)
|
|
451
|
+
if (rowOpts.isCurrent || highlightCurrentRow) {
|
|
452
|
+
if (currentRowOpts.isFollowSelected) {
|
|
453
|
+
$xeTable.triggerCurrentRowEvent(evnt, params)
|
|
454
|
+
} else {
|
|
455
|
+
// 当前行按键上下移动
|
|
456
|
+
if ((isUpArrow || isDwArrow) && (rowOpts.isCurrent || highlightCurrentRow)) {
|
|
457
|
+
$xeTable.moveCurrentRow(isUpArrow, isDwArrow, evnt)
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (columnOpts.isCurrent || highlightCurrentColumn) {
|
|
462
|
+
if (currentColumnOpts.isFollowSelected) {
|
|
463
|
+
$xeTable.triggerCurrentColumnEvent(evnt, params)
|
|
464
|
+
} else {
|
|
465
|
+
// 当前行按键左右移动
|
|
466
|
+
if ((isLeftArrow || isRightArrow) && (columnOpts.isCurrent || highlightCurrentColumn)) {
|
|
467
|
+
$xeTable.moveCurrentColumn(isLeftArrow, isRightArrow, evnt)
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
moveEnterSelected (args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt) {
|
|
473
|
+
const { highlightCurrentRow, highlightCurrentColumn } = props
|
|
474
|
+
const rowOpts = computeRowOpts.value
|
|
475
|
+
const currentRowOpts = computeCurrentRowOpts.value
|
|
476
|
+
const columnOpts = computeColumnOpts.value
|
|
477
|
+
const currentColumnOpts = computeCurrentColumnOpts.value
|
|
478
|
+
const params = handleMoveSelected(evnt, args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow)
|
|
479
|
+
if (((rowOpts.isCurrent || highlightCurrentRow) && currentRowOpts.isFollowSelected)) {
|
|
480
|
+
$xeTable.triggerCurrentRowEvent(evnt, params)
|
|
481
|
+
}
|
|
482
|
+
if ((columnOpts.isCurrent || highlightCurrentColumn) && currentColumnOpts.isFollowSelected) {
|
|
483
|
+
$xeTable.triggerCurrentColumnEvent(evnt, params)
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
// 已废弃,待删除
|
|
487
|
+
moveSelected (args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt) {
|
|
488
|
+
handleMoveSelected(evnt, args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow)
|
|
489
|
+
},
|
|
490
|
+
handleCellMousedownEvent
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return keyboardMethods
|
|
494
|
+
}
|
|
495
|
+
})
|