fix: 调整npm-dashboard的tab的实现逻辑
This commit is contained in:
@@ -1,22 +1,42 @@
|
|||||||
.npm-tabs {
|
.npm-tabs {
|
||||||
.el-tabs--top .el-tabs__item.is-top:nth-child(2) {
|
position: relative;
|
||||||
padding-left: 20px;
|
|
||||||
}
|
.npm-tabs__active-bar {
|
||||||
.el-tabs__nav-wrap::after {
|
position: absolute;
|
||||||
height: 1px;
|
|
||||||
background-color: #E2E5EC;
|
|
||||||
}
|
|
||||||
.el-tabs--top .el-tabs__item {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
.el-tabs__active-bar.is-top {
|
|
||||||
top: 0;
|
|
||||||
height: 3px;
|
height: 3px;
|
||||||
border-radius: 5px 2.5px 0 0;
|
top: 0;
|
||||||
|
background-color: #046EC9;
|
||||||
|
border-radius: 5px 5px 0 0;
|
||||||
|
transition: all linear .2s;
|
||||||
}
|
}
|
||||||
|
.el-tabs.el-tabs--border-card {
|
||||||
|
position: absolute;
|
||||||
|
top: 3px;
|
||||||
|
width: 100%;
|
||||||
|
border: none;
|
||||||
|
box-shadow: none;
|
||||||
|
|
||||||
|
&>.el-tabs__header {
|
||||||
|
background-color: white;
|
||||||
|
border-color: #E2E5EC;
|
||||||
|
|
||||||
|
.el-tabs__nav-wrap {
|
||||||
|
padding-left: 27px;
|
||||||
|
}
|
||||||
|
.el-tabs__item:first-child {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.el-tabs__content {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.el-tabs__item.is-top {
|
.el-tabs__item.is-top {
|
||||||
|
height: 35px;
|
||||||
|
line-height: 35px;
|
||||||
|
|
||||||
.npm-tab__label {
|
.npm-tab__label {
|
||||||
padding: 0 20px;
|
|
||||||
color: #353636;
|
color: #353636;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@@ -31,7 +51,6 @@
|
|||||||
&.is-active {
|
&.is-active {
|
||||||
.npm-tab__label {
|
.npm-tab__label {
|
||||||
color: #353636;
|
color: #353636;
|
||||||
box-shadow: 1px 0 0 0 #E2E5EC, inset 1px 0 0 #E2E5EC;
|
|
||||||
|
|
||||||
i {
|
i {
|
||||||
color: #046EC9;
|
color: #046EC9;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="npm-tabs">
|
<div class="npm-tabs">
|
||||||
<el-tabs v-model="currentTab" ref="elTabs">
|
<div class="npm-tabs__active-bar"></div>
|
||||||
|
<el-tabs v-model="currentTab" ref="elTabs" type="border-card">
|
||||||
<el-tab-pane>
|
<el-tab-pane>
|
||||||
<template #label>
|
<template #label>
|
||||||
<div class="npm-tab__label">
|
<div class="npm-tab__label">
|
||||||
@@ -34,21 +35,29 @@ export default {
|
|||||||
name: 'NpmTabs',
|
name: 'NpmTabs',
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
currentTab: 0
|
currentTab: 0,
|
||||||
|
leftOffset: 27
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
currentTab (n) {
|
currentTab (n) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.handleActiveBar(n)
|
||||||
|
})
|
||||||
this.$emit('tabChange', n)
|
this.$emit('tabChange', n)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
handleActiveBar (index) {
|
||||||
|
const { offsetLeft, clientWidth, clientLeft } = document.querySelector('.npm-tabs .el-tabs__item.is-active')
|
||||||
|
const activeBar = document.querySelector('.npm-tabs .npm-tabs__active-bar')
|
||||||
|
activeBar.style.width = `${clientWidth + 2}px`
|
||||||
|
activeBar.style.left = `${offsetLeft + this.leftOffset + clientLeft - 1}px`
|
||||||
|
}
|
||||||
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
// 修正字体改变导致的active-bar宽度计算偏差
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const activeTab = document.querySelector('.npm-tabs .el-tabs__item.is-active')
|
this.handleActiveBar(0)
|
||||||
const activeTabStyle = window.getComputedStyle(activeTab)
|
|
||||||
const activeBar = document.querySelector('.npm-tabs .el-tabs__active-bar')
|
|
||||||
activeBar.style.width = `${parseFloat(activeTabStyle.width) - parseFloat(activeTabStyle.paddingLeft)}px`
|
|
||||||
}, 200)
|
}, 200)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user