fix(KLPTable): 调整浮动层位置防止超出屏幕边界
添加 adjustedTooltipStyle 计算属性,当浮动层超出屏幕底部或右侧时自动调整位置
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<transition name="el-fade-in-linear">
|
||||
<div v-if="tooltipVisible && data" class="row-tooltip" :style="tooltipStyle" ref="rowTooltip">
|
||||
<div v-if="tooltipVisible && data" class="row-tooltip" :style="adjustedTooltipStyle" ref="rowTooltip">
|
||||
<slot>
|
||||
<div class="tooltip-list">
|
||||
<div class="tooltip-item" v-for="field in visibleColumns" :key="field.prop">
|
||||
@@ -38,6 +38,22 @@ export default {
|
||||
// 一个列要同时有用 label 和 prop 才显示在浮层中, 并且prop有值时才显示
|
||||
visibleColumns() {
|
||||
return this.columns.filter(field => field.label && field.prop && this.data[field.prop])
|
||||
},
|
||||
// 修正后的tooltipStyle / 其实tooltipStyle只包含两个属性:top, left, 当在屏幕中无法完全展示时,需要根据实际情况调整位置
|
||||
adjustedTooltipStyle() {
|
||||
const { top, left } = this.tooltipStyle;
|
||||
const tooltipRect = this.$refs.rowTooltip?.getBoundingClientRect();
|
||||
if (!tooltipRect) return this.tooltipStyle;
|
||||
|
||||
// 检查是否超出底部边界
|
||||
if (parseInt(top) + tooltipRect.height > window.innerHeight) {
|
||||
return { ...this.tooltipStyle, top: `${window.innerHeight - tooltipRect.height - 12}px` };
|
||||
}
|
||||
// 检查是否超出右侧边界
|
||||
if (parseInt(left) + tooltipRect.width > window.innerWidth) {
|
||||
return { ...this.tooltipStyle, left: `${window.innerWidth - tooltipRect.width - 16}px` };
|
||||
}
|
||||
return this.tooltipStyle;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -83,7 +99,7 @@ export default {
|
||||
padding: 12px 14px;
|
||||
pointer-events: none;
|
||||
z-index: 5;
|
||||
max-height: 70%;
|
||||
/* max-height: 70%; */
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user