| | |
| | | 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, { |
| | |
| | | router, |
| | | store, |
| | | computed: { |
| | | ...mapState(['userInfo', 'homePage']) |
| | | ...mapState(['userInfo', 'homePage','topMenuCurrent','menuData']) |
| | | }, |
| | | watch: { |
| | | async userInfo () { |
| | |
| | | } |
| | | }, |
| | | methods: { |
| | | ...mapMutations(['switchCollapseMenu', 'setHomePage']), |
| | | ...mapMutations(['switchCollapseMenu', 'setHomePage', 'setTopMenuCurrent', 'setTopMenuCurrent']), |
| | | // 初始化本地配置 |
| | | initLocalConfig () { |
| | | // 菜单状态配置 |
| | |
| | | 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 |
| | | topList.forEach(item => { |
| | | if (item.linkType === 0 && topCurrent == null) { |
| | | topCurrent = item |
| | | } |
| | | }) |
| | | this.setTopMenuCurrent(topCurrent) |
| | | // 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) |
| | | // 404 |