fix: table column resize for scroll, close #4811

pull/4825/head
tangjinzhou 2021-10-27 16:31:53 +08:00
parent 15d4b2eb2c
commit 42cc616ed3
1 changed files with 3 additions and 32 deletions

View File

@ -1,17 +1,7 @@
import addEventListenerWrap from '../../vc-util/Dom/addEventListener'; import addEventListenerWrap from '../../vc-util/Dom/addEventListener';
import type { EventHandler } from '../../_util/EventInterface'; import type { EventHandler } from '../../_util/EventInterface';
import raf from '../../_util/raf'; import raf from '../../_util/raf';
import { import { defineComponent, onUnmounted, computed, ref, watchEffect, getCurrentInstance } from 'vue';
defineComponent,
onUnmounted,
nextTick,
watch,
computed,
ref,
watchEffect,
getCurrentInstance,
onMounted,
} from 'vue';
import type { PropType } from 'vue'; import type { PropType } from 'vue';
import devWarning from '../../vc-util/devWarning'; import devWarning from '../../vc-util/devWarning';
import type { ColumnType } from '../interface'; import type { ColumnType } from '../interface';
@ -81,13 +71,7 @@ export default defineComponent({
: Infinity; : Infinity;
}); });
const instance = getCurrentInstance(); const instance = getCurrentInstance();
// eslint-disable-next-line vue/no-setup-props-destructure let baseWidth = 0;
let baseWidth = props.width;
onMounted(() => {
nextTick(() => {
baseWidth = instance.vnode.el?.parentNode?.getBoundingClientRect().width;
});
});
const dragging = ref(false); const dragging = ref(false);
let rafId: number; let rafId: number;
const updateWidth = (e: HandleEvent) => { const updateWidth = (e: HandleEvent) => {
@ -117,15 +101,12 @@ export default defineComponent({
const handleStop = (e: HandleEvent) => { const handleStop = (e: HandleEvent) => {
dragging.value = false; dragging.value = false;
updateWidth(e); updateWidth(e);
nextTick(() => {
baseWidth = instance.vnode.el?.parentNode?.getBoundingClientRect().width;
});
removeEvents(); removeEvents();
}; };
const handleStart = (e: HandleEvent, eventsFor: any) => { const handleStart = (e: HandleEvent, eventsFor: any) => {
dragging.value = true; dragging.value = true;
removeEvents(); removeEvents();
baseWidth = instance.vnode.el.parentNode.getBoundingClientRect().width;
if (e instanceof MouseEvent && e.which !== 1) { if (e instanceof MouseEvent && e.which !== 1) {
return; return;
} }
@ -150,16 +131,6 @@ export default defineComponent({
e.preventDefault(); e.preventDefault();
}; };
watch(
() => props.width,
() => {
if (!dragging.value) {
baseWidth = props.width;
}
},
{ immediate: true },
);
return () => { return () => {
const { prefixCls } = props; const { prefixCls } = props;
const touchEvents = { const touchEvents = {