vxe-table 3.18.0-beta.8 → 3.18.0

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.
@@ -130,6 +130,167 @@ function handleMoveSelected ($xeTable: VxeTableConstructor & VxeTablePrivateMeth
130
130
  return params
131
131
  }
132
132
 
133
+ function handleCheckboxRangeEvent ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, evnt: any, params: any) {
134
+ const internalData = $xeTable as unknown as TableInternalData
135
+
136
+ const { elemStore } = internalData
137
+ const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
138
+ const leftScrollElem = getRefElem(elemStore['left-body-scroll'])
139
+ const rightScrollElem = getRefElem(elemStore['right-body-scroll'])
140
+ const { column, cell } = params
141
+ if (column.type === 'checkbox') {
142
+ let bodyWrapperElem = bodyScrollElem as HTMLElement
143
+ if (leftScrollElem && column.fixed === 'left') {
144
+ bodyWrapperElem = leftScrollElem
145
+ } else if (rightScrollElem && column.fixed === 'right') {
146
+ bodyWrapperElem = rightScrollElem
147
+ }
148
+ if (!bodyWrapperElem) {
149
+ return
150
+ }
151
+ const el = $xeTable.$refs.refElem as HTMLDivElement
152
+ const disX = evnt.clientX
153
+ const disY = evnt.clientY
154
+ const checkboxRangeElem = bodyWrapperElem.querySelector('.vxe-table--checkbox-range') as HTMLElement
155
+ const trElem = cell.parentNode
156
+ const selectRecords = $xeTable.getCheckboxRecords()
157
+ let lastRangeRows = []
158
+ const marginSize = 1
159
+ const offsetRest = getTargetOffset(evnt.target, bodyWrapperElem)
160
+ const startTop = offsetRest.offsetTop + evnt.offsetY
161
+ const startLeft = offsetRest.offsetLeft + evnt.offsetX
162
+ const startScrollTop = bodyWrapperElem.scrollTop
163
+ const rowHeight = trElem.offsetHeight
164
+ const trRect = trElem.getBoundingClientRect()
165
+ const offsetClientTop = disY - trRect.y
166
+ let mouseScrollTimeout: any = null
167
+ let isMouseScrollDown: any = false
168
+ let mouseScrollSpaceSize = 1
169
+ const triggerEvent = (type: any, evnt: any) => {
170
+ $xeTable.dispatchEvent(`checkbox-range-${type}` as 'checkbox-range-change' | 'checkbox-range-start' | 'checkbox-range-end', {
171
+ records: () => $xeTable.getCheckboxRecords(),
172
+ reserves: () => $xeTable.getCheckboxReserveRecords()
173
+ }, evnt)
174
+ }
175
+ const handleChecked = (evnt: any) => {
176
+ const { clientX, clientY } = evnt
177
+ const offsetLeft = clientX - disX
178
+ const offsetTop = clientY - disY + (bodyWrapperElem.scrollTop - startScrollTop)
179
+ let rangeHeight = Math.abs(offsetTop)
180
+ let rangeWidth = Math.abs(offsetLeft)
181
+ let rangeTop = startTop
182
+ let rangeLeft = startLeft
183
+ if (offsetTop < marginSize) {
184
+ // 向上
185
+ rangeTop += offsetTop
186
+ if (rangeTop < marginSize) {
187
+ rangeTop = marginSize
188
+ rangeHeight = startTop
189
+ }
190
+ } else {
191
+ // 向下
192
+ rangeHeight = Math.min(rangeHeight, bodyWrapperElem.scrollHeight - startTop - marginSize)
193
+ }
194
+ if (offsetLeft < marginSize) {
195
+ // 向左
196
+ rangeLeft += offsetLeft
197
+ if (rangeWidth > startLeft) {
198
+ rangeLeft = marginSize
199
+ rangeWidth = startLeft
200
+ }
201
+ } else {
202
+ // 向右
203
+ rangeWidth = Math.min(rangeWidth, bodyWrapperElem.clientWidth - startLeft - marginSize)
204
+ }
205
+ checkboxRangeElem.style.height = `${rangeHeight}px`
206
+ checkboxRangeElem.style.width = `${rangeWidth}px`
207
+ checkboxRangeElem.style.left = `${rangeLeft}px`
208
+ checkboxRangeElem.style.top = `${rangeTop}px`
209
+ checkboxRangeElem.style.display = 'block'
210
+ const rangeRows = getCheckboxRangeRows($xeTable, evnt, params, trElem, trRect, offsetClientTop, offsetTop < marginSize ? -rangeHeight : rangeHeight)
211
+ // 至少滑动 10px 才能有效匹配
212
+ if (rangeHeight > 10 && rangeRows.length !== lastRangeRows.length) {
213
+ const isControlKey = hasControlKey(evnt)
214
+ lastRangeRows = rangeRows
215
+ if (isControlKey) {
216
+ rangeRows.forEach((row: any) => {
217
+ $xeTable.handleBatchSelectRows([row], selectRecords.indexOf(row) === -1)
218
+ })
219
+ } else {
220
+ $xeTable.setAllCheckboxRow(false)
221
+ $xeTable.handleCheckedCheckboxRow(rangeRows, true, false)
222
+ }
223
+ triggerEvent('change', evnt)
224
+ }
225
+ }
226
+ // 停止鼠标滚动
227
+ const stopMouseScroll = () => {
228
+ clearTimeout(mouseScrollTimeout)
229
+ mouseScrollTimeout = null
230
+ }
231
+ // 开始鼠标滚动
232
+ const startMouseScroll = (evnt: any) => {
233
+ stopMouseScroll()
234
+ mouseScrollTimeout = setTimeout(() => {
235
+ if (mouseScrollTimeout) {
236
+ const { scrollLeft, scrollTop, clientHeight, scrollHeight } = bodyWrapperElem
237
+ const topSize = Math.ceil(mouseScrollSpaceSize * 50 / rowHeight)
238
+ if (isMouseScrollDown) {
239
+ if (scrollTop + clientHeight < scrollHeight) {
240
+ $xeTable.scrollTo(scrollLeft, scrollTop + topSize)
241
+ startMouseScroll(evnt)
242
+ handleChecked(evnt)
243
+ } else {
244
+ stopMouseScroll()
245
+ }
246
+ } else {
247
+ if (scrollTop) {
248
+ $xeTable.scrollTo(scrollLeft, scrollTop - topSize)
249
+ startMouseScroll(evnt)
250
+ handleChecked(evnt)
251
+ } else {
252
+ stopMouseScroll()
253
+ }
254
+ }
255
+ }
256
+ }, 50)
257
+ }
258
+ addClass(el, 'drag--range')
259
+ document.onmousemove = evnt => {
260
+ evnt.preventDefault()
261
+ evnt.stopPropagation()
262
+ const { clientY } = evnt
263
+ const { boundingTop } = getAbsolutePos(bodyWrapperElem)
264
+ // 如果超过可视区,触发滚动
265
+ if (clientY < boundingTop) {
266
+ isMouseScrollDown = false
267
+ mouseScrollSpaceSize = boundingTop - clientY
268
+ if (!mouseScrollTimeout) {
269
+ startMouseScroll(evnt)
270
+ }
271
+ } else if (clientY > boundingTop + bodyWrapperElem.clientHeight) {
272
+ isMouseScrollDown = true
273
+ mouseScrollSpaceSize = clientY - boundingTop - bodyWrapperElem.clientHeight
274
+ if (!mouseScrollTimeout) {
275
+ startMouseScroll(evnt)
276
+ }
277
+ } else if (mouseScrollTimeout) {
278
+ stopMouseScroll()
279
+ }
280
+ handleChecked(evnt)
281
+ }
282
+ document.onmouseup = (evnt) => {
283
+ stopMouseScroll()
284
+ removeClass(el, 'drag--range')
285
+ checkboxRangeElem.removeAttribute('style')
286
+ document.onmousemove = null
287
+ document.onmouseup = null
288
+ triggerEvent('end', evnt)
289
+ }
290
+ triggerEvent('start', evnt)
291
+ }
292
+ }
293
+
133
294
  export default {
134
295
  methods: {
135
296
  // 处理 Tab 键移动
@@ -344,181 +505,24 @@ export default {
344
505
  },
345
506
  handleCellMousedownEvent (evnt: any, params: any) {
346
507
  const $xeTable = this as VxeTableConstructor & VxeTablePrivateMethods
508
+ const props = $xeTable
347
509
 
348
- const { editConfig, editOpts, handleSelected, checkboxConfig, checkboxOpts, mouseConfig, mouseOpts } = this
510
+ const { editConfig, checkboxConfig, mouseConfig } = props
511
+ const checkboxOpts = $xeTable.computeCheckboxOpts
512
+ const mouseOpts = $xeTable.computeMouseOpts
513
+ const editOpts = $xeTable.computeEditOpts
349
514
  if (mouseConfig && mouseOpts.area && $xeTable.triggerCellAreaModnEvent) {
350
515
  return $xeTable.triggerCellAreaModnEvent(evnt, params)
351
516
  } else {
352
517
  if (checkboxConfig && checkboxOpts.range) {
353
- this.handleCheckboxRangeEvent(evnt, params)
518
+ handleCheckboxRangeEvent($xeTable, evnt, params)
354
519
  }
355
520
  if (mouseConfig && mouseOpts.selected) {
356
521
  if (!editConfig || editOpts.mode === 'cell') {
357
- handleSelected(params, evnt)
358
- }
359
- }
360
- }
361
- },
362
- handleCheckboxRangeEvent (evnt: any, params: any) {
363
- const $xeTable = this
364
- const internalData = $xeTable
365
-
366
- const { elemStore } = internalData
367
- const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
368
- const leftScrollElem = getRefElem(elemStore['left-body-scroll'])
369
- const rightScrollElem = getRefElem(elemStore['right-body-scroll'])
370
- const { column, cell } = params
371
- if (column.type === 'checkbox') {
372
- let bodyWrapperElem = bodyScrollElem as HTMLElement
373
- if (leftScrollElem && column.fixed === 'left') {
374
- bodyWrapperElem = leftScrollElem
375
- } else if (rightScrollElem && column.fixed === 'right') {
376
- bodyWrapperElem = rightScrollElem
377
- }
378
- if (!bodyWrapperElem) {
379
- return
380
- }
381
- const el = $xeTable.$refs.refElem as HTMLDivElement
382
- const disX = evnt.clientX
383
- const disY = evnt.clientY
384
- const checkboxRangeElem = bodyWrapperElem.querySelector('.vxe-table--checkbox-range') as HTMLElement
385
- const trElem = cell.parentNode
386
- const selectRecords = this.getCheckboxRecords()
387
- let lastRangeRows = []
388
- const marginSize = 1
389
- const offsetRest = getTargetOffset(evnt.target, bodyWrapperElem)
390
- const startTop = offsetRest.offsetTop + evnt.offsetY
391
- const startLeft = offsetRest.offsetLeft + evnt.offsetX
392
- const startScrollTop = bodyWrapperElem.scrollTop
393
- const rowHeight = trElem.offsetHeight
394
- const trRect = trElem.getBoundingClientRect()
395
- const offsetClientTop = disY - trRect.y
396
- let mouseScrollTimeout: any = null
397
- let isMouseScrollDown: any = false
398
- let mouseScrollSpaceSize = 1
399
- const triggerEvent = (type: any, evnt: any) => {
400
- this.emitEvent(`checkbox-range-${type}`, {
401
- records: () => this.getCheckboxRecords(),
402
- reserves: () => this.getCheckboxReserveRecords()
403
- }, evnt)
404
- }
405
- const handleChecked = (evnt: any) => {
406
- const { clientX, clientY } = evnt
407
- const offsetLeft = clientX - disX
408
- const offsetTop = clientY - disY + (bodyWrapperElem.scrollTop - startScrollTop)
409
- let rangeHeight = Math.abs(offsetTop)
410
- let rangeWidth = Math.abs(offsetLeft)
411
- let rangeTop = startTop
412
- let rangeLeft = startLeft
413
- if (offsetTop < marginSize) {
414
- // 向上
415
- rangeTop += offsetTop
416
- if (rangeTop < marginSize) {
417
- rangeTop = marginSize
418
- rangeHeight = startTop
419
- }
420
- } else {
421
- // 向下
422
- rangeHeight = Math.min(rangeHeight, bodyWrapperElem.scrollHeight - startTop - marginSize)
423
- }
424
- if (offsetLeft < marginSize) {
425
- // 向左
426
- rangeLeft += offsetLeft
427
- if (rangeWidth > startLeft) {
428
- rangeLeft = marginSize
429
- rangeWidth = startLeft
430
- }
431
- } else {
432
- // 向右
433
- rangeWidth = Math.min(rangeWidth, bodyWrapperElem.clientWidth - startLeft - marginSize)
434
- }
435
- checkboxRangeElem.style.height = `${rangeHeight}px`
436
- checkboxRangeElem.style.width = `${rangeWidth}px`
437
- checkboxRangeElem.style.left = `${rangeLeft}px`
438
- checkboxRangeElem.style.top = `${rangeTop}px`
439
- checkboxRangeElem.style.display = 'block'
440
- const rangeRows = getCheckboxRangeRows(this, evnt, params, trElem, trRect, offsetClientTop, offsetTop < marginSize ? -rangeHeight : rangeHeight)
441
- // 至少滑动 10px 才能有效匹配
442
- if (rangeHeight > 10 && rangeRows.length !== lastRangeRows.length) {
443
- const isControlKey = hasControlKey(evnt)
444
- lastRangeRows = rangeRows
445
- if (isControlKey) {
446
- rangeRows.forEach((row: any) => {
447
- $xeTable.handleBatchSelectRows([row], selectRecords.indexOf(row) === -1)
448
- })
449
- } else {
450
- this.setAllCheckboxRow(false)
451
- this.handleCheckedCheckboxRow(rangeRows, true, false)
452
- }
453
- triggerEvent('change', evnt)
454
- }
455
- }
456
- // 停止鼠标滚动
457
- const stopMouseScroll = () => {
458
- clearTimeout(mouseScrollTimeout)
459
- mouseScrollTimeout = null
460
- }
461
- // 开始鼠标滚动
462
- const startMouseScroll = (evnt: any) => {
463
- stopMouseScroll()
464
- mouseScrollTimeout = setTimeout(() => {
465
- if (mouseScrollTimeout) {
466
- const { scrollLeft, scrollTop, clientHeight, scrollHeight } = bodyWrapperElem
467
- const topSize = Math.ceil(mouseScrollSpaceSize * 50 / rowHeight)
468
- if (isMouseScrollDown) {
469
- if (scrollTop + clientHeight < scrollHeight) {
470
- this.scrollTo(scrollLeft, scrollTop + topSize)
471
- startMouseScroll(evnt)
472
- handleChecked(evnt)
473
- } else {
474
- stopMouseScroll()
475
- }
476
- } else {
477
- if (scrollTop) {
478
- this.scrollTo(scrollLeft, scrollTop - topSize)
479
- startMouseScroll(evnt)
480
- handleChecked(evnt)
481
- } else {
482
- stopMouseScroll()
483
- }
484
- }
485
- }
486
- }, 50)
487
- }
488
- addClass(el, 'drag--range')
489
- document.onmousemove = evnt => {
490
- evnt.preventDefault()
491
- evnt.stopPropagation()
492
- const { clientY } = evnt
493
- const { boundingTop } = getAbsolutePos(bodyWrapperElem)
494
- // 如果超过可视区,触发滚动
495
- if (clientY < boundingTop) {
496
- isMouseScrollDown = false
497
- mouseScrollSpaceSize = boundingTop - clientY
498
- if (!mouseScrollTimeout) {
499
- startMouseScroll(evnt)
500
- }
501
- } else if (clientY > boundingTop + bodyWrapperElem.clientHeight) {
502
- isMouseScrollDown = true
503
- mouseScrollSpaceSize = clientY - boundingTop - bodyWrapperElem.clientHeight
504
- if (!mouseScrollTimeout) {
505
- startMouseScroll(evnt)
506
- }
507
- } else if (mouseScrollTimeout) {
508
- stopMouseScroll()
522
+ $xeTable.handleSelected(params, evnt)
509
523
  }
510
- handleChecked(evnt)
511
524
  }
512
- document.onmouseup = (evnt) => {
513
- stopMouseScroll()
514
- removeClass(el, 'drag--range')
515
- checkboxRangeElem.removeAttribute('style')
516
- document.onmousemove = null
517
- document.onmouseup = null
518
- triggerEvent('end', evnt)
519
- }
520
- triggerEvent('start', evnt)
521
525
  }
522
526
  }
523
- } as any
527
+ }
524
528
  }
@@ -1906,6 +1906,16 @@ export default {
1906
1906
  this.preventEvent(null, 'activated')
1907
1907
  },
1908
1908
  deactivated () {
1909
+ const $xeTable = this
1910
+ const reactData = $xeTable as unknown as TableReactData
1911
+ const internalData = $xeTable as unknown as TableInternalData
1912
+
1913
+ const { filterStore } = reactData
1914
+ if (filterStore.visible) {
1915
+ $xeTable.clearFilter()
1916
+ }
1917
+ $xeTable.closeTooltip()
1918
+ internalData.isActivated = false
1909
1919
  this.preventEvent(null, 'deactivated')
1910
1920
  },
1911
1921
  beforeDestroy () {