Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 UTableView 在某些情况下父节点设置了min-width:fit-content的情况下,handleResize会一直执行 #307

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/components/u-table-view.vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -599,19 +599,21 @@ export default {
this.watchValue(this.value);
this.watchValues(this.values);
this.handleResize();
addResizeListener(this.$el, this.handleResize);
this.preRootWidth = undefined;
addResizeListener(this.$el, this.handleResizeListener);

if (this.stickHead) {
this.scrollParentEl = findScrollParent(this.$el);
this.scrollParentEl && this.scrollParentEl.addEventListener('scroll', this.onScrollParentScroll);
}
},
destroyed() {
removeResizeListener(this.$el, this.handleResize);
removeResizeListener(this.$el, this.handleResizeListener);
if (this.stickHead) {
this.scrollParentEl && this.scrollParentEl.removeEventListener('scroll', this.onScrollParentScroll);
}
this.clearTimeout();
this.preRootWidth = undefined;
},
methods: {
typeCheck(type) {
Expand Down Expand Up @@ -714,7 +716,7 @@ export default {
number2Pixel(value) {
return isNumber(value) ? value + 'px' : '';
},
handleResize() {
handleResize(isListener) {
if (this.resizeBodyHeight) {
this.bodyHeight = undefined;
}
Expand All @@ -730,6 +732,17 @@ export default {
parentEl = parentEl.parentElement;
rootWidth = parentEl ? parentEl.offsetWidth : 0;
}
// 有些情况下rootWidth会缓慢增长,导致handleResize一直执行
if (isListener) {
if (!this.preRootWidth) {
this.preRootWidth = rootWidth;
} else {
if (Math.abs(this.preRootWidth - rootWidth) <= 1) {
rootWidth = this.preRootWidth;
}
this.preRootWidth = rootWidth;
}
}

// 分别获取有百分比、具体数值和无 width 的列
const percentColumnVMs = [];
Expand Down Expand Up @@ -2002,6 +2015,9 @@ export default {
}
return '100%';
},
handleResizeListener() {
this.handleResize(true);
},
},
};
</script>
Expand Down