CN-697 feat: npm-tab保留状态
This commit is contained in:
@@ -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)) {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
if (tabDom) {
|
||||||
const offsetLeft = tabDom.offsetLeft
|
const offsetLeft = tabDom.offsetLeft
|
||||||
const clientWidth = tabDom.clientWidth
|
const clientWidth = tabDom.clientWidth
|
||||||
const clientLeft = tabDom.clientLeft
|
const clientLeft = tabDom.clientLeft
|
||||||
const activeBar = document.querySelector('.npm-tabs .npm-tabs__active-bar')
|
const activeBar = document.querySelector('.npm-tabs .npm-tabs__active-bar')
|
||||||
activeBar.style.cssText += `width: ${clientWidth + 2}px; left: ${offsetLeft + this.leftOffset + clientLeft - 1}px;`
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user