refactor(table): clean code

This commit is contained in:
07akioni 2021-09-03 01:10:54 +08:00
parent a715dfd545
commit 29577a22d2
2 changed files with 9 additions and 7 deletions

View File

@ -290,10 +290,12 @@ export default defineComponent({
onKeydown={handleKeyDown} onKeydown={handleKeyDown}
onClick={handleClick} onClick={handleClick}
onMousedown={() => { onMousedown={() => {
const userCallBack = window.onselectstart const preventDefault = (e: Event): void => {
window.onselectstart = () => false e.preventDefault()
}
window.addEventListener('selectstart', preventDefault)
setTimeout(() => { setTimeout(() => {
window.onselectstart = userCallBack window.removeEventListener('selectstart', preventDefault)
}, 0) }, 0)
}} }}
> >

View File

@ -143,12 +143,9 @@ export default defineComponent({
checked: boolean, checked: boolean,
shiftKey: boolean shiftKey: boolean
): void { ): void {
const lastKey = lastSelectedKey
lastSelectedKey = tmNode.key
if (shiftKey) { if (shiftKey) {
const lastIndex = paginatedDataRef.value.findIndex( const lastIndex = paginatedDataRef.value.findIndex(
(item) => item.key === lastKey (item) => item.key === lastSelectedKey
) )
if (lastIndex !== -1) { if (lastIndex !== -1) {
const currentIndex = paginatedDataRef.value.findIndex( const currentIndex = paginatedDataRef.value.findIndex(
@ -167,6 +164,8 @@ export default defineComponent({
} else { } else {
doUncheck(rowKeysToCheck) doUncheck(rowKeysToCheck)
} }
lastSelectedKey = tmNode.key
return
} }
} }
@ -175,6 +174,7 @@ export default defineComponent({
} else { } else {
doUncheck(tmNode.key) doUncheck(tmNode.key)
} }
lastSelectedKey = tmNode.key
} }
function getScrollContainer (): HTMLElement | null { function getScrollContainer (): HTMLElement | null {
if (virtualScrollRef.value) { if (virtualScrollRef.value) {