修复一波页面导航
This commit is contained in:
@@ -34,8 +34,9 @@ export default {
|
||||
name: "navTabs",
|
||||
components: {Setting, Close},
|
||||
computed: {
|
||||
...mapState(mainStore, ['pages']),
|
||||
tabs: v => v.pages
|
||||
...mapState(mainStore, ['pages', 'routes']),
|
||||
tabs: v => v.pages,
|
||||
currentTab: v => v.$route.fullPath
|
||||
},
|
||||
methods: {
|
||||
...mapActions(mainStore, ['deletePage', 'clearOtherPages', 'addPage']),
|
||||
@@ -43,14 +44,15 @@ export default {
|
||||
const {pages} = this
|
||||
if (id == this.currentTab) {
|
||||
const index = pages.findIndex(e => e.id == id)
|
||||
const next = pages?.[index + 1] || pages?.[index - 1] || {id: this.fixed.id || "/"}
|
||||
const next = pages?.[index + 1] || pages?.[index - 1] || {id: "/"}
|
||||
console.log(next, this.currentTab)
|
||||
this.handleJump({name: next.id})
|
||||
}
|
||||
this.deletePage(id)
|
||||
},
|
||||
handleJump(page) {
|
||||
const {name} = page
|
||||
name != this.$route.fullPath && this.$router.push(name)
|
||||
name != this.currentTab && this.$router.push(name)
|
||||
},
|
||||
handleOpt(v) {
|
||||
const opts = {
|
||||
@@ -67,14 +69,10 @@ export default {
|
||||
$route: {
|
||||
immediate: true,
|
||||
handler(v) {
|
||||
const currentPage = this.pages.find(e => e.name == v.name);
|
||||
const currentPage = this.routes.find(e => e.name == v.name);
|
||||
currentPage && this.addPage(currentPage)
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
const currentPage = JSON.parse(localStorage.getItem("apps") || null)?.find(e => e.name == this.$route.name);
|
||||
currentPage && mainStore().addPage(currentPage)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -16,12 +16,12 @@ app.config.globalProperties.$sys = {
|
||||
title: "综合业务管理平台"
|
||||
}
|
||||
Object.keys(tools).map(e => app.config.globalProperties[e] = tools[e])
|
||||
app.use(eui, {locale: zhCn})
|
||||
const store = createPinia()
|
||||
store.use(persist)
|
||||
app.use(store)
|
||||
router.then(r => {
|
||||
app.use(eui, {locale: zhCn})
|
||||
app.use(r)
|
||||
const store = createPinia()
|
||||
store.use(persist)
|
||||
app.use(store)
|
||||
app.mount('#app')
|
||||
})
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import {createRouter, createWebHistory} from 'vue-router'
|
||||
import {getToken} from './tools'
|
||||
import {mainStore} from "./store";
|
||||
|
||||
|
||||
let home = {name: "工作台", path: "/v", component: () => import('../views/home')},
|
||||
let home = {name: "工作台", path: "/", component: () => import('../views/home')},
|
||||
routes = [{name: "登录", path: "/login", component: () => import('../views/login')}]
|
||||
const loadApps = () => {
|
||||
const files = import.meta.glob('../apps/App*.vue'), apps = []
|
||||
@@ -19,7 +20,7 @@ const loadApps = () => {
|
||||
}
|
||||
})
|
||||
})).then(() => {
|
||||
localStorage.setItem("apps", JSON.stringify(apps))
|
||||
mainStore().setRoutes(apps)
|
||||
home.children = apps
|
||||
routes.push(home)
|
||||
})
|
||||
|
||||
@@ -5,7 +5,8 @@ export const mainStore = defineStore('main', {
|
||||
state: () => ({
|
||||
user: {},
|
||||
token: "",
|
||||
pages: []
|
||||
pages: [],
|
||||
routes: []
|
||||
}),
|
||||
actions: {
|
||||
getToken(params) {
|
||||
@@ -25,7 +26,8 @@ export const mainStore = defineStore('main', {
|
||||
})
|
||||
},
|
||||
addPage(page) {
|
||||
if (!this.pages.find(e => e.id == location.href)) this.pages.push({...page, id: location.href})
|
||||
const id = page?.id || location.href?.replace(location.origin, "")
|
||||
if (!this.pages.find(e => e.id == id)) this.pages.push({...page, id})
|
||||
},
|
||||
deletePage(id) {
|
||||
id = id || location.href?.replace(location.origin, "")
|
||||
@@ -42,6 +44,9 @@ export const mainStore = defineStore('main', {
|
||||
logout() {
|
||||
this.user = {}
|
||||
this.token = ""
|
||||
},
|
||||
setRoutes(routes) {
|
||||
this.routes = routes
|
||||
}
|
||||
},
|
||||
persist: {
|
||||
|
||||
Reference in New Issue
Block a user