CN-697 feat: npm-tab保留状态

This commit is contained in:
chenjinsong
2022-09-07 21:32:43 +08:00
parent c9f34523e0
commit 66d5e134a8
2 changed files with 45 additions and 18 deletions

View File

@@ -38,6 +38,8 @@ import _ from 'lodash'
import Chart from '@/views/charts2/Chart' import Chart from '@/views/charts2/Chart'
import { panelTypeAndRouteMapping, storageKey, drillDownPanelTypeMapping } from '@/utils/constants' import { panelTypeAndRouteMapping, storageKey, drillDownPanelTypeMapping } from '@/utils/constants'
import { typeMapping } from '@/views/charts2/chart-tools' import { typeMapping } from '@/views/charts2/chart-tools'
import { useRoute } from 'vue-router'
import { ref } from 'vue'
export default { export default {
name: 'ChartList', name: 'ChartList',
props: { props: {
@@ -52,8 +54,7 @@ export default {
return { return {
panelTypeAndRouteMapping, panelTypeAndRouteMapping,
typeMapping, typeMapping,
layout: [], layout: []
npmTabIndex: 0
} }
}, },
components: { components: {
@@ -61,6 +62,14 @@ export default {
GridItem: VueGridLayout.GridItem, GridItem: VueGridLayout.GridItem,
Chart Chart
}, },
setup () {
const { query } = useRoute()
const tabIndexParam = query.tabIndex
const npmTabIndex = ref(tabIndexParam ? parseInt(tabIndexParam) : 0)
return {
npmTabIndex
}
},
watch: { watch: {
chartList (n) { chartList (n) {
if (!_.isEmpty(n)) { if (!_.isEmpty(n)) {

View File

@@ -20,18 +20,41 @@ import { getSecond } from '@/utils/date-util'
import { get } from '@/utils/http' import { get } from '@/utils/http'
import { api } from '@/utils/api' import { api } from '@/utils/api'
import { drillDownPanelTypeMapping } from '@/utils/constants' import { drillDownPanelTypeMapping } from '@/utils/constants'
import { overwriteUrl, urlParamsHandler } from '@/utils/tools'
import { useRoute } from 'vue-router'
import { ref } from 'vue'
export default { export default {
name: 'NpmTabs', name: 'NpmTabs',
data () { data () {
return { return {
currentTab: 0, leftOffset: 27
leftOffset: 27,
tabs: []
} }
}, },
mixins: [chartMixin], mixins: [chartMixin],
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
})
}
const { query } = useRoute()
const tabIndexParam = query.tabIndex
const currentTab = ref(tabIndexParam ? parseInt(tabIndexParam) : 0)
return {
currentTab,
tabs
}
},
watch: { watch: {
currentTab (n) { currentTab (n) {
const { query } = this.$route
const newUrl = urlParamsHandler(window.location.href, query, {
tabIndex: n
})
overwriteUrl(newUrl)
this.$nextTick(() => { this.$nextTick(() => {
this.handleActiveBar(n) this.handleActiveBar(n)
}) })
@@ -43,22 +66,17 @@ export default {
methods: { methods: {
handleActiveBar (index) { handleActiveBar (index) {
const tabDom = document.getElementById('tab-' + index) const tabDom = document.getElementById('tab-' + index)
const offsetLeft = tabDom.offsetLeft if (tabDom) {
const clientWidth = tabDom.clientWidth const offsetLeft = tabDom.offsetLeft
const clientLeft = tabDom.clientLeft const clientWidth = tabDom.clientWidth
const activeBar = document.querySelector('.npm-tabs .npm-tabs__active-bar') const clientLeft = tabDom.clientLeft
activeBar.style.cssText += `width: ${clientWidth + 2}px; left: ${offsetLeft + this.leftOffset + clientLeft - 1}px;` const activeBar = document.querySelector('.npm-tabs .npm-tabs__active-bar')
activeBar.style.cssText += `width: ${clientWidth + 2}px; left: ${offsetLeft + this.leftOffset + clientLeft - 1}px;`
}
} }
}, },
mounted () { mounted () {
this.toggleLoading(false) this.toggleLoading(false)
if (this.chart.params && this.chart.params.tabs) {
this.tabs = this.chart.params.tabs
this.tabs.forEach(item => {
item.disable = false
})
}
if (this.chart.panelId === drillDownPanelTypeMapping.npmOverviewIp) { if (this.chart.panelId === drillDownPanelTypeMapping.npmOverviewIp) {
// 当client或server的session数为0时对应tab置灰不可选默认高亮另一个不为0的tab // 当client或server的session数为0时对应tab置灰不可选默认高亮另一个不为0的tab
const condition = this.$store.getters.getQueryCondition.split(/["|'](.*?)["|']/) const condition = this.$store.getters.getQueryCondition.split(/["|'](.*?)["|']/)
@@ -96,7 +114,7 @@ export default {
}) })
} else { } else {
setTimeout(() => { setTimeout(() => {
this.handleActiveBar(0) this.handleActiveBar(this.currentTab)
}, 400) }, 400)
} }
} }