修复一下tab页签

This commit is contained in:
aixianling
2022-05-17 10:54:34 +08:00
parent dbca23bb6d
commit da259ebec6

View File

@@ -21,7 +21,7 @@ export default {
...mapState(['apps']), ...mapState(['apps']),
currentTab() { currentTab() {
let {name, query, hash} = this.$route let {name, query, hash} = this.$route
return [name, query?.id, hash].join("") return [name?.replace(query?.id, ''), query?.id, hash].join("")
} }
}, },
data() { data() {
@@ -32,21 +32,19 @@ export default {
watch: { watch: {
$route: { $route: {
immediate: true, immediate: true,
handler(v) { handler() {
this.getTabs(v) this.getTabs("route")
} }
}, },
}, },
methods: { methods: {
handleTabClick(tab) { handleTabClick({name}) {
let to = {}, selectedTab = this.tabs.find(e => e.name == tab.name) let {name: route, query, hash} = this.tabs.find(e => e.name == name),
if (selectedTab) { exps = []
to = {...selectedTab, params: {tabclick: 1}} query.id && exps.push(query.id)
} else { hash && exps.push(hash)
let {name, query, hash} = tab let reg = new RegExp(`(${exps.join("|")})`, 'g')
to = {name, query, hash, params: {tabclick: 1}} this.$router.push({name: route.replace(reg, ''), query, hash})
}
this.$router.push({...to})
}, },
handleTabRemove(id = this.currentTab) { handleTabRemove(id = this.currentTab) {
let tabs = JSON.parse(JSON.stringify(this.tabs)), let tabs = JSON.parse(JSON.stringify(this.tabs)),
@@ -57,11 +55,13 @@ export default {
} }
this.tabs.splice(index, 1) this.tabs.splice(index, 1)
}, },
getTabs() { getTabs(from) {
let {name, query, hash} = this.$route let {name, query, hash} = this.$route
console.log(`getTabs>>>>>>>>>%s>>>>>>>%s`, from, name)
let tab = this.tabs.find(e => e.name == this.currentTab), let tab = this.tabs.find(e => e.name == this.currentTab),
tabName = [name, query?.id, hash].join("") tabName = [name, query?.id, hash].join("")
if (tab) { if (tab) {
} else if (!name) {
} else if (tabName) { } else if (tabName) {
let menu = this.apps.find(e => e.name == name) let menu = this.apps.find(e => e.name == name)
this.tabs.push({name: tabName, query, hash, label: menu?.label}) this.tabs.push({name: tabName, query, hash, label: menu?.label})
@@ -69,7 +69,7 @@ export default {
}, },
}, },
created() { created() {
this.getTabs() this.getTabs("created")
} }
} }
</script> </script>