fix: calculate string width to set Tabs name width (#286)

This commit is contained in:
Fine0830 2023-06-20 18:04:41 +08:00 committed by GitHub
parent 6c4991bc56
commit 1ba56ca0cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,7 @@ limitations under the License. -->
class="tab-name" class="tab-name"
:readonly="isNaN(editTabIndex) && !canEditTabName" :readonly="isNaN(editTabIndex) && !canEditTabName"
:class="{ view: !canEditTabName }" :class="{ view: !canEditTabName }"
:style="{ width: getStringWidth(child.name) + 'px' }"
/> />
<Icon <Icon
v-show="activeTabIndex === idx" v-show="activeTabIndex === idx"
@ -202,6 +203,16 @@ limitations under the License. -->
const l = dashboardStore.layout.findIndex((d: LayoutConfig) => d.i === props.data.i); const l = dashboardStore.layout.findIndex((d: LayoutConfig) => d.i === props.data.i);
dashboardStore.setCurrentTabItems(dashboardStore.layout[l].children[activeTabIndex.value].children); dashboardStore.setCurrentTabItems(dashboardStore.layout[l].children[activeTabIndex.value].children);
} }
function getStringWidth(s: string) {
const dom = document.createElement("span");
dom.style.display = "inline-block";
dom.textContent = s;
document.body.appendChild(dom);
const width = dom.clientWidth;
document.body.removeChild(dom);
return width + 10;
}
function copyLink() { function copyLink() {
let path = ""; let path = "";
if (route.params.activeTabIndex === undefined) { if (route.params.activeTabIndex === undefined) {
@ -254,6 +265,7 @@ limitations under the License. -->
removeTab, removeTab,
clickTabs, clickTabs,
copyLink, copyLink,
getStringWidth,
...toRefs(props), ...toRefs(props),
activeTabWidget, activeTabWidget,
dashboardStore, dashboardStore,
@ -275,6 +287,7 @@ limitations under the License. -->
overflow-x: auto; overflow-x: auto;
white-space: nowrap; white-space: nowrap;
overflow-y: hidden; overflow-y: hidden;
padding: 0 10px;
span { span {
display: inline-block; display: inline-block;
@ -285,16 +298,15 @@ limitations under the License. -->
} }
.tab-name { .tab-name {
max-width: 130px; max-width: 150px;
height: 20px; height: 20px;
line-height: 20px; line-height: 20px;
outline: none; outline: none;
color: #333; color: #333;
font-style: normal; font-style: normal;
margin-right: 5px;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
text-align: center; margin-right: 20px;
} }
.tab-icons { .tab-icons {