a723fd415a160dd4262cbbdb2f92dffdf4af0f1f.svn-base 6.5 KB

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