Base.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="home">
  3. <el-container>
  4. <el-header>
  5. <div class="space_between_in base_head">
  6. <topNav :iconFlag="iconFlag" @getUnpack="getUnpack"></topNav>
  7. <UserInfo></UserInfo>
  8. </div>
  9. </el-header>
  10. <el-container>
  11. <el-aside :width="sideWidth+'px'">
  12. <div class="card_aside">
  13. <div class="card_menu">
  14. <el-menu :collapse="iconFlag" :default-active="activePath" class="el-menu-vertical-demo" router
  15. :collapse-transition="false" @open="handleOpen" @close="handleClose">
  16. <template v-for="(item,index) in menus">
  17. <el-menu-item class="menu_item" :index="item.path" :key="index" @click="saveNavState(item.path)">
  18. <i :class="item.meta.icon" class="menu_icon iconfont"></i>
  19. <span slot="title">{{item.meta.title}}</span>
  20. </el-menu-item>
  21. </template>
  22. </el-menu>
  23. </div>
  24. <div class="card_support" v-if="!iconFlag">
  25. <span>技术服务:宝智达科技</span>
  26. <span style="margin-top: 5px;">服务电话:400-600-0968</span>
  27. </div>
  28. </div>
  29. </el-aside>
  30. <el-main>
  31. <div class="main">
  32. <router-view></router-view>
  33. </div>
  34. </el-main>
  35. </el-container>
  36. </el-container>
  37. </div>
  38. </template>
  39. <script>
  40. import {
  41. mapState
  42. } from 'vuex'
  43. import topNav from './topNav.vue'
  44. import UserInfo from './userInfo.vue'
  45. export default {
  46. name: 'BaseView',
  47. components: {
  48. topNav,
  49. UserInfo
  50. },
  51. data() {
  52. return {
  53. menus: [],
  54. // 被激活的链接地址
  55. activePath: '',
  56. iconFlag: false,
  57. sideWidth: 200,
  58. }
  59. },
  60. computed: {
  61. ...mapState({
  62. // 动态主路由
  63. mainMenu: state => state.permission.menu
  64. })
  65. },
  66. created() {
  67. this.activePath = localStorage.getItem('activePath')
  68. this.getLeftMenu()
  69. },
  70. methods: {
  71. getLeftMenu() {
  72. const mRoutes = this.$store.state.permission.menu;
  73. let mRoutesList = []
  74. mRoutes.forEach(item => {
  75. if (item.name == 'index') {
  76. mRoutesList = item.children
  77. }
  78. })
  79. this.menus = getpath(mRoutesList, '')
  80. function getpath(routerMap, parent) {
  81. routerMap.map(item => {
  82. item.path = `${(parent.path) || ''}/${item.name}`
  83. if (item.children && item.children.length > 0) {
  84. return getpath(item.children, item)
  85. }
  86. })
  87. return routerMap
  88. }
  89. },
  90. handleOpen(key, keyPath) {
  91. // console.log(key, keyPath);
  92. },
  93. handleClose(key, keyPath) {
  94. // console.log(key, keyPath);
  95. },
  96. // 保存链接的激活状态
  97. saveNavState(activePath) {
  98. localStorage.setItem("activePath", activePath);
  99. this.activePath = activePath
  100. },
  101. // 展开收起
  102. getUnpack(flag) {
  103. if (flag) {
  104. this.iconFlag = false
  105. this.sideWidth = 200
  106. } else {
  107. this.iconFlag = true
  108. this.sideWidth = 64
  109. }
  110. }
  111. }
  112. }
  113. </script>
  114. <style>
  115. .el-main {
  116. padding: 20px 20px;
  117. height: calc(100vh - 60px);
  118. }
  119. </style>
  120. <style lang="scss" scoped>
  121. ::v-deep .el-aside {
  122. transition: width 0.15s;
  123. -webkit-transition: width 0.15s;
  124. -moz-transition: width 0.15s;
  125. -webkit-transition: width 0.15s;
  126. -o-transition: width 0.15s;
  127. }
  128. ::v-deep .el-container {
  129. height: calc(100vh - 1px);
  130. }
  131. .el-header {
  132. box-shadow: 0 5px 10px -2px #dfe5f8;
  133. z-index: 2;
  134. }
  135. .base_head {
  136. height: 100%;
  137. }
  138. .card_aside {
  139. height: calc(100% - 20px);
  140. display: flex;
  141. flex-direction: column;
  142. justify-content: space-between;
  143. padding-top: 20px;
  144. }
  145. .el-menu-vertical-demo {
  146. border-right: none !important;
  147. }
  148. .menu_item {
  149. display: flex;
  150. align-items: center;
  151. }
  152. .menu_icon {
  153. font-size: 22px !important;
  154. margin-right: 10px;
  155. }
  156. .card_support {
  157. display: flex;
  158. flex-direction: column;
  159. align-items: flex-start;
  160. margin-bottom: 10px;
  161. color: rgb(204, 204, 204);
  162. padding-left: 20px;
  163. span {
  164. font-size: 14px;
  165. }
  166. }
  167. ::v-deep .el-main {
  168. background: #fcfbff;
  169. }
  170. .main {
  171. height: 100%;
  172. }
  173. </style>