GlobalHeader.vue 6.8 KB

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