GlobalHeader.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <!-- , width: fixedHeader ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%' -->
  3. <a-layout-header
  4. v-if="!headerBarFixed"
  5. :class="[fixedHeader && 'ant-header-fixedHeader', sidebarOpened ? 'ant-header-side-opened' : 'ant-header-side-closed', ]"
  6. :style="{ padding: '0' }">
  7. <div v-if="mode === 'sidemenu'" class="header" :class="theme">
  8. <a-icon
  9. v-if="device==='mobile'"
  10. class="trigger"
  11. :type="collapsed ? 'menu-fold' : 'menu-unfold'"
  12. @click="toggle"></a-icon>
  13. <a-icon
  14. v-else
  15. class="trigger"
  16. :type="collapsed ? 'menu-unfold' : 'menu-fold'"
  17. @click="toggle"/>
  18. <span v-if="device === 'desktop'">
  19. <!-- 欢迎进入 Jeecg-Boot 企业级快速开发平台 -->
  20. </span>
  21. <span v-else>
  22. <!-- Jeecg-Boot -->
  23. </span>
  24. <user-menu :theme="theme"/>
  25. </div>
  26. <!-- 顶部导航栏模式 -->
  27. <div v-else :class="['top-nav-header-index', theme]">
  28. <div class="header-index-wide">
  29. <div class="header-index-left" :style="topMenuStyle.headerIndexLeft">
  30. <logo class="top-nav-header" :show-title="device !== 'mobile'" :style="topMenuStyle.topNavHeader"/>
  31. <div v-if="device !== 'mobile'" :style="topMenuStyle.topSmenuStyle">
  32. <s-menu
  33. mode="horizontal"
  34. :menu="menus"
  35. :theme="theme"></s-menu>
  36. </div>
  37. <a-icon
  38. v-else
  39. class="trigger"
  40. :type="collapsed ? 'menu-fold' : 'menu-unfold'"
  41. @click="toggle"></a-icon>
  42. </div>
  43. <user-menu class="header-index-right" :theme="theme" :style="topMenuStyle.headerIndexRight"/>
  44. </div>
  45. </div>
  46. </a-layout-header>
  47. </template>
  48. <script>
  49. import UserMenu from '../tools/UserMenu'
  50. import SMenu from '../menu/'
  51. import Logo from '../tools/Logo'
  52. import { mixin } from '@/utils/mixin.js'
  53. export default {
  54. name: 'GlobalHeader',
  55. components: {
  56. UserMenu,
  57. SMenu,
  58. Logo
  59. },
  60. mixins: [mixin],
  61. props: {
  62. mode: {
  63. type: String,
  64. // sidemenu, topmenu
  65. default: 'sidemenu'
  66. },
  67. menus: {
  68. type: Array,
  69. required: true
  70. },
  71. theme: {
  72. type: String,
  73. required: false,
  74. default: 'dark'
  75. },
  76. collapsed: {
  77. type: Boolean,
  78. required: false,
  79. default: false
  80. },
  81. device: {
  82. type: String,
  83. required: false,
  84. default: 'desktop'
  85. }
  86. },
  87. data() {
  88. return {
  89. headerBarFixed: false,
  90. //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
  91. topMenuStyle: {
  92. headerIndexLeft: {},
  93. topNavHeader: {},
  94. headerIndexRight: {},
  95. topSmenuStyle: {}
  96. }
  97. }
  98. },
  99. watch: {
  100. /** 监听设备变化 */
  101. device() {
  102. if (this.mode === 'topmenu') {
  103. this.buildTopMenuStyle()
  104. }
  105. },
  106. /** 监听导航栏模式变化 */
  107. mode(newVal) {
  108. if (newVal === 'topmenu') {
  109. this.buildTopMenuStyle()
  110. }
  111. }
  112. },
  113. //update-end--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
  114. mounted() {
  115. window.addEventListener('scroll', this.handleScroll)
  116. //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
  117. if (this.mode === 'topmenu') {
  118. this.buildTopMenuStyle()
  119. }
  120. //update-end--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
  121. },
  122. methods: {
  123. handleScroll() {
  124. if (this.autoHideHeader) {
  125. let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
  126. if (scrollTop > 100) {
  127. this.headerBarFixed = true
  128. } else {
  129. this.headerBarFixed = false
  130. }
  131. } else {
  132. this.headerBarFixed = false
  133. }
  134. },
  135. toggle() {
  136. this.$emit('toggle')
  137. },
  138. //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
  139. buildTopMenuStyle() {
  140. if (this.mode === 'topmenu') {
  141. if (this.device === 'mobile') {
  142. // 手机端需要清空样式,否则显示会错乱
  143. this.topMenuStyle.topNavHeader = {}
  144. this.topMenuStyle.topSmenuStyle = {}
  145. this.topMenuStyle.headerIndexRight = {}
  146. this.topMenuStyle.headerIndexLeft = {}
  147. } else {
  148. let rightWidth = '360px'
  149. this.topMenuStyle.topNavHeader = { 'min-width': '165px' }
  150. this.topMenuStyle.topSmenuStyle = { 'width': 'calc(100% - 165px)' }
  151. this.topMenuStyle.headerIndexRight = { 'min-width': rightWidth }
  152. this.topMenuStyle.headerIndexLeft = { 'width': `calc(100% - ${rightWidth})` }
  153. }
  154. }
  155. }
  156. //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
  157. }
  158. }
  159. </script>
  160. <style lang="less" scoped>
  161. /* update_begin author:scott date:20190220 for: 缩小首页布局顶部的高度*/
  162. @height: 59px;
  163. .layout {
  164. .top-nav-header-index {
  165. .header-index-wide {
  166. margin-left: 10px;
  167. .ant-menu.ant-menu-horizontal {
  168. height: @height;
  169. line-height: @height;
  170. }
  171. }
  172. .trigger {
  173. line-height: 64px;
  174. &:hover {
  175. background: rgba(0, 0, 0, 0.05);
  176. }
  177. }
  178. }
  179. .header {
  180. z-index: 2;
  181. color: white;
  182. height: @height;
  183. background-color: @primary-color;
  184. transition: background 300ms;
  185. /* dark 样式 */
  186. &.dark {
  187. color: #000000;
  188. box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
  189. background-color: white !important;
  190. }
  191. }
  192. .header, .top-nav-header-index {
  193. &.dark .trigger:hover {
  194. background: rgba(0, 0, 0, 0.05);
  195. }
  196. }
  197. }
  198. .ant-layout-header {
  199. height: @height;
  200. line-height: @height;
  201. }
  202. /* update_end author:scott date:20190220 for: 缩小首页布局顶部的高度*/
  203. </style>