2022-07-18 15:04:32 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="npm-tabs">
|
2022-07-18 18:18:34 +08:00
|
|
|
|
<div class="npm-tabs__active-bar"></div>
|
2022-11-28 09:20:41 +08:00
|
|
|
|
<el-tabs v-model="currentTab" ref="elTabs" type="border-card" v-show="isCurTabReady"
|
|
|
|
|
|
@tab-click="handleClick">
|
2022-12-14 11:26:28 +08:00
|
|
|
|
<el-tab-pane v-for="(tab,index) in tabs" :key="tab.i18n" :name="JSON.stringify(index)" :disabled="tab.disable" >
|
2022-07-18 15:04:32 +08:00
|
|
|
|
<template #label>
|
|
|
|
|
|
<div class="npm-tab__label">
|
2022-08-11 15:49:41 +08:00
|
|
|
|
<i :class="tab.icon"></i>
|
|
|
|
|
|
<span>{{$t(tab.i18n)}}</span>
|
2022-07-18 15:04:32 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
</el-tabs>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-08-21 22:11:53 +08:00
|
|
|
|
import chartMixin from '@/views/charts2/chart-mixin'
|
2022-09-02 14:06:00 +08:00
|
|
|
|
import { getSecond } from '@/utils/date-util'
|
|
|
|
|
|
import { api } from '@/utils/api'
|
2023-08-24 17:15:41 +08:00
|
|
|
|
import axios from 'axios'
|
2022-09-02 14:06:00 +08:00
|
|
|
|
import { drillDownPanelTypeMapping } from '@/utils/constants'
|
2022-09-07 21:32:43 +08:00
|
|
|
|
import { overwriteUrl, urlParamsHandler } from '@/utils/tools'
|
|
|
|
|
|
import { ref } from 'vue'
|
2022-07-18 15:04:32 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: 'NpmTabs',
|
2022-07-18 16:09:13 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2022-11-28 09:20:41 +08:00
|
|
|
|
leftOffset: 27,
|
2022-12-14 11:26:28 +08:00
|
|
|
|
currentTab: ref('0'),
|
2022-12-08 16:09:46 +08:00
|
|
|
|
isCurTabReady: false
|
2022-07-18 15:04:32 +08:00
|
|
|
|
}
|
2022-07-18 16:09:13 +08:00
|
|
|
|
},
|
2022-08-21 22:11:53 +08:00
|
|
|
|
mixins: [chartMixin],
|
2022-09-07 21:32:43 +08:00
|
|
|
|
setup (props) {
|
|
|
|
|
|
const tabs = ref([])
|
|
|
|
|
|
if (props.chart.params && props.chart.params.tabs) {
|
|
|
|
|
|
tabs.value = [...props.chart.params.tabs]
|
|
|
|
|
|
tabs.value.forEach(item => {
|
|
|
|
|
|
item.disable = false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
|
|
|
tabs
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-12-14 18:07:48 +08:00
|
|
|
|
emits: ['tabChange'],
|
2022-07-18 16:09:13 +08:00
|
|
|
|
watch: {
|
|
|
|
|
|
currentTab (n) {
|
2023-03-24 16:37:12 +08:00
|
|
|
|
this.reloadUrl(n)
|
2022-09-07 21:32:43 +08:00
|
|
|
|
|
2022-07-18 18:18:34 +08:00
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.handleActiveBar(n)
|
|
|
|
|
|
})
|
2022-09-01 17:14:15 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.$emit('tabChange', n)
|
2022-09-01 17:41:27 +08:00
|
|
|
|
}, 400)
|
2023-01-06 09:48:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
timeFilter: {
|
|
|
|
|
|
handler () {
|
|
|
|
|
|
this.initTabs()
|
|
|
|
|
|
}
|
2022-07-18 16:09:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-07-18 18:18:34 +08:00
|
|
|
|
methods: {
|
2023-01-06 09:48:19 +08:00
|
|
|
|
initTabs () {
|
|
|
|
|
|
const { query } = this.$route
|
|
|
|
|
|
const tabIndexParam = query.tabIndex
|
|
|
|
|
|
const curTabIndexInUrl = tabIndexParam ? parseInt(tabIndexParam) : null
|
|
|
|
|
|
if (this.chart.panelId === drillDownPanelTypeMapping.npmOverviewIp) {
|
|
|
|
|
|
const self = this
|
|
|
|
|
|
// 当client或server的session数为0时,对应tab置灰,不可选,默认高亮另一个不为0的tab
|
|
|
|
|
|
const conditionStr = this.$route.query.queryCondition ? this.$route.query.queryCondition : ''
|
|
|
|
|
|
const condition = conditionStr.split(/["|'](.*?)["|']/)
|
|
|
|
|
|
const params = {
|
|
|
|
|
|
startTime: getSecond(this.timeFilter.startTime),
|
|
|
|
|
|
endTime: getSecond(this.timeFilter.endTime),
|
|
|
|
|
|
ip: condition[1]
|
|
|
|
|
|
}
|
2023-08-24 17:15:41 +08:00
|
|
|
|
axios.get(api.npm.overview.relatedSessions, { params: params }).then(res => {
|
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
|
self.sessionData = res.data.data.result
|
2023-01-06 09:48:19 +08:00
|
|
|
|
self.clientSessions = self.sessionData.clientSessions / (self.sessionData.clientSessions * 1 + self.sessionData.serverSessions * 1)
|
|
|
|
|
|
self.serverSessions = self.sessionData.serverSessions / (self.sessionData.clientSessions * 1 + self.sessionData.serverSessions * 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
|
const thirdMenu = this.$route.query.thirdMenu
|
|
|
|
|
|
self.ableTab(0)
|
|
|
|
|
|
self.ableTab(1)
|
|
|
|
|
|
let curTabIndex = 0
|
|
|
|
|
|
if (thirdMenu === 'network.clientIps') {
|
|
|
|
|
|
curTabIndex = 0
|
|
|
|
|
|
if (self.serverSessions === 0) {
|
|
|
|
|
|
self.disableTab(1)
|
|
|
|
|
|
} else if (curTabIndexInUrl !== null) {
|
|
|
|
|
|
curTabIndex = curTabIndexInUrl
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (thirdMenu === 'network.serverIps') {
|
|
|
|
|
|
curTabIndex = 1
|
|
|
|
|
|
if (self.clientSessions === 0) {
|
|
|
|
|
|
self.disableTab(0)
|
|
|
|
|
|
} else if (curTabIndexInUrl !== null) {
|
|
|
|
|
|
curTabIndex = curTabIndexInUrl
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 禁用tab设置
|
|
|
|
|
|
if (self.clientSessions === 0) {
|
|
|
|
|
|
self.disableTab(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (self.serverSessions === 0) {
|
|
|
|
|
|
self.disableTab(1)
|
|
|
|
|
|
}
|
|
|
|
|
|
// 当前tab设置
|
|
|
|
|
|
if (self.clientSessions !== 0 && self.serverSessions === 0) {
|
|
|
|
|
|
curTabIndex = 0
|
|
|
|
|
|
} else if (self.clientSessions === 0 && self.serverSessions !== 0) {
|
|
|
|
|
|
curTabIndex = 1
|
|
|
|
|
|
} else { // 都为0或者都不为0,则停留在url中tab参数指定的tab
|
|
|
|
|
|
if (curTabIndexInUrl !== null) {
|
|
|
|
|
|
curTabIndex = curTabIndexInUrl
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
self.currentTab = JSON.stringify(curTabIndex)
|
|
|
|
|
|
self.isCurTabReady = true
|
|
|
|
|
|
// URL中tabIndex的设置,client初始化时查询条件需要:side条件
|
2023-03-24 16:37:12 +08:00
|
|
|
|
self.reloadUrl(self.currentTab)
|
|
|
|
|
|
|
2023-01-06 09:48:19 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
self.handleActiveBar(self.currentTab)
|
|
|
|
|
|
}, 400)
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.$emit('tabChange', self.currentTab)
|
|
|
|
|
|
}, 400)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.currentTab = curTabIndexInUrl ? JSON.stringify(curTabIndexInUrl) : '0'
|
|
|
|
|
|
this.isCurTabReady = true
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.handleActiveBar(this.currentTab)
|
|
|
|
|
|
}, 400)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-12-08 16:09:46 +08:00
|
|
|
|
handleClick (tab) {
|
2023-03-24 16:37:12 +08:00
|
|
|
|
this.reloadUrl(tab.index)
|
2022-11-28 09:20:41 +08:00
|
|
|
|
},
|
2022-07-18 18:18:34 +08:00
|
|
|
|
handleActiveBar (index) {
|
2022-09-02 14:06:00 +08:00
|
|
|
|
const tabDom = document.getElementById('tab-' + index)
|
2022-09-07 21:32:43 +08:00
|
|
|
|
if (tabDom) {
|
|
|
|
|
|
const offsetLeft = tabDom.offsetLeft
|
|
|
|
|
|
const clientWidth = tabDom.clientWidth
|
|
|
|
|
|
const clientLeft = tabDom.clientLeft
|
|
|
|
|
|
const activeBar = document.querySelector('.npm-tabs .npm-tabs__active-bar')
|
|
|
|
|
|
activeBar.style.cssText += `width: ${clientWidth + 2}px; left: ${offsetLeft + this.leftOffset + clientLeft - 1}px;`
|
|
|
|
|
|
}
|
2022-11-28 09:20:41 +08:00
|
|
|
|
},
|
2022-12-08 16:09:46 +08:00
|
|
|
|
disableTab (n) {
|
2022-11-28 09:20:41 +08:00
|
|
|
|
this.tabs[n].disable = true
|
2022-12-08 16:09:46 +08:00
|
|
|
|
const tabEle = document.getElementById('tab-' + n)
|
2022-11-28 09:20:41 +08:00
|
|
|
|
tabEle.style.cssText = 'cursor: not-allowed;'
|
2023-01-06 09:48:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
ableTab (n) {
|
|
|
|
|
|
this.tabs[n].disable = false
|
|
|
|
|
|
const tabEle = document.getElementById('tab-' + n)
|
|
|
|
|
|
tabEle.style.cssText = 'cursor: pointer;'
|
2023-03-24 16:37:12 +08:00
|
|
|
|
},
|
|
|
|
|
|
reloadUrl (index) {
|
|
|
|
|
|
const { query } = this.$route
|
|
|
|
|
|
const newUrl = urlParamsHandler(window.location.href, query, {
|
|
|
|
|
|
tabIndex: index
|
|
|
|
|
|
})
|
|
|
|
|
|
overwriteUrl(newUrl)
|
2022-07-18 18:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-07-18 16:09:13 +08:00
|
|
|
|
mounted () {
|
2023-01-06 09:48:19 +08:00
|
|
|
|
this.initTabs()
|
2022-07-18 15:04:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|