vxe-table 3.10.14 → 3.10.16

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.
@@ -23,25 +23,42 @@ function getTargetOffset (target: any, container: any) {
23
23
  return { offsetTop, offsetLeft }
24
24
  }
25
25
 
26
- function getCheckboxRangeRows (_vm: any, params: any, targetTrElem: any, moveRange: any) {
26
+ function getCheckboxRangeRows ($xeTable: any, evnt: MouseEvent, params: any, targetTrElem: HTMLElement, trRect: DOMRect, offsetClientTop: number, moveRange: number) {
27
+ const reactData = $xeTable
28
+ const internalData = $xeTable
29
+
27
30
  let countHeight = 0
28
- let rangeRows = []
31
+ let rangeRows: any[] = []
32
+ let moveSize = 0
29
33
  const isDown = moveRange > 0
30
- const moveSize = moveRange > 0 ? moveRange : (Math.abs(moveRange) + targetTrElem.offsetHeight)
31
- const { afterFullData, scrollYStore, scrollYLoad } = _vm
34
+ const { scrollYLoad } = reactData
35
+ const { afterFullData, scrollYStore } = internalData
32
36
  if (scrollYLoad) {
33
- const _rowIndex = _vm.getVTRowIndex(params.row)
37
+ if (isDown) {
38
+ moveSize = offsetClientTop + moveRange
39
+ } else {
40
+ moveSize = (trRect.height - offsetClientTop) + Math.abs(moveRange)
41
+ }
42
+ const _rowIndex = $xeTable.getVTRowIndex(params.row)
34
43
  if (isDown) {
35
44
  rangeRows = afterFullData.slice(_rowIndex, _rowIndex + Math.ceil(moveSize / scrollYStore.rowHeight))
36
45
  } else {
37
- rangeRows = afterFullData.slice(_rowIndex - Math.floor(moveSize / scrollYStore.rowHeight) + 1, _rowIndex + 1)
46
+ rangeRows = afterFullData.slice(_rowIndex - Math.floor(moveSize / scrollYStore.rowHeight), _rowIndex + 1)
38
47
  }
39
48
  } else {
49
+ if (isDown) {
50
+ moveSize = evnt.clientY - trRect.y
51
+ } else {
52
+ moveSize = trRect.y - evnt.clientY + trRect.height
53
+ }
40
54
  const siblingProp = isDown ? 'next' : 'previous'
41
55
  while (targetTrElem && countHeight < moveSize) {
42
- rangeRows.push(_vm.getRowNode(targetTrElem).item)
43
- countHeight += targetTrElem.offsetHeight
44
- targetTrElem = targetTrElem[`${siblingProp}ElementSibling`]
56
+ const rowNodeRest = $xeTable.getRowNode(targetTrElem)
57
+ if (rowNodeRest) {
58
+ rangeRows.push(rowNodeRest.item)
59
+ countHeight += targetTrElem.offsetHeight
60
+ targetTrElem = targetTrElem[`${siblingProp}ElementSibling`] as HTMLElement
61
+ }
45
62
  }
46
63
  }
47
64
  return rangeRows
@@ -228,6 +245,8 @@ export default {
228
245
  const startLeft = offsetRest.offsetLeft + evnt.offsetX
229
246
  const startScrollTop = bodyWrapperElem.scrollTop
230
247
  const rowHeight = trElem.offsetHeight
248
+ const trRect = trElem.getBoundingClientRect()
249
+ const offsetClientTop = disY - trRect.y
231
250
  let mouseScrollTimeout: any = null
232
251
  let isMouseScrollDown: any = false
233
252
  let mouseScrollSpaceSize = 1
@@ -269,7 +288,7 @@ export default {
269
288
  checkboxRangeElem.style.left = `${rangeLeft}px`
270
289
  checkboxRangeElem.style.top = `${rangeTop}px`
271
290
  checkboxRangeElem.style.display = 'block'
272
- const rangeRows = getCheckboxRangeRows(this, params, trElem, offsetTop < marginSize ? -rangeHeight : rangeHeight)
291
+ const rangeRows = getCheckboxRangeRows(this, evnt, params, trElem, trRect, offsetClientTop, offsetTop < marginSize ? -rangeHeight : rangeHeight)
273
292
  // 至少滑动 10px 才能有效匹配
274
293
  if (rangeHeight > 10 && rangeRows.length !== lastRangeRows.length) {
275
294
  lastRangeRows = rangeRows
@@ -5,6 +5,8 @@ import { scrollToView } from '../../../ui/src/dom'
5
5
  import { handleFieldOrColumn, getRowid } from '../../src/util'
6
6
  import { warnLog, errLog } from '../../../ui/src/log'
7
7
 
8
+ import type { VxeTableDefines } from '../../../../types'
9
+
8
10
  const { getConfig, validators } = VxeUI
9
11
 
10
12
  /**
@@ -73,7 +75,7 @@ export default {
73
75
  warnLog('vxe.error.notValidators', ['fullValidate(rows, callback)', 'fullValidate(rows)'])
74
76
  }
75
77
  }
76
- return this.beginValidate(rows, cb, true)
78
+ return this.beginValidate(rows, null, cb, true)
77
79
  },
78
80
  /**
79
81
  * 快速校验,如果存在记录不通过的记录,则返回不再继续校验(异步校验除外)
@@ -84,7 +86,27 @@ export default {
84
86
  warnLog('vxe.error.notValidators', ['validate(rows, callback)', 'validate(rows)'])
85
87
  }
86
88
  }
87
- return this.beginValidate(rows, cb)
89
+ return this.beginValidate(rows, null, cb)
90
+ },
91
+ /**
92
+ * 完整校验单元格,和 validateField 的区别就是会给有效数据中的每一行进行校验
93
+ */
94
+ _fullValidateField (rows: any, fieldOrColumn: any) {
95
+ const colList = (XEUtils.isArray(fieldOrColumn) ? fieldOrColumn : (fieldOrColumn ? [fieldOrColumn] : [])).map(column => handleFieldOrColumn(this, column))
96
+ if (colList.length) {
97
+ return this.beginValidate(rows, colList, null, true)
98
+ }
99
+ return this.$nextTick()
100
+ },
101
+ /**
102
+ * 快速校验单元格,如果存在记录不通过的记录,则返回不再继续校验(异步校验除外)
103
+ */
104
+ _validateField (rows: any, fieldOrColumn: any) {
105
+ const colList = (XEUtils.isArray(fieldOrColumn) ? fieldOrColumn : (fieldOrColumn ? [fieldOrColumn] : [])).map(column => handleFieldOrColumn(this, column))
106
+ if (colList.length) {
107
+ return this.beginValidate(rows, colList, null)
108
+ }
109
+ return this.$nextTick()
88
110
  },
89
111
  /**
90
112
  * 聚焦到校验通过的单元格并弹出校验错误提示
@@ -131,7 +153,7 @@ export default {
131
153
  * 如果只传 callback 否则默认验证整个表格数据
132
154
  * 返回 Promise 对象,或者使用回调方式
133
155
  */
134
- beginValidate (rows: any, cb: any, isFull: any) {
156
+ beginValidate (rows: any, cols: VxeTableDefines.ColumnInfo[] | null, cb: any, isFull: any) {
135
157
  const validRest: any = {}
136
158
  const { editRules, afterFullData, visibleColumn, treeConfig, treeOpts } = this
137
159
  const childrenField = treeOpts.children || treeOpts.childrenField
@@ -154,12 +176,13 @@ export default {
154
176
  this.clearValidate()
155
177
  const validErrMaps: any = {}
156
178
  if (editRules) {
157
- const columns = this.getColumns()
179
+ const columns = cols && cols.length ? cols : this.getColumns()
158
180
  const handleVaild = (row: any) => {
159
181
  if (isFull || !this.validRuleErr) {
160
182
  const colVailds: any[] = []
161
183
  columns.forEach((column: any) => {
162
- if ((isFull || !this.validRuleErr) && XEUtils.has(editRules, column.property)) {
184
+ const field = XEUtils.isString(column) ? column : column.field
185
+ if ((isFull || !this.validRuleErr) && XEUtils.has(editRules, field)) {
163
186
  colVailds.push(
164
187
  this.validCellRules('all', row, column)
165
188
  .catch(({ rule, rules }: any) => {
@@ -170,11 +193,11 @@ export default {
170
193
  row,
171
194
  columnIndex: this.getColumnIndex(column),
172
195
  column,
173
- field: column.property,
196
+ field,
174
197
  $table: this
175
198
  }
176
- if (!validRest[column.property]) {
177
- validRest[column.property] = []
199
+ if (!validRest[field]) {
200
+ validRest[field] = []
178
201
  }
179
202
  validErrMaps[`${getRowid(this, row)}:${column.id}`] = {
180
203
  column,
@@ -182,7 +205,7 @@ export default {
182
205
  rule,
183
206
  content: rule.content
184
207
  }
185
- validRest[column.property].push(rest)
208
+ validRest[field].push(rest)
186
209
  if (!isFull) {
187
210
  this.validRuleErr = true
188
211
  return Promise.reject(rest)
@@ -371,7 +394,7 @@ export default {
371
394
  const { validOpts, validErrorMaps } = this
372
395
  const validTip = this.$refs.validTip
373
396
  const rowList = XEUtils.isArray(rows) ? rows : (rows ? [rows] : [])
374
- const colList = (XEUtils.isArray(fieldOrColumn) ? fieldOrColumn : (fieldOrColumn ? [fieldOrColumn] : []).map(column => handleFieldOrColumn(this, column)))
397
+ const colList = (XEUtils.isArray(fieldOrColumn) ? fieldOrColumn : (fieldOrColumn ? [fieldOrColumn] : [])).map(column => handleFieldOrColumn(this, column))
375
398
  let validErrMaps: any = {}
376
399
  if (validTip && validTip.visible) {
377
400
  validTip.close()
@@ -3041,7 +3041,14 @@ const Methods = {
3041
3041
  // 如果点击了当前表格之外
3042
3042
  !getEventTargetNode(evnt, $el).flag
3043
3043
  ) {
3044
- setTimeout(() => this.clearEdit(evnt))
3044
+ setTimeout(() => {
3045
+ this.clearEdit(evnt).then(() => {
3046
+ // 如果存在校验,点击了表格之外则清除
3047
+ if (!this.isActivated && editRules && validOpts.autoClear) {
3048
+ this.validErrorMaps = {}
3049
+ }
3050
+ })
3051
+ })
3045
3052
  }
3046
3053
  })
3047
3054
  }
@@ -6370,7 +6377,7 @@ const Methods = {
6370
6377
  } as any
6371
6378
 
6372
6379
  // Module methods
6373
- const funcs = 'setFilter,openFilter,clearFilter,getCheckedFilters,updateFilterOptionStatus,closeMenu,setActiveCellArea,getActiveCellArea,getCellAreas,clearCellAreas,copyCellArea,cutCellArea,pasteCellArea,getCopyCellArea,getCopyCellAreas,clearCopyCellArea,setCellAreas,openFNR,openFind,openReplace,closeFNR,getSelectedCell,clearSelected,insert,insertAt,insertNextAt,remove,removeCheckboxRow,removeRadioRow,removeCurrentRow,getRecordset,getInsertRecords,getRemoveRecords,getUpdateRecords,clearEdit,clearActived,getEditRecord,getActiveRecord,isEditByRow,isActiveByRow,setEditRow,setActiveRow,setEditCell,setActiveCell,setSelectCell,clearValidate,fullValidate,validate,openExport,closeExport,openPrint,closePrint,getPrintHtml,exportData,openImport,closeImport,importData,saveFile,readFile,importByFile,print,openCustom,closeCustom,saveCustom,cancelCustom,resetCustom,toggleCustomAllCheckbox,setCustomAllCheckbox'.split(',')
6380
+ const funcs = 'setFilter,openFilter,clearFilter,getCheckedFilters,updateFilterOptionStatus,closeMenu,setActiveCellArea,getActiveCellArea,getCellAreas,clearCellAreas,copyCellArea,cutCellArea,pasteCellArea,getCopyCellArea,getCopyCellAreas,clearCopyCellArea,setCellAreas,openFNR,openFind,openReplace,closeFNR,getSelectedCell,clearSelected,insert,insertAt,insertNextAt,remove,removeCheckboxRow,removeRadioRow,removeCurrentRow,getRecordset,getInsertRecords,getRemoveRecords,getUpdateRecords,clearEdit,clearActived,getEditRecord,getActiveRecord,isEditByRow,isActiveByRow,setEditRow,setActiveRow,setEditCell,setActiveCell,setSelectCell,clearValidate,fullValidate,validate,fullValidateField,validateField,openExport,closeExport,openPrint,closePrint,getPrintHtml,exportData,openImport,closeImport,importData,saveFile,readFile,importByFile,print,openCustom,closeCustom,saveCustom,cancelCustom,resetCustom,toggleCustomAllCheckbox,setCustomAllCheckbox'.split(',')
6374
6381
 
6375
6382
  funcs.forEach(name => {
6376
6383
  Methods[name] = function (...args: any[]) {