From 1851c374e5eafabf8918ee2eaec5d5abafcc26d1 Mon Sep 17 00:00:00 2001 From: From-wh Date: Tue, 18 Apr 2023 14:48:24 +0800 Subject: [PATCH] =?UTF-8?q?improve:=20=E8=8F=9C=E5=8D=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/admin/src/layout/index.vue | 3 ++ .../src/layout/navBars/tagsView/tagsView.vue | 52 +++++++++++++------ .../admin/src/pages/account/login/index.vue | 5 +- template/admin/src/router/modules/index.js | 4 +- template/admin/src/store/module/menus.js | 5 +- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/template/admin/src/layout/index.vue b/template/admin/src/layout/index.vue index 1ae954a3b..4aaf0c232 100644 --- a/template/admin/src/layout/index.vue +++ b/template/admin/src/layout/index.vue @@ -31,6 +31,9 @@ export default { getThemeConfig() { return this.$store.state.themeConfig.themeConfig; }, + tagNavList() { + return this.$store.state.app.tagNavList; + }, }, watch: { $route(newRoute) { diff --git a/template/admin/src/layout/navBars/tagsView/tagsView.vue b/template/admin/src/layout/navBars/tagsView/tagsView.vue index 9ae9bdcdf..ba45c569d 100644 --- a/template/admin/src/layout/navBars/tagsView/tagsView.vue +++ b/template/admin/src/layout/navBars/tagsView/tagsView.vue @@ -40,6 +40,8 @@ import Contextmenu from '@/layout/navBars/tagsView/contextmenu'; import { Session } from '@/utils/storage.js'; import { mapMutations } from 'vuex'; +import setting from '@/setting'; + export default { name: 'tagsView', components: { Contextmenu }, @@ -77,7 +79,9 @@ export default { this.tagsViewRoutesList = this.$store.state.app.tagNavList; }, mounted() { - // this.getTagsViewRoutes(); + if (!this.$store.state.app.tagNavList.length) { + this.getTagsViewRoutes(); + } }, methods: { ...mapMutations(['setBreadCrumb', 'setTagNavList', 'addTag', 'setLocal', 'setHomeRoute', 'closeTag']), @@ -90,7 +94,15 @@ export default { onTagsClick(v, k) { this.tagsRoutePath = v.path; this.tagsRefsIndex = k; - this.$router.push(v); + try { + if (v.name == 'home_index') { + this.$router.replace(`${setting.routePre}/home/`); + } else { + this.$router.push(v); + } + } catch (error) { + console.log(error); + } }, // 获取 tagsView 的下标:用于处理 tagsView 点击时的横向滚动 getTagsRefsIndex(path) { @@ -184,9 +196,8 @@ export default { // 获取 vuex 中的 tagsViewRoutes 列表 getTagsViewRoutes() { this.tagsRoutePath = this.$route.path; - this.tagsViewList = []; - if (!this.$store.state.themeConfig.themeConfig.isCacheTagsView) Session.remove('tagsViewList'); - this.tagsViewRoutesList = this.$store.state.tagsViewRoutes.tagsViewRoutes; + // if (!this.$store.state.themeConfig.themeConfig.isCacheTagsView) Session.remove('tagsViewList'); + this.tagsViewRoutesList = this.$store.state.menus.oneLvMenus; this.initTagsViewList(); }, // 存储 tagsViewList 到浏览器临时缓存中,页面刷新时,保留记录 @@ -195,14 +206,17 @@ export default { }, // 初始化设置了 tagsView 数据 initTagsViewList() { - if (Session.get('tagsViewList') && this.$store.state.themeConfig.themeConfig.isCacheTagsView) { - this.tagsViewList = Session.get('tagsViewList'); - } else { - this.tagsViewRoutesList.map((v) => { - if (v.isAffix && !v.isHide) this.tagsViewList.push({ ...v }); - }); - this.addTagsView(this.$route.path); - } + // if (Session.get('tagsViewList') && this.$store.state.themeConfig.themeConfig.isCacheTagsView) { + // this.tagsViewList = Session.get('tagsViewList'); + // } else { + let arr = []; + console.log(this.tagsViewRoutesList); + this.tagsViewRoutesList.map((v) => { + if (v.meta && v.meta.isAffix) arr.push({ ...v }); + }); + // } + console.log(arr); + this.setTagNavList(arr); // 初始化当前元素(li)的下标 this.getTagsRefsIndex(this.$route.path); // 添加初始化横向滚动条移动到对应位置 @@ -224,8 +238,7 @@ export default { this.tagsDropdown.y = clientY; this.$refs.tagsContextmenu.openContextmenu(v); }, - onContextmenuIcon(e) { - }, + onContextmenuIcon(e) {}, // 当前项右键菜单点击 onCurrentContextmenuClick(data) { let { id, path } = data; @@ -417,6 +430,13 @@ export default { // .tags-style-three { // } // // 风格4 + // 风格1 + .tags-style-one { + .is-active { + background: none !important; + color: #fff !important; + } + } // 风格4 .tags-style-four { .layout-navbars-tagsview-ul-li { @@ -436,7 +456,7 @@ export default { } .is-active { background: none !important; - color: var(--prev-bg-menu-hover-ba-color) !important; + color: #fff !important; } } // 风格5 diff --git a/template/admin/src/pages/account/login/index.vue b/template/admin/src/pages/account/login/index.vue index bacf901c9..2caad821c 100644 --- a/template/admin/src/pages/account/login/index.vue +++ b/template/admin/src/pages/account/login/index.vue @@ -213,6 +213,8 @@ export default { this.$store.dispatch('routesList/setRoutesList', data.menus); let arr = formatFlatteningRoutes(this.$router.options.routes); this.formatTwoStageRoutes(arr); + this.$store.commit('menus/setOneLvMenus', arr); + // 记录用户信息 this.$store.commit('userInfo/name', data.user_info.account); this.$store.commit('userInfo/avatar', data.user_info.head_pic); @@ -241,8 +243,7 @@ export default { this.checkSocket(); } catch (e) {} PrevLoading.start(); - - return this.$router.replace({ + return this.$router.push({ path: findFirstNonNullChildren(res.data.menus).path || this.$routeProStr + '/', }); }) diff --git a/template/admin/src/router/modules/index.js b/template/admin/src/router/modules/index.js index 8f4fc111d..62daff1bb 100644 --- a/template/admin/src/router/modules/index.js +++ b/template/admin/src/router/modules/index.js @@ -9,7 +9,7 @@ // +--------------------------------------------------------------------- import LayoutMain from '@/layout'; -import setting from '@/setting' +import setting from '@/setting'; let routePre = setting.routePre; // export default { @@ -52,7 +52,7 @@ export default { component: LayoutMain, children: [ { - path: routePre+'/home', + path: routePre + '/home/', name: `${pre}index`, header: 'home', meta: { diff --git a/template/admin/src/store/module/menus.js b/template/admin/src/store/module/menus.js index 5db25bd7d..8981c82f9 100644 --- a/template/admin/src/store/module/menus.js +++ b/template/admin/src/store/module/menus.js @@ -26,6 +26,7 @@ export default { menusName: getMenusName(), openMenus: [], childMenuList: [], + oneLvMenus: [], }, mutations: { getmenusNav(state, menuList) { @@ -37,8 +38,10 @@ export default { setopenMenus(state, openList) { state.openMenus = openList; }, + setOneLvMenus(state, oneLvMenus) { + state.oneLvMenus = oneLvMenus; + }, childMenuList(state, list) { - console.log('bbbbb') state.childMenuList = list; }, },