GlobalHeader.vue 7.3 KB

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