fix: 修复ChartTabs组件切换界面时,tab未被重置的问题

This commit is contained in:
刘洪洪
2022-12-07 18:28:00 +08:00
parent ddff5a25f5
commit c6a9adfc4f

View File

@@ -91,12 +91,30 @@ export default {
const tabIndexParam = query.tabIndex
currentTab = ref(tabIndexParam ? parseInt(tabIndexParam) : 0)
} else if (!tabList) {
// 此处为刷新界面时根据当前路由获取index
currentTab = tabsData.value.findIndex(item => {
return item.path === routerPath
})
window.currentChartTabList = [currentTab]
window.currentChartTabList = [{ path: routerPath, index: currentTab }]
} else {
currentTab = tabList[1] ? parseFloat(tabList[1]) : parseFloat(tabList[0])
// 此处为切换界面如果window里保存的路径和tabsData里的路径一致选择window数据并使用
// 两个不一致的话则默认选择tabsData里的第一条
let obj0 = null
let obj1 = null
obj0 = tabsData.value.find(item => { return item.path === tabList[0].path })
if (tabList[1]) {
obj1 = tabsData.value.find(item => { return item.path === tabList[1].path })
}
if (obj0 && obj1) {
currentTab = parseFloat(tabList[1].index)
} else if (obj0) {
currentTab = parseFloat(tabList[0].index)
} else {
window.currentChartTabList = [{ path: tabsData.value[0].path, index: 0 }]
currentTab = 0
}
}
}
@@ -140,7 +158,7 @@ export default {
if (window.currentChartTabList) {
window.currentChartTabList.forEach((item) => {
this.$nextTick(() => {
this.handleActiveBar(parseFloat(item))
this.handleActiveBar(parseFloat(item.index))
})
})
} else {
@@ -170,13 +188,13 @@ export default {
}
},
handleClick (item) {
if (window.currentChartTabList) {
window.currentChartTabList.push(item.index)
if (window.currentChartTabList.length > 2) {
window.currentChartTabList.splice(0, 1)
}
} else {
window.currentChartTabList = [item.index]
window.currentChartTabList.push({
path: this.tabsData[item.index].path,
index: item.index
})
if (window.currentChartTabList.length > 2) {
window.currentChartTabList.splice(0, 1)
}
this.$emit('click', item)