index.vue 8.8 KB

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