123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <template>
- <div class="home">
- <el-container>
- <el-header>
- <div class="space_between_in base_head">
- <topNav :iconFlag="iconFlag" @getUnpack="getUnpack"></topNav>
- <UserInfo></UserInfo>
- </div>
- </el-header>
- <el-container>
- <el-aside :width="sideWidth+'px'">
- <div class="card_aside">
- <div class="card_menu">
- <el-menu :collapse="iconFlag" :default-active="activePath" class="el-menu-vertical-demo" router
- :collapse-transition="false" @open="handleOpen" @close="handleClose">
- <template v-for="(item,index) in menus">
- <el-menu-item class="menu_item" :index="item.path" :key="index" @click="saveNavState(item.path)">
- <i :class="item.meta.icon" class="menu_icon iconfont"></i>
- <span slot="title">{{item.meta.title}}</span>
- </el-menu-item>
- </template>
- </el-menu>
- </div>
- <div class="card_support" v-if="!iconFlag">
- <span>技术服务:宝智达科技</span>
- <span style="margin-top: 5px;">服务电话:400-600-0968</span>
- </div>
- </div>
- </el-aside>
- <el-main>
- <div class="main">
- <router-view></router-view>
- </div>
- </el-main>
- </el-container>
- </el-container>
- </div>
- </template>
- <script>
- import {
- mapState
- } from 'vuex'
- import topNav from './topNav.vue'
- import UserInfo from './userInfo.vue'
- export default {
- name: 'BaseView',
- components: {
- topNav,
- UserInfo
- },
- data() {
- return {
- menus: [],
- // 被激活的链接地址
- activePath: '',
- iconFlag: false,
- sideWidth: 200,
- }
- },
- computed: {
- ...mapState({
- // 动态主路由
- mainMenu: state => state.permission.menu
- })
- },
- created() {
- this.activePath = localStorage.getItem('activePath')
- this.getLeftMenu()
- },
- methods: {
- getLeftMenu() {
- const mRoutes = this.$store.state.permission.menu;
- let mRoutesList = []
- mRoutes.forEach(item => {
- if (item.name == 'index') {
- mRoutesList = item.children
- }
- })
- this.menus = getpath(mRoutesList, '')
- function getpath(routerMap, parent) {
- routerMap.map(item => {
- item.path = `${(parent.path) || ''}/${item.name}`
- if (item.children && item.children.length > 0) {
- return getpath(item.children, item)
- }
- })
- return routerMap
- }
- },
- handleOpen(key, keyPath) {
- // console.log(key, keyPath);
- },
- handleClose(key, keyPath) {
- // console.log(key, keyPath);
- },
- // 保存链接的激活状态
- saveNavState(activePath) {
- localStorage.setItem("activePath", activePath);
- this.activePath = activePath
- },
- // 展开收起
- getUnpack(flag) {
- if (flag) {
- this.iconFlag = false
- this.sideWidth = 200
- } else {
- this.iconFlag = true
- this.sideWidth = 64
- }
- }
- }
- }
- </script>
- <style>
- .el-main {
- padding: 20px 20px;
- height: calc(100vh - 60px);
- }
- </style>
- <style lang="scss" scoped>
- ::v-deep .el-aside {
- transition: width 0.15s;
- -webkit-transition: width 0.15s;
- -moz-transition: width 0.15s;
- -webkit-transition: width 0.15s;
- -o-transition: width 0.15s;
- }
- ::v-deep .el-container {
- height: calc(100vh - 1px);
- }
- .el-header {
- box-shadow: 0 5px 10px -2px #dfe5f8;
- z-index: 2;
- }
- .base_head {
- height: 100%;
- }
- .card_aside {
- height: calc(100% - 20px);
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- padding-top: 20px;
- }
- .el-menu-vertical-demo {
- border-right: none !important;
- }
- .menu_item {
- display: flex;
- align-items: center;
- }
- .menu_icon {
- font-size: 22px !important;
- margin-right: 10px;
- }
- .card_support {
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- margin-bottom: 10px;
- color: rgb(204, 204, 204);
- padding-left: 20px;
- span {
- font-size: 14px;
- }
- }
- ::v-deep .el-main {
- background: #fcfbff;
- }
- .main {
- height: 100%;
- }
- </style>
|