index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. <div class="tilte">
  7. <img alt class="logoimg" src="~@/assets/nav_logo.png" />
  8. <h2 class="tit-text" v-if="isSider">Gin-Vue-Admin</h2>
  9. </div>
  10. <Aside class="aside" />
  11. </el-aside>
  12. <!-- 分块滑动功能 -->
  13. <el-main class="main-cont main-right">
  14. <transition :duration="{ enter: 800, leave: 100 }" mode="out-in" name="el-fade-in-linear">
  15. <div
  16. :style="{width: `calc(100% - ${isMobile?'0px':isCollapse?'54px':'220px'})`}"
  17. class="topfix"
  18. >
  19. <el-row>
  20. <!-- :xs="8" :sm="6" :md="4" :lg="3" :xl="1" -->
  21. <el-header class="header-cont">
  22. <el-col :xs="2" :lg="1" :md="1" :sm="1" :xl="1">
  23. <div @click="totalCollapse" class="menu-total">
  24. <i class="el-icon-s-unfold" v-if="isCollapse"></i>
  25. <i class="el-icon-s-fold" v-else></i>
  26. </div>
  27. </el-col>
  28. <el-col :xs="10" :lg="14" :md='14' :sm="9" :xl="14">
  29. <el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
  30. <el-breadcrumb-item
  31. :key="item.path"
  32. v-for="item in matched.slice(1,matched.length)"
  33. >{{item.meta.title}}</el-breadcrumb-item>
  34. </el-breadcrumb>
  35. </el-col>
  36. <el-col :xs="12" :lg="9" :md="9" :sm="14" :xl="9">
  37. <div class="fl-right right-box">
  38. <Search />
  39. <Screenfull class="screenfull" :style="{cursor:'pointer'}"></Screenfull>
  40. <el-dropdown>
  41. <span class="header-avatar">
  42. <CustomPic/>
  43. <span style="margin-left: 5px">{{userInfo.nickName}}</span>
  44. <i class="el-icon-arrow-down"></i>
  45. </span>
  46. <el-dropdown-menu class="dropdown-group" slot="dropdown">
  47. <el-dropdown-item>
  48. <span>
  49. 更多信息
  50. <el-badge is-dot />
  51. </span>
  52. </el-dropdown-item>
  53. <el-dropdown-item @click.native="toPerson" icon="el-icon-s-custom">个人信息</el-dropdown-item>
  54. <el-dropdown-item @click.native="LoginOut" icon="el-icon-table-lamp">登 出</el-dropdown-item>
  55. </el-dropdown-menu>
  56. </el-dropdown>
  57. </div>
  58. </el-col>
  59. </el-header>
  60. </el-row>
  61. <!-- 当前面包屑用路由自动生成可根据需求修改 -->
  62. <!--
  63. :to="{ path: item.path }" 暂时注释不用-->
  64. <HistoryComponent />
  65. </div>
  66. </transition>
  67. <transition mode="out-in" name="el-fade-in-linear">
  68. <keep-alive>
  69. <router-view :key="$route.fullPath" v-loading="loadingFlag" element-loading-text="正在加载中" class="admin-box" v-if="$route.meta.keepAlive && reloadFlag"></router-view>
  70. </keep-alive>
  71. </transition>
  72. <transition mode="out-in" name="el-fade-in-linear">
  73. <router-view :key="$route.fullPath" v-loading="loadingFlag" element-loading-text="正在加载中" class="admin-box" v-if="!$route.meta.keepAlive && reloadFlag"></router-view>
  74. </transition>
  75. <BottomInfo />
  76. </el-main>
  77. </el-container>
  78. </el-container>
  79. </template>
  80. <script>
  81. import Aside from '@/view/layout/aside'
  82. import HistoryComponent from '@/view/layout/aside/historyComponent/history'
  83. import Screenfull from '@/view/layout/screenfull'
  84. import Search from '@/view/layout/search/search'
  85. import BottomInfo from '@/view/layout/bottomInfo/bottomInfo'
  86. import { mapGetters, mapActions } from 'vuex'
  87. import CustomPic from '@/components/customPic'
  88. export default {
  89. name: 'Layout',
  90. data() {
  91. return {
  92. show: false,
  93. isCollapse: false,
  94. isSider: true,
  95. isMobile: false,
  96. isShadowBg: false,
  97. loadingFlag:false,
  98. reloadFlag:true,
  99. value: ''
  100. }
  101. },
  102. components: {
  103. Aside,
  104. HistoryComponent,
  105. Screenfull,
  106. Search,
  107. BottomInfo,
  108. CustomPic
  109. },
  110. methods: {
  111. ...mapActions('user', ['LoginOut']),
  112. reload(){
  113. this.reloadFlag = false
  114. this.$nextTick(()=>{
  115. this.reloadFlag = true
  116. })
  117. },
  118. totalCollapse() {
  119. this.isCollapse = !this.isCollapse
  120. this.isSider = !this.isCollapse
  121. this.isShadowBg = !this.isCollapse
  122. this.$bus.emit('collapse', this.isCollapse)
  123. },
  124. toPerson() {
  125. this.$router.push({ name: 'person' })
  126. },
  127. changeShadow() {
  128. this.isShadowBg = !this.isShadowBg
  129. this.isSider = !!this.isCollapse
  130. this.totalCollapse()
  131. },
  132. },
  133. computed: {
  134. ...mapGetters('user', ['userInfo']),
  135. title() {
  136. return this.$route.meta.title || '当前页面'
  137. },
  138. matched() {
  139. return this.$route.matched
  140. }
  141. },
  142. mounted() {
  143. let screenWidth = document.body.clientWidth
  144. if (screenWidth < 1000) {
  145. this.isMobile = true
  146. this.isSider = false
  147. this.isCollapse = true
  148. } else if (screenWidth >= 1000 && screenWidth < 1200) {
  149. this.isMobile = false
  150. this.isSider = false
  151. this.isCollapse = true
  152. } else {
  153. this.isMobile = false
  154. this.isSider = true
  155. this.isCollapse = false
  156. }
  157. this.$bus.emit('collapse', this.isCollapse)
  158. this.$bus.emit('mobile', this.isMobile)
  159. this.$bus.on("reload",this.reload)
  160. this.$bus.on("showLoading",()=>{
  161. this.loadingFlag = true
  162. })
  163. this.$bus.on("closeLoading",()=>{
  164. this.loadingFlag = false
  165. })
  166. window.onresize = () => {
  167. return (() => {
  168. let screenWidth = document.body.clientWidth
  169. if (screenWidth < 1000) {
  170. this.isMobile = true
  171. this.isSider = false
  172. this.isCollapse = true
  173. } else if (screenWidth >= 1000 && screenWidth < 1200) {
  174. this.isMobile = false
  175. this.isSider = false
  176. this.isCollapse = true
  177. } else {
  178. this.isMobile = false
  179. this.isSider = true
  180. this.isCollapse = false
  181. }
  182. this.$bus.emit('collapse', this.isCollapse)
  183. this.$bus.emit('mobile', this.isMobile)
  184. })()
  185. }
  186. }
  187. }
  188. </script>
  189. <style lang="scss">
  190. @import '@/style/mobile.scss';
  191. // $headerHigh: 52px;
  192. // $mainHight: 100vh;
  193. // .dropdown-group {
  194. // min-width: 100px;
  195. // }
  196. // .topfix {
  197. // position: fixed;
  198. // top: 0;
  199. // box-sizing: border-box;
  200. // z-index: 999;
  201. // }
  202. // .admin-box {
  203. // min-height: calc(100vh - 240px);
  204. // background-color: rgb(255, 255, 255);
  205. // margin-top: 100px;
  206. // }
  207. // .el-scrollbar__wrap {
  208. // padding-bottom: 17px;
  209. // }
  210. // .layout-cont {
  211. // .right-box {
  212. // text-align: center;
  213. // vertical-align: middle;
  214. // img {
  215. // vertical-align: middle;
  216. // border: 1px solid #ccc;
  217. // border-radius: 6px;
  218. // }
  219. // }
  220. // .header-cont {
  221. // height: $headerHigh !important;
  222. // background: #fff;
  223. // box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  224. // line-height: $headerHigh;
  225. // }
  226. // .main-cont {
  227. // .breadcrumb {
  228. // line-height: 48px;
  229. // display: inline-block;
  230. // padding: 0 24px;
  231. // // padding: 6px;
  232. // // border-bottom: 1px solid #eee;
  233. // }
  234. // &.el-main {
  235. // overflow: auto;
  236. // background: #fff;
  237. // // padding: 0px 10px;
  238. // // background: #fff;
  239. // }
  240. // height: $mainHight !important;
  241. // overflow: visible;
  242. // position: relative;
  243. // .menu-total {
  244. // // z-index: 5;
  245. // // position: absolute;
  246. // // top: 10px;
  247. // // right: -35px;
  248. // margin-left: -10px;
  249. // float: left;
  250. // margin-top: 10px;
  251. // width: 30px;
  252. // height: 30px;
  253. // line-height: 30px;
  254. // font-size: 30px;
  255. // // border: 0 solid #ffffff;
  256. // // border-radius: 50%;
  257. // // background: #fff;
  258. // }
  259. // .aside {
  260. // overflow: auto;
  261. // // background: #fff;
  262. // &::-webkit-scrollbar {
  263. // display: none;
  264. // }
  265. // }
  266. // .el-menu-vertical {
  267. // height: calc(100vh - 64px) !important;
  268. // visibility: auto;
  269. // &:not(.el-menu--collapse) {
  270. // width: 220px;
  271. // }
  272. // }
  273. // .el-menu--collapse {
  274. // width: 54px;
  275. // li {
  276. // .el-tooltip,
  277. // .el-submenu__title {
  278. // padding: 0px 15px !important;
  279. // }
  280. // }
  281. // }
  282. // &::-webkit-scrollbar {
  283. // display: none;
  284. // }
  285. // &.main-left {
  286. // width: auto !important;
  287. // }
  288. // &.main-right {
  289. // .admin-title {
  290. // float: left;
  291. // font-size: 16px;
  292. // vertical-align: middle;
  293. // margin-left: 20px;
  294. // img {
  295. // vertical-align: middle;
  296. // }
  297. // &.collapse {
  298. // width: 53px;
  299. // }
  300. // }
  301. // }
  302. // }
  303. // }
  304. // .tilte {
  305. // background: #001529;
  306. // min-height: 64px;
  307. // line-height: 64px;
  308. // background: #002140;
  309. // text-align: center;
  310. // .logoimg {
  311. // width: 30px;
  312. // height: 30px;
  313. // vertical-align: middle;
  314. // background: #fff;
  315. // border-radius: 50%;
  316. // padding: 3px;
  317. // }
  318. // .tit-text {
  319. // display: inline-block;
  320. // color: #fff;
  321. // font-weight: 600;
  322. // font-size: 20px;
  323. // vertical-align: middle;
  324. // }
  325. // }
  326. // .screenfull {
  327. // display: inline-block;
  328. // }
  329. // .header-avatar{
  330. // display: flex;
  331. // justify-content: center;
  332. // align-items: center;
  333. // }
  334. </style>