From bff05c941230c57f0a1ed8d0e3c4f9c7b2b8af13 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期二, 11 十一月 2025 16:40:14 +0800
Subject: [PATCH] 优化
---
admin/src/main.js | 68 +++++++++++++++++++++++++++++++---
1 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/admin/src/main.js b/admin/src/main.js
index ec668b6..dc697c7 100644
--- a/admin/src/main.js
+++ b/admin/src/main.js
@@ -12,7 +12,13 @@
import plugins from './plugins'
import { mapState, mapMutations } from 'vuex'
import { fetchMenuTree } from './api/system/menu'
+import preventReClick from '@/directives/directive'
+import Treeselect from '@riophae/vue-treeselect'
+import '@riophae/vue-treeselect/dist/vue-treeselect.css'
+Vue.component('treeselect', Treeselect)
+
+Vue.use(preventReClick)
Vue.config.productionTip = false
Vue.use(ElementUI, {
size: 'small'
@@ -32,7 +38,7 @@
router,
store,
computed: {
- ...mapState(['userInfo', 'homePage'])
+ ...mapState(['userInfo', 'homePage','topMenuCurrent','menuData'])
},
watch: {
async userInfo () {
@@ -40,10 +46,16 @@
return
}
await this.initRoutes()
+ },
+ async topMenuCurrent () {
+ if (this.topMenuCurrent == null) {
+ return
+ }
+ await this.chagneRoutes()
}
},
methods: {
- ...mapMutations(['switchCollapseMenu', 'setHomePage']),
+ ...mapMutations(['switchCollapseMenu', 'setCurrentIndex', 'setHomePage', 'setTopMenuCurrent', 'setTopMenuCurrent','cleartagsview']),
// 鍒濆鍖栨湰鍦伴厤缃�
initLocalConfig () {
// 鑿滃崟鐘舵�侀厤缃�
@@ -62,15 +74,47 @@
this.$store.commit('resetMenus')
// 鑾峰彇鑿滃崟
const storeMenus = this.$store.state.menuData.list
+ const storeTopMenus = this.$store.state.topMenuList.list
if (storeMenus.length > 0 && this.homePage == null) {
this.setHomePage(storeMenus[0])
}
await fetchMenuTree()
- .then(menus => {
+ .then(allmenus => {
// 娣诲姞鑿滃崟
- storeMenus.push.apply(storeMenus, menus)
+ var topList = allmenus.filter(item => {
+ return item.type === 1
+ })
+ storeTopMenus.push.apply(storeTopMenus, topList)
+ var topCurrent = null
+ var tlist =[]
+ topList.forEach(item => {
+ if (item.linkType === 0 ) {
+ if (topCurrent == null) {
+ topCurrent = item
+ }
+ tlist.push(...item.children)
+ }
+ })
+ if (this.$route.query && this.$route.query.menuparams) {
+ let menu = topList.filter(item => item.params === this.$route.query.menuparams)
+ this.setTopMenuCurrent(menu[0])
+ this.setCurrentIndex(topList.findIndex(obj => obj.params === this.$route.query.menuparams))
+ } else {
+ this.setTopMenuCurrent(topCurrent)
+ this.setCurrentIndex(0)
+ }
+ // console.log(topList)
+ // var menus = []
+ // topList.forEach(item => {
+ // console.log(topCurrent.id, item.id)
+ // if (item.id == this.topMenuCurrent.id) {
+ // menus = item.children
+ // }
+ // })
+ console.log('menus', this.menuData.list)
+ storeMenus.push.apply(storeMenus, this.menuData.list)
// 娣诲姞璺敱
- this.__addRouters(storeMenus)
+ this.__addRouters(tlist)
// 404
router.addRoute({
path: '*',
@@ -83,7 +127,9 @@
redirect: this.homePage.url
})
// 璺敱鍔犺浇瀹屾垚鍚庯紝濡傛灉璁块棶鐨勬槸/锛岃烦杞嚦鍔ㄦ�佽瘑鍒殑棣栭〉
- if (this.$route.path === '/') {
+ if (this.$route.query && this.$route.query.menuparams) {
+ this.$router.push(topList.filter(item => item.params === this.$route.query.menuparams)[0].homeUrl)
+ } else if (this.$route.path === '/') {
this.$router.push(this.homePage.url)
}
})
@@ -94,6 +140,16 @@
this.loading = false
})
},
+ async chagneRoutes () {
+ // 閲嶇疆鑿滃崟
+ this.cleartagsview('/index')
+ console.log('menus', this.menuData.list)
+ // 娣诲姞璺敱
+ // this.__addRouters(this.menuData.list)
+ if(this.topMenuCurrent.homeUrl){
+ await this.$router.push({path: this.topMenuCurrent.homeUrl, query: {}})
+ }
+ },
// 鏂板缓璺敱
__addRouters (routes, parents = []) {
if (routes == null || routes.length === 0) {
--
Gitblit v1.9.3