index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <el-container class="layout-cont" >
  3. <el-container :class="[isSider?'openside':'hideside',isMobile ? 'mobile': '']">
  4. <el-row :class="[isShadowBg?'shadowBg':'']" @click.native="changeShadow()"></el-row>
  5. <el-aside class="main-cont main-left">
  6. <Aside class="aside" />
  7. </el-aside>
  8. <!-- 分块滑动功能 -->
  9. <el-main class="main-cont main-right">
  10. <el-header class="header-cont">
  11. <div @click="totalCollapse" class="menu-total">
  12. <i class="el-icon-s-unfold" v-if="isCollapse"></i>
  13. <i class="el-icon-s-fold" v-else></i>
  14. </div>
  15. <h1 class="admin-title">Gin-Vue-Admin</h1>
  16. <div class="fl-right right-box">
  17. <el-dropdown>
  18. <span class="el-dropdown-link">
  19. <img :src="userInfo.headerImg" height="30" width="30" />
  20. {{userInfo.nickName}}
  21. <i class="el-icon-arrow-down"></i>
  22. </span>
  23. <el-dropdown-menu class="dropdown-group" slot="dropdown">
  24. <el-dropdown-item>
  25. <span>
  26. 更多信息
  27. <el-badge is-dot />
  28. </span>
  29. </el-dropdown-item>
  30. <el-dropdown-item @click.native="toPerson" icon="el-icon-s-custom">个人信息</el-dropdown-item>
  31. <el-dropdown-item @click.native="LoginOut" icon="el-icon-table-lamp">登 出</el-dropdown-item>
  32. </el-dropdown-menu>
  33. </el-dropdown>
  34. </div>
  35. </el-header>
  36. <!-- 当前面包屑用路由自动生成可根据需求修改 -->
  37. <!--
  38. :to="{ path: item.path }" 暂时注释不用-->
  39. <el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
  40. <el-breadcrumb-item
  41. :key="item.path"
  42. v-for="item in matched.slice(1,matched.length)"
  43. >{{item.meta.title}}</el-breadcrumb-item>
  44. </el-breadcrumb>
  45. <transition mode="out-in" name="el-fade-in-linear">
  46. <router-view class="admin-box"></router-view>
  47. </transition>
  48. </el-main>
  49. </el-container>
  50. </el-container>
  51. </template>
  52. <script>
  53. import Aside from '@/view/layout/aside'
  54. import { mapGetters, mapActions } from 'vuex'
  55. export default {
  56. name: 'Layout',
  57. data() {
  58. return {
  59. isCollapse: false,
  60. isSider: true,
  61. isMobile: false,
  62. isShadowBg: false
  63. }
  64. },
  65. components: {
  66. Aside
  67. },
  68. created(){
  69. let screenWidth = document.body.clientWidth
  70. if(screenWidth<1000){
  71. this.isMobile = true
  72. this.isSider = false
  73. this.isCollapse = !this.isCollapse
  74. }else{
  75. this.isMobile = false
  76. }
  77. },
  78. methods: {
  79. ...mapActions('user', ['LoginOut']),
  80. totalCollapse() {
  81. this.isCollapse = !this.isCollapse
  82. this.isSider = !this.isCollapse
  83. this.isShadowBg = !this.isCollapse
  84. this.$bus.emit('totalCollapse')
  85. },
  86. toPerson() {
  87. this.$router.push({ name: 'person' })
  88. },
  89. changeShadow(){
  90. this.isShadowBg = !this.isShadowBg
  91. this.isSider = !!this.isCollapse
  92. this.totalCollapse()
  93. }
  94. },
  95. computed: {
  96. ...mapGetters('user', ['userInfo']),
  97. title() {
  98. return this.$route.meta.title || '当前页面'
  99. },
  100. matched() {
  101. return this.$route.matched
  102. }
  103. },
  104. mounted() {
  105. window.onresize = () => {
  106. return (() => {
  107. let screenWidth = document.body.clientWidth
  108. if(!this.screenWidth && this.isSider){
  109. if(screenWidth < 1000){
  110. this.isMobile = true
  111. this.isSider = false
  112. this.isCollapse = true
  113. this.$bus.emit('collapse',this.isCollapse)
  114. }
  115. }else {
  116. if(screenWidth < 1000){
  117. this.isMobile = true
  118. this.isSider = false
  119. this.isCollapse = true
  120. } else {
  121. this.isMobile = false
  122. }
  123. }
  124. })()
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss">
  130. $headerHigh: 52px;
  131. $mainHight: 100vh;
  132. .el-dropdown-link {
  133. cursor: pointer;
  134. }
  135. .dropdown-group {
  136. min-width: 100px;
  137. }
  138. .el-scrollbar__wrap {
  139. padding-bottom: 17px;
  140. }
  141. .layout-cont {
  142. .right-box {
  143. text-align: center;
  144. vertical-align: middle;
  145. img {
  146. vertical-align: middle;
  147. border: 1px solid #ccc;
  148. border-radius: 6px;
  149. }
  150. }
  151. .menu-contorl {
  152. line-height: 52px;
  153. font-size: 20px;
  154. color: #eee;
  155. display: table-cell;
  156. vertical-align: middle;
  157. }
  158. .header-cont {
  159. height: $headerHigh !important;
  160. background: #fff;
  161. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  162. line-height: $headerHigh;
  163. }
  164. .main-cont {
  165. .breadcrumb {
  166. line-height: 24px;
  167. // padding: 6px;
  168. // border-bottom: 1px solid #eee;
  169. margin-bottom: 6px;
  170. }
  171. &.el-main {
  172. overflow: auto;
  173. // padding: 0px 10px;
  174. // background: #fff;
  175. }
  176. height: $mainHight !important;
  177. overflow: visible;
  178. position: relative;
  179. .menu-total {
  180. // z-index: 5;
  181. // position: absolute;
  182. // top: 10px;
  183. // right: -35px;
  184. margin-left: -10px;
  185. float: left;
  186. margin-top: 10px;
  187. width: 30px;
  188. height: 30px;
  189. line-height: 30px;
  190. font-size: 30px;
  191. // border: 0 solid #ffffff;
  192. // border-radius: 50%;
  193. // background: #fff;
  194. }
  195. .aside {
  196. overflow: auto;
  197. // background: #fff;
  198. &::-webkit-scrollbar {
  199. display: none;
  200. }
  201. }
  202. .el-menu-vertical {
  203. height: 100vh !important;
  204. visibility: auto;
  205. &:not(.el-menu--collapse) {
  206. width: 220px;
  207. }
  208. }
  209. &::-webkit-scrollbar {
  210. display: none;
  211. }
  212. &.main-left {
  213. width: auto !important;
  214. }
  215. &.main-right {
  216. .admin-title {
  217. float: left;
  218. font-size: 16px;
  219. vertical-align: middle;
  220. margin-left: 20px;
  221. img {
  222. vertical-align: middle;
  223. }
  224. &.collapse {
  225. width: 53px;
  226. }
  227. }
  228. }
  229. }
  230. }
  231. </style>