Blame view

ant-design-vue-jeecg/src/components/page/GlobalHeader.vue 5.99 KB
肖超群 authored
1
2
3
4
<template>
  <!-- , width: fixedHeader ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'  -->
  <a-layout-header
    v-if="!headerBarFixed"
5
6
7
8
9
10
    :class="[
      fixedHeader && 'ant-header-fixedHeader',
      sidebarOpened ? 'ant-header-side-opened' : 'ant-header-side-closed'
    ]"
    :style="{ padding: '0' }"
  >
肖超群 authored
11
12
    <div v-if="mode === 'sidemenu'" class="header" :class="theme">
      <a-icon
13
        v-if="device === 'mobile'"
肖超群 authored
14
15
        class="trigger"
        :type="collapsed ? 'menu-fold' : 'menu-unfold'"
16
17
18
19
        @click="toggle"
      />
      <a-icon v-else class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="toggle" />
      <user-menu :theme="theme" />
肖超群 authored
20
21
22
23
24
    </div>
    <!-- 顶部导航栏模式 -->
    <div v-else :class="['top-nav-header-index', theme]">
      <div class="header-index-wide">
        <div class="header-index-left" :style="topMenuStyle.headerIndexLeft">
25
          <logo class="top-nav-header" :show-title="device !== 'mobile'" :style="topMenuStyle.topNavHeader" />
肖超群 authored
26
          <div v-if="device !== 'mobile'" :style="topMenuStyle.topSmenuStyle">
27
            <s-menu mode="horizontal" :menu="menus" :theme="theme" @updateMenuTitle="handleUpdateMenuTitle"></s-menu>
肖超群 authored
28
          </div>
29
          <a-icon v-else class="trigger" :type="collapsed ? 'menu-fold' : 'menu-unfold'" @click="toggle"></a-icon>
肖超群 authored
30
        </div>
31
        <user-menu class="header-index-right" :theme="theme" :style="topMenuStyle.headerIndexRight" />
肖超群 authored
32
33
34
35
36
37
      </div>
    </div>
  </a-layout-header>
</template>

<script>
肖超群 authored
38
39
40
import UserMenu from '../tools/UserMenu'
import SMenu from '../menu/'
import Logo from '../tools/Logo'
41
import { mixin } from '@/utils/mixin.js'
肖超群 authored
42
43
44
45
46
47

export default {
  name: 'GlobalHeader',
  components: {
    UserMenu,
    SMenu,
48
    Logo
肖超群 authored
49
50
51
52
53
54
55
  },
  mixins: [mixin],
  props: {
    mode: {
      type: String,
      // sidemenu, topmenu
      default: 'sidemenu'
肖超群 authored
56
    },
肖超群 authored
57
58
59
    menus: {
      type: Array,
      required: true
肖超群 authored
60
    },
肖超群 authored
61
62
63
64
    theme: {
      type: String,
      required: false,
      default: 'dark'
肖超群 authored
65
    },
肖超群 authored
66
67
68
69
    collapsed: {
      type: Boolean,
      required: false,
      default: false
肖超群 authored
70
    },
肖超群 authored
71
72
73
74
75
76
77
78
79
    device: {
      type: String,
      required: false,
      default: 'desktop'
    }
  },
  data() {
    return {
      headerBarFixed: false,
肖超群 authored
80
      //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
肖超群 authored
81
82
83
84
85
86
      topMenuStyle: {
        headerIndexLeft: {},
        topNavHeader: {},
        headerIndexRight: {},
        topSmenuStyle: {}
      },
87
      chatStatus: ''
肖超群 authored
88
89
90
91
92
    }
  },
  watch: {
    /** 监听设备变化 */
    device() {
肖超群 authored
93
94
95
96
      if (this.mode === 'topmenu') {
        this.buildTopMenuStyle()
      }
    },
肖超群 authored
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    /** 监听导航栏模式变化 */
    mode(newVal) {
      if (newVal === 'topmenu') {
        this.buildTopMenuStyle()
      }
    }
  },
  //update-end--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
  mounted() {
    window.addEventListener('scroll', this.handleScroll)
    //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
    if (this.mode === 'topmenu') {
      this.buildTopMenuStyle()
    }
    //update-end--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
  },
  methods: {
    handleScroll() {
      if (this.autoHideHeader) {
        let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
        if (scrollTop > 100) {
          this.headerBarFixed = true
肖超群 authored
119
120
121
        } else {
          this.headerBarFixed = false
        }
肖超群 authored
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
      } else {
        this.headerBarFixed = false
      }
    },
    toggle() {
      this.$emit('toggle')
    },
    //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
    buildTopMenuStyle() {
      if (this.mode === 'topmenu') {
        if (this.device === 'mobile') {
          // 手机端需要清空样式,否则显示会错乱
          this.topMenuStyle.topNavHeader = {}
          this.topMenuStyle.topSmenuStyle = {}
          this.topMenuStyle.headerIndexRight = {}
          this.topMenuStyle.headerIndexLeft = {}
        } else {
          let rightWidth = '400px'
140
141
142
143
          this.topMenuStyle.topNavHeader = { 'min-width': '165px' }
          this.topMenuStyle.topSmenuStyle = { width: 'calc(100% - 165px)' }
          this.topMenuStyle.headerIndexRight = { 'min-width': rightWidth, 'white-space': 'nowrap' }
          this.topMenuStyle.headerIndexLeft = { width: `calc(100% - ${rightWidth})` }
肖超群 authored
144
        }
肖超群 authored
145
146
147
      }
    },
    //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
肖超群 authored
148
肖超群 authored
149
150
151
    // update-begin-author:sunjianlei date:20210508 for: 修复动态功能测试菜单、带参数菜单标题错误、展开错误的问题
    handleUpdateMenuTitle(value) {
      this.$emit('updateMenuTitle', value)
152
    }
肖超群 authored
153
    // update-end-author:sunjianlei date:20210508 for: 修复动态功能测试菜单、带参数菜单标题错误、展开错误的问题
肖超群 authored
154
  }
肖超群 authored
155
}
肖超群 authored
156
157
158
</script>

<style lang="less" scoped>
肖超群 authored
159
/* update_begin author:scott date:20190220 for: 缩小首页布局顶部的高度*/
肖超群 authored
160
肖超群 authored
161
@height: 59px;
肖超群 authored
162
肖超群 authored
163
164
165
166
.layout {
  .top-nav-header-index {
    .header-index-wide {
      margin-left: 10px;
肖超群 authored
167
肖超群 authored
168
169
170
      .ant-menu.ant-menu-horizontal {
        height: @height;
        line-height: @height;
肖超群 authored
171
172
173
      }
    }
肖超群 authored
174
175
    .trigger {
      line-height: 64px;
肖超群 authored
176
肖超群 authored
177
      &:hover {
肖超群 authored
178
179
180
181
182
        background: rgba(0, 0, 0, 0.05);
      }
    }
  }
肖超群 authored
183
184
185
  .header {
    z-index: 2;
    color: white;
肖超群 authored
186
    height: @height;
肖超群 authored
187
188
189
190
191
192
193
194
195
196
    background-color: @primary-color;
    transition: background 300ms;

    /* dark 样式 */

    &.dark {
      color: #000000;
      box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
      background-color: white !important;
    }
肖超群 authored
197
198
  }
199
200
  .header,
  .top-nav-header-index {
肖超群 authored
201
202
203
204
205
206
207
208
209
210
211
212
    &.dark .trigger:hover {
      background: rgba(0, 0, 0, 0.05);
    }
  }
}

.ant-layout-header {
  height: @height;
  line-height: @height;
}

/* update_end author:scott date:20190220 for: 缩小首页布局顶部的高度*/
肖超群 authored
213
</style>