Header.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="header">
  3. <!-- 折叠按钮 -->
  4. <div class="collapse-btn" @click="collapseChage">
  5. <i v-if="!collapse" class="el-icon-s-fold"></i>
  6. <i v-else class="el-icon-s-unfold"></i>
  7. </div>
  8. <div class="logo">网站中台</div>
  9. <div class="header-right">
  10. <div class="header-user-con">
  11. <!-- 全屏显示 -->
  12. <div class="btn-fullscreen" @click="handleFullScreen">
  13. <el-tooltip effect="dark" :content="fullscreen ? `取消全屏` : `全屏`" placement="bottom">
  14. <i class="el-icon-rank"></i>
  15. </el-tooltip>
  16. </div>
  17. <!-- 用户头像 -->
  18. <div class="user-avator">
  19. <img :src="headerImg" />
  20. </div>
  21. <!-- 用户名下拉菜单 -->
  22. <el-dropdown class="user-name" trigger="click" @command="handleCommand">
  23. <span class="el-dropdown-link">
  24. {{ (user && user.name) || '' }}
  25. <i class="el-icon-caret-bottom"></i>
  26. </span>
  27. <el-dropdown-menu slot="dropdown">
  28. <el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
  29. </el-dropdown-menu>
  30. </el-dropdown>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import bus from '@l/bus';
  37. import { mapState, createNamespacedHelpers } from 'vuex';
  38. export default {
  39. data() {
  40. return {
  41. collapse: false,
  42. fullscreen: false,
  43. headerImg: require('@f/assets/img/img.jpg'),
  44. };
  45. },
  46. computed: {
  47. ...mapState(['user']),
  48. },
  49. methods: {
  50. // 用户名下拉菜单选择事件
  51. handleCommand(command) {
  52. if (command == 'loginout') {
  53. this.$router.push('/login');
  54. localStorage.removeItem('user');
  55. localStorage.removeItem('token');
  56. sessionStorage.removeItem('params');
  57. sessionStorage.removeItem('userMenu');
  58. }
  59. },
  60. // 侧边栏折叠
  61. collapseChage() {
  62. this.collapse = !this.collapse;
  63. bus.$emit('collapse', this.collapse);
  64. },
  65. // 全屏事件
  66. handleFullScreen() {
  67. let element = document.documentElement;
  68. if (this.fullscreen) {
  69. if (document.exitFullscreen) {
  70. document.exitFullscreen();
  71. } else if (document.webkitCancelFullScreen) {
  72. document.webkitCancelFullScreen();
  73. } else if (document.mozCancelFullScreen) {
  74. document.mozCancelFullScreen();
  75. } else if (document.msExitFullscreen) {
  76. document.msExitFullscreen();
  77. }
  78. } else {
  79. if (element.requestFullscreen) {
  80. element.requestFullscreen();
  81. } else if (element.webkitRequestFullScreen) {
  82. element.webkitRequestFullScreen();
  83. } else if (element.mozRequestFullScreen) {
  84. element.mozRequestFullScreen();
  85. } else if (element.msRequestFullscreen) {
  86. // IE11
  87. element.msRequestFullscreen();
  88. }
  89. }
  90. this.fullscreen = !this.fullscreen;
  91. },
  92. },
  93. mounted() {
  94. if (document.body.clientWidth < 1500) {
  95. this.collapseChage();
  96. }
  97. },
  98. };
  99. </script>
  100. <style scoped>
  101. .header {
  102. position: relative;
  103. box-sizing: border-box;
  104. width: 100%;
  105. height: 60px;
  106. font-size: 22px;
  107. color: #fff;
  108. }
  109. .collapse-btn {
  110. float: left;
  111. padding: 0 21px;
  112. cursor: pointer;
  113. line-height: 60px;
  114. }
  115. .header .logo {
  116. float: left;
  117. width: 250px;
  118. line-height: 60px;
  119. }
  120. .header-right {
  121. float: right;
  122. padding-right: 50px;
  123. }
  124. .header-user-con {
  125. display: flex;
  126. height: 60px;
  127. align-items: center;
  128. }
  129. .btn-fullscreen {
  130. transform: rotate(45deg);
  131. margin-right: 5px;
  132. font-size: 24px;
  133. }
  134. .btn-bell,
  135. .btn-fullscreen {
  136. position: relative;
  137. width: 30px;
  138. height: 30px;
  139. text-align: center;
  140. border-radius: 15px;
  141. cursor: pointer;
  142. }
  143. .btn-bell-badge {
  144. position: absolute;
  145. right: 0;
  146. top: -2px;
  147. width: 8px;
  148. height: 8px;
  149. border-radius: 4px;
  150. background: #f56c6c;
  151. color: #fff;
  152. }
  153. .btn-bell .el-icon-bell {
  154. color: #fff;
  155. }
  156. .user-name {
  157. margin-left: 10px;
  158. }
  159. .user-avator {
  160. margin-left: 20px;
  161. }
  162. .user-avator img {
  163. display: block;
  164. width: 40px;
  165. height: 40px;
  166. border-radius: 50%;
  167. }
  168. .el-dropdown-link {
  169. color: #fff;
  170. cursor: pointer;
  171. }
  172. .el-dropdown-menu__item {
  173. text-align: center;
  174. }
  175. </style>