Skip to content

Commit

Permalink
perf: remove tab in query
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuler committed Aug 21, 2024
1 parent a618794 commit e3c3729
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
6 changes: 4 additions & 2 deletions src/layout/components/AppMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ export default {
query[k] = v
}
let key
if (this.$route.name.toLowerCase().includes('list')) {
return _.trimEnd(this.$route.path, '/') + '?' + new URLSearchParams(query).toString()
key = _.trimEnd(this.$route.path, '/') + '?' + new URLSearchParams(query).toString()
} else {
return new Date().getTime()
key = new Date().getTime()
}
return key
},
chatAiEnabled() {
return this.publicSettings?.CHAT_AI_ENABLED
Expand Down
32 changes: 12 additions & 20 deletions src/layout/components/TabPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<el-alert v-if="helpMessage" type="success">
<span v-sanitize="helpMessage" class="announcement-main" />
</el-alert>
<transition v-if="!loading" appear mode="out-in" name="fade-transform">
<transition appear mode="out-in" name="fade-transform">
<slot>
<keep-alive>
<component :is="computeActiveComponent" />
Expand Down Expand Up @@ -83,16 +83,18 @@ export default {
},
data() {
return {
loading: true,
toSentenceCase: toSentenceCase
loading: false,
toSentenceCase: toSentenceCase,
activeTab: this.activeMenu
}
},
computed: {
iActiveMenu: {
get() {
return this.activeMenu
return this.activeTab
},
set(item) {
this.activeTab = item
this.$emit('update:activeMenu', item)
}
},
Expand All @@ -119,32 +121,22 @@ export default {
},
watch: {
$route(to, from) {
const activeTab = to.query?.tab
if (activeTab && this.iActiveMenu !== activeTab) {
this.iActiveMenu = activeTab
}
// 好像没必要
// const activeTab = to.query?.tab
// if (activeTab && this.iActiveMenu !== activeTab) {
// this.iActiveMenu = activeTab
// }
}
},
activated() {
this.iActiveMenu = this.getPropActiveTab()
this.loading = false
},
created() {
this.iActiveMenu = this.getPropActiveTab()
this.loading = false
},
methods: {
handleTabClick(tab) {
this.$emit('tab-click', tab)
this.$emit('update:activeMenu', tab.name)
this.iActiveMenu = tab.name
this.$cookie.set(this.$route.path, tab.name, 1)
if (this.$router.currentRoute.query[this.$route.path]) {
this.$router.push({
query: { ...this.$route.query, [this.$route.path]: '' }
})
}
},
getPropActiveTab() {
let activeTab = ''
Expand Down
17 changes: 9 additions & 8 deletions src/views/assets/Asset/AssetList/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ export default {
},
methods: {
handleTabClick(tab) {
const query = _.cloneDeep(this.$route.query)
const newQuery = {
...query,
tab: tab.name
}
this.$nextTick(() => {
this.$router.replace({ query: newQuery })
})
// 这样不行,会闪
// const query = _.cloneDeep(this.$route.query)
// const newQuery = {
// ...query,
// tab: tab.name
// }
// this.$nextTick(() => {
// this.$router.replace({ query: newQuery })
// })
}
}
}
Expand Down

0 comments on commit e3c3729

Please sign in to comment.