From 36f5de2de97d4be9b29b54ce7f6a938ccba01607 Mon Sep 17 00:00:00 2001 From: kubbo <390378816@qq.com> Date: Wed, 8 Feb 2023 22:34:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E6=B3=A2=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=AF=BC=E8=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/navTabs.vue | 16 +++++++--------- web/src/main.js | 8 ++++---- web/src/utils/router.js | 5 +++-- web/src/utils/store.js | 9 +++++++-- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/web/src/components/navTabs.vue b/web/src/components/navTabs.vue index 56d4e61..c1ad08a 100644 --- a/web/src/components/navTabs.vue +++ b/web/src/components/navTabs.vue @@ -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) } } diff --git a/web/src/main.js b/web/src/main.js index 36a8840..b0fe62f 100644 --- a/web/src/main.js +++ b/web/src/main.js @@ -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') }) diff --git a/web/src/utils/router.js b/web/src/utils/router.js index 85cabb2..4ab20f3 100644 --- a/web/src/utils/router.js +++ b/web/src/utils/router.js @@ -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) }) diff --git a/web/src/utils/store.js b/web/src/utils/store.js index d9969b9..ff03052 100644 --- a/web/src/utils/store.js +++ b/web/src/utils/store.js @@ -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: {