Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 如果配置了右键菜单;支持方向键操作、回车
evnt.preventDefault()
evnt.stopPropagation()
if (ctxMenuStore.showChild && this._hasCtxChilds(ctxMenuStore.selected)) {
this._handleCtxMenu(evnt, keyCode, ctxMenuStore, 'selectChild', 37, false, ctxMenuStore.selected.children)
} else {
this._handleCtxMenu(evnt, keyCode, ctxMenuStore, 'selected', 39, true, this.ctxMenuList)
}
return
} else if (isTab || (keyCode >= 37 && keyCode <= 40)) {
// 方向键、Tab 键处理
if ((this.configs.isTabKey && isTab) || this.configs.isArrowKey) {
let rowIndex = XEUtils.findIndexOf(tableData, isTab ? row => row.editActive || row.checked : row => row.checked)
let row = tableData[rowIndex]
if (row) {
let columnIndex = XEUtils.findIndexOf(columns, isTab ? column => column.property === row.editActive || column.property === row.checked : column => column.property === row.checked)
let column = columns[columnIndex]
if (column) {
switch (keyCode) {
case 9:
let offsetColumn = columns.find((column, index) => index > columnIndex && column.property)
// 从当前行中查找下一个可编辑列
// 如果找不到则从下一行开始找
if (offsetColumn && offsetColumn.property) {
if (this.configs.mode === 'cell' && row.editActive) {
let { cell } = this._getColumnByRowIndex(row.data, column.property)
this._validCellRules('blur', row, column)
.then(() => {
this._restoreTooltip()
this._clearActiveData()
this._tabActiveCell(row, offsetColumn)
}).catch(rule => this._toValidError(rule, row, column, cell))
_getRowIndex (row) {
return XEUtils.findIndexOf(this._getTDatas(), item => item === row)
},
// 获取列的索引
if (rowIndex > 0) {
this._moveUpAndDown(tableData, row, column, rowIndex - 1)
}
break
case 40:
if (rowIndex < tableData.length - 1) {
this._moveUpAndDown(tableData, row, column, rowIndex + 1)
}
break
}
}
}
}
} else if (this.configs.isCheckedEdit && ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 96 && keyCode <= 111) || (keyCode >= 186 && keyCode <= 192) || (keyCode >= 219 && keyCode <= 222) || keyCode === 32)) {
// 如果是选中状态,按任意键进入编辑
let rowIndex = XEUtils.findIndexOf(tableData, row => !row.editActive && row.checked)
let row = tableData[rowIndex]
if (row) {
let columnIndex = XEUtils.findIndexOf(columns, column => column.property === row.checked)
let column = columns[columnIndex]
if (column) {
let { cell } = this._getColumnByRowIndex(row.data, column.property)
this._triggerActive(row, column, cell, event)
.then(() => {
if (this.configs.checkedEditMethod ? this.configs.checkedEditMethod({ row: row.data, rowIndex, column, columnIndex, cell }, evnt) !== false : true) {
XEUtils.set(row.data, column.property, null)
}
})
}
}
} else if (this.configs.isDelKey && (keyCode === 8 || keyCode === 46)) {
// 如果是删除键
checkValid () {
// 查找是否存在校验不通过的列
let matchObj = XEUtils.findTree(this.datas, row => row.validActive, this.elTreeOpts)
if (matchObj) {
let row = matchObj.item
let column = XEUtils.findIndexOf(this.getColumns(), column => column.property === row.validActive)
return {
error: true,
row: row.data,
rowIndex: this._getRowIndex(row),
column,
columnIndex: this._getColumnIndex(column),
rule: row.validRule
}
}
return {
error: false
}
},
/**
let rowIndex = this._getRowIndex(row)
let type = 'out'
let isClearActive = true
let trElem, cellElem
target = evnt.target
while (target && target.nodeType && target !== document) {
if (UtilHandle.hasClass(target, 'elx-editable-row')) {
trElem = target
} else if (UtilHandle.hasClass(target, 'elx-editable-column')) {
cellElem = target
} else if (UtilHandle.hasClass(target, 'elx-editable')) {
// 如果是同表格
if (trElem && cellElem && target === this.$el) {
if (this.configs.mode === 'row') {
// 并且是同一行
if (XEUtils.findIndexOf(Array.from(trElem.parentNode.children), item => item === trElem) === rowIndex) {
return
}
} else {
// 并且是同一单元格
if (cellElem === cell) {
return
}
}
type = 'in'
}
break
}
target = target.parentNode
}
if (clearActiveMethod) {
let param = {
break
case 40:
if (rowIndex < tableData.length - 1) {
this._moveUpAndDown(tableData, row, column, rowIndex + 1)
}
break
}
}
}
}
} else if (this.configs.isCheckedEdit && ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 96 && keyCode <= 111) || (keyCode >= 186 && keyCode <= 192) || (keyCode >= 219 && keyCode <= 222) || keyCode === 32)) {
// 如果是选中状态,按任意键进入编辑
let rowIndex = XEUtils.findIndexOf(tableData, row => !row.editActive && row.checked)
let row = tableData[rowIndex]
if (row) {
let columnIndex = XEUtils.findIndexOf(columns, column => column.property === row.checked)
let column = columns[columnIndex]
if (column) {
let { cell } = this._getColumnByRowIndex(row.data, column.property)
this._triggerActive(row, column, cell, event)
.then(() => {
if (this.configs.checkedEditMethod ? this.configs.checkedEditMethod({ row: row.data, rowIndex, column, columnIndex, cell }, evnt) !== false : true) {
XEUtils.set(row.data, column.property, null)
}
})
}
}
} else if (this.configs.isDelKey && (keyCode === 8 || keyCode === 46)) {
// 如果是删除键
let rowIndex = XEUtils.findIndexOf(tableData, row => !row.editActive && row.checked)
let row = tableData[rowIndex]
if (row) {
if (this.configs.mode === 'cell' && row.editActive) {
let { cell } = this._getColumnByRowIndex(row.data, column.property)
this._validCellRules('blur', row, column)
.then(() => {
this._restoreTooltip()
this._clearActiveData()
this._tabActiveCell(row, offsetColumn)
}).catch(rule => this._toValidError(rule, row, column, cell))
} else {
this._tabActiveCell(row, offsetColumn)
}
evnt.preventDefault()
} else {
let offsetRow = tableData[rowIndex + 1]
if (offsetRow) {
columnIndex = XEUtils.findIndexOf(columns, column => column.property)
let offsetColumn = columns[columnIndex]
if (this.configs.mode === 'cell' && row.editActive) {
let { cell } = this._getColumnByRowIndex(row.data, column.property)
this._validCellRules('blur', row, column)
.then(() => {
row.editActive = null
row.checked = null
this._tabActiveCell(offsetRow, offsetColumn)
this._restoreTooltip()
this.$refs.refElTable.setCurrentRow(offsetRow)
}).catch(rule => this._toValidError(rule, row, column, cell))
} else {
row.checked = null
this._tabActiveCell(offsetRow, offsetColumn)
this.$refs.refElTable.setCurrentRow(offsetRow)
}
showMenu = true
}
break
}
target = target.parentNode
}
this._triggerClear(evnt)
if (showMenu) {
let rowElem = cellElem.parentNode
let columnIndex = XEUtils.findIndexOf(Array.from(rowElem.children), tdElem => tdElem === cellElem)
let column = this.getColumns()[columnIndex]
if (headerElem) {
this._showContextMenu(1, { column, columnIndex, cell: cellElem }, evnt)
} else {
let tableData = this._getTDatas()
let rowIndex = XEUtils.findIndexOf(Array.from(bodyElem.querySelector('tbody').children), trElem => trElem === rowElem)
let row = tableData[rowIndex]
if (row.editActive !== column.property) {
this._showContextMenu(0, { row, rowIndex, column, columnIndex, cell: cellElem }, evnt)
this.setChecked(row.data, column.property)
}
}
} else {
this.closeContextMenu()
}
},
/**
} else if (UtilHandle.hasClass(target, 'el-table__body')) {
bodyElem = target
} else if (UtilHandle.hasClass(target, 'elx-editable-column')) {
cellElem = target
} else if (UtilHandle.hasClass(target, 'elx-editable')) {
if ((headerElem || bodyElem) && cellElem && target === this.$el) {
showMenu = true
}
break
}
target = target.parentNode
}
this._triggerClear(evnt)
if (showMenu) {
let rowElem = cellElem.parentNode
let columnIndex = XEUtils.findIndexOf(Array.from(rowElem.children), tdElem => tdElem === cellElem)
let column = this.getColumns()[columnIndex]
if (headerElem) {
this._showContextMenu(1, { column, columnIndex, cell: cellElem }, evnt)
} else {
let tableData = this._getTDatas()
let rowIndex = XEUtils.findIndexOf(Array.from(bodyElem.querySelector('tbody').children), trElem => trElem === rowElem)
let row = tableData[rowIndex]
if (row.editActive !== column.property) {
this._showContextMenu(0, { row, rowIndex, column, columnIndex, cell: cellElem }, evnt)
this.setChecked(row.data, column.property)
}
}
} else {
this.closeContextMenu()
}
},