index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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()" />
  5. <el-aside class="main-cont main-left">
  6. <div class="tilte" :style="{background: backgroundColor}">
  7. <img alt class="logoimg" :src="$GIN_VUE_ADMIN.appLogo">
  8. <h2 v-if="isSider" class="tit-text" :style="{color:textColor}">{{ $GIN_VUE_ADMIN.appName }}</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 class="menu-total" @click="totalCollapse">
  24. <i v-if="isCollapse" class="el-icon-s-unfold" />
  25. <i v-else class="el-icon-s-fold" />
  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. v-for="item in matched.slice(1,matched.length)"
  32. :key="item.path"
  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'}" />
  40. <el-dropdown>
  41. <span class="header-avatar" style="cursor: pointer">
  42. <CustomPic />
  43. <span style="margin-left: 5px">{{ userInfo.nickName }}</span>
  44. <i class="el-icon-arrow-down" />
  45. </span>
  46. <el-dropdown-menu slot="dropdown" class="dropdown-group">
  47. <el-dropdown-item>
  48. <span style="font-weight: 600;">
  49. 当前角色:{{ userInfo.authority.authorityName }}
  50. </span>
  51. </el-dropdown-item>
  52. <template v-if="userInfo.authorities">
  53. <el-dropdown-item v-for="item in userInfo.authorities.filter(i=>i.authorityId!==userInfo.authorityId)" :key="item.authorityId" @click.native="changeUserAuth(item.authorityId)">
  54. <span>
  55. 切换为:{{ item.authorityName }}
  56. </span>
  57. </el-dropdown-item>
  58. </template>
  59. <el-dropdown-item icon="el-icon-s-custom" @click.native="toPerson">个人信息</el-dropdown-item>
  60. <el-dropdown-item icon="el-icon-table-lamp" @click.native="LoginOut">登 出</el-dropdown-item>
  61. </el-dropdown-menu>
  62. </el-dropdown>
  63. </div>
  64. </el-col>
  65. </el-header>
  66. </el-row>
  67. <!-- 当前面包屑用路由自动生成可根据需求修改 -->
  68. <!--
  69. :to="{ path: item.path }" 暂时注释不用-->
  70. <HistoryComponent />
  71. </div>
  72. </transition>
  73. <transition mode="out-in" name="el-fade-in-linear">
  74. <keep-alive>
  75. <router-view v-if="$route.meta.keepAlive && reloadFlag" v-loading="loadingFlag" element-loading-text="正在加载中" class="admin-box" />
  76. </keep-alive>
  77. </transition>
  78. <transition mode="out-in" name="el-fade-in-linear">
  79. <router-view v-if="!$route.meta.keepAlive && reloadFlag" v-loading="loadingFlag" element-loading-text="正在加载中" class="admin-box" />
  80. </transition>
  81. <BottomInfo />
  82. <setting />
  83. </el-main>
  84. </el-container>
  85. </el-container>
  86. </template>
  87. <script>
  88. import Aside from '@/view/layout/aside'
  89. import HistoryComponent from '@/view/layout/aside/historyComponent/history'
  90. import Screenfull from '@/view/layout/screenfull'
  91. import Search from '@/view/layout/search/search'
  92. import BottomInfo from '@/view/layout/bottomInfo/bottomInfo'
  93. import { mapGetters, mapActions } from 'vuex'
  94. import CustomPic from '@/components/customPic'
  95. import Setting from './setting'
  96. import { setUserAuthority } from '@/api/user'
  97. export default {
  98. name: 'Layout',
  99. components: {
  100. Aside,
  101. HistoryComponent,
  102. Screenfull,
  103. Search,
  104. BottomInfo,
  105. CustomPic,
  106. Setting
  107. },
  108. data() {
  109. return {
  110. show: false,
  111. isCollapse: false,
  112. isSider: true,
  113. isMobile: false,
  114. isShadowBg: false,
  115. loadingFlag: false,
  116. reloadFlag: true,
  117. value: ''
  118. }
  119. },
  120. computed: {
  121. ...mapGetters('user', ['userInfo', 'sideMode', 'baseColor']),
  122. textColor() {
  123. if (this.$store.getters['user/sideMode'] === 'dark') {
  124. return '#fff'
  125. } else if (this.$store.getters['user/sideMode'] === 'light') {
  126. return '#191a23'
  127. } else {
  128. return this.baseColor
  129. }
  130. },
  131. backgroundColor() {
  132. if (this.sideMode === 'dark') {
  133. return '#191a23'
  134. } else if (this.sideMode === 'light') {
  135. return '#fff'
  136. } else {
  137. return this.sideMode
  138. }
  139. },
  140. title() {
  141. return this.$route.meta.title || '当前页面'
  142. },
  143. matched() {
  144. return this.$route.matched
  145. }
  146. },
  147. mounted() {
  148. const screenWidth = document.body.clientWidth
  149. if (screenWidth < 1000) {
  150. this.isMobile = true
  151. this.isSider = false
  152. this.isCollapse = true
  153. } else if (screenWidth >= 1000 && screenWidth < 1200) {
  154. this.isMobile = false
  155. this.isSider = false
  156. this.isCollapse = true
  157. } else {
  158. this.isMobile = false
  159. this.isSider = true
  160. this.isCollapse = false
  161. }
  162. this.$bus.emit('collapse', this.isCollapse)
  163. this.$bus.emit('mobile', this.isMobile)
  164. this.$bus.on('reload', this.reload)
  165. this.$bus.on('showLoading', () => {
  166. this.loadingFlag = true
  167. })
  168. this.$bus.on('closeLoading', () => {
  169. this.loadingFlag = false
  170. })
  171. window.onresize = () => {
  172. return (() => {
  173. const screenWidth = document.body.clientWidth
  174. if (screenWidth < 1000) {
  175. this.isMobile = true
  176. this.isSider = false
  177. this.isCollapse = true
  178. } else if (screenWidth >= 1000 && screenWidth < 1200) {
  179. this.isMobile = false
  180. this.isSider = false
  181. this.isCollapse = true
  182. } else {
  183. this.isMobile = false
  184. this.isSider = true
  185. this.isCollapse = false
  186. }
  187. this.$bus.emit('collapse', this.isCollapse)
  188. this.$bus.emit('mobile', this.isMobile)
  189. })()
  190. }
  191. },
  192. methods: {
  193. ...mapActions('user', ['LoginOut', 'GetUserInfo']),
  194. async changeUserAuth(id) {
  195. const res = await setUserAuthority({
  196. authorityId: id
  197. })
  198. if (res.code === 0) {
  199. window.location.reload()
  200. }
  201. },
  202. reload() {
  203. this.reloadFlag = false
  204. this.$nextTick(() => {
  205. this.reloadFlag = true
  206. })
  207. },
  208. totalCollapse() {
  209. this.isCollapse = !this.isCollapse
  210. this.isSider = !this.isCollapse
  211. this.isShadowBg = !this.isCollapse
  212. this.$bus.emit('collapse', this.isCollapse)
  213. },
  214. toPerson() {
  215. this.$router.push({ name: 'person' })
  216. },
  217. changeShadow() {
  218. this.isShadowBg = !this.isShadowBg
  219. this.isSider = !!this.isCollapse
  220. this.totalCollapse()
  221. }
  222. }
  223. }
  224. </script>
  225. <style lang="scss">
  226. @import '@/style/mobile.scss';
  227. .dark{
  228. background-color: #191a23 !important;
  229. color: #fff !important;
  230. }
  231. .light{
  232. background-color: #fff !important;
  233. color: #000 !important;
  234. }
  235. </style>