Blame view

ant-design-vue-jeecg/src/components/page/GlobalHeader.vue 6.11 KB
1
2
<template>
  <!-- , width: fixedHeader ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'  -->
3
4
5
6
7
8
  <a-layout-header
    v-if="!headerBarFixed"
    :class="[fixedHeader && 'ant-header-fixedHeader', sidebarOpened ? 'ant-header-side-opened' : 'ant-header-side-closed', ]"
    :style="{ padding: '0' }">

    <div v-if="mode === 'sidemenu'" class="header" :class="theme">
9
10
11
12
      <a-icon
        v-if="device==='mobile'"
        class="trigger"
        :type="collapsed ? 'menu-fold' : 'menu-unfold'"
13
        @click="toggle"></a-icon>
14
15
16
17
      <a-icon
        v-else
        class="trigger"
        :type="collapsed ? 'menu-unfold' : 'menu-fold'"
18
        @click="toggle"/>
19
20
21
22
23

      <span v-if="device === 'desktop'">欢迎进入 Jeecg-Boot 企业级快速开发平台</span>
      <span v-else>Jeecg-Boot</span>

      <user-menu :theme="theme"/>
24
    </div>
25
    <!-- 顶部导航栏模式 -->
26
27
    <div v-else :class="['top-nav-header-index', theme]">
      <div class="header-index-wide">
28
29
        <div class="header-index-left" :style="topMenuStyle.headerIndexLeft">
          <logo class="top-nav-header" :show-title="device !== 'mobile'" :style="topMenuStyle.topNavHeader"/>
30
31
32
33
34
          <div v-if="device !== 'mobile'" :style="topMenuStyle.topSmenuStyle">
            <s-menu
              mode="horizontal"
              :menu="menus"
              :theme="theme"></s-menu>
35
          </div>
36
37
38
39
          <a-icon
            v-else
            class="trigger"
            :type="collapsed ? 'menu-fold' : 'menu-unfold'"
40
            @click="toggle"></a-icon>
41
        </div>
42
        <user-menu class="header-index-right" :theme="theme" :style="topMenuStyle.headerIndexRight"/>
43
44
45
46
47
48
49
50
51
52
53
54
55
56
      </div>
    </div>

  </a-layout-header>
</template>

<script>
  import UserMenu from '../tools/UserMenu'
  import SMenu from '../menu/'
  import Logo from '../tools/Logo'

  import { mixin } from '@/utils/mixin.js'

  export default {
57
    name: 'GlobalHeader',
58
59
60
    components: {
      UserMenu,
      SMenu,
61
      Logo,
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    },
    mixins: [mixin],
    props: {
      mode: {
        type: String,
        // sidemenu, topmenu
        default: 'sidemenu'
      },
      menus: {
        type: Array,
        required: true
      },
      theme: {
        type: String,
        required: false,
        default: 'dark'
      },
      collapsed: {
        type: Boolean,
        required: false,
        default: false
      },
      device: {
        type: String,
        required: false,
        default: 'desktop'
      }
    },
    data() {
      return {
        headerBarFixed: false,
93
        //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
94
95
96
97
        topMenuStyle: {
          headerIndexLeft: {},
          topNavHeader: {},
          headerIndexRight: {},
98
          topSmenuStyle: {}
99
100
        },
        chatStatus: '',
101
102
      }
    },
103
104
105
106
107
108
109
110
111
112
    watch: {
      /** 监听设备变化 */
      device() {
        if (this.mode === 'topmenu') {
          this.buildTopMenuStyle()
        }
      },
      /** 监听导航栏模式变化 */
      mode(newVal) {
        if (newVal === 'topmenu') {
113
          this.buildTopMenuStyle()
114
115
116
        }
      }
    },
117
    //update-end--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
118
    mounted() {
119
      window.addEventListener('scroll', this.handleScroll)
120
      //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
121
122
123
      if (this.mode === 'topmenu') {
        this.buildTopMenuStyle()
      }
124
      //update-end--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
125
126
    },
    methods: {
127
      handleScroll() {
128
129
130
131
132
133
134
135
136
137
138
139
140
        if (this.autoHideHeader) {
          let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
          if (scrollTop > 100) {
            this.headerBarFixed = true
          } else {
            this.headerBarFixed = false
          }
        } else {
          this.headerBarFixed = false
        }
      },
      toggle() {
        this.$emit('toggle')
141
      },
142
      //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
143
144
145
146
147
      buildTopMenuStyle() {
        if (this.mode === 'topmenu') {
          if (this.device === 'mobile') {
            // 手机端需要清空样式,否则显示会错乱
            this.topMenuStyle.topNavHeader = {}
148
            this.topMenuStyle.topSmenuStyle = {}
149
150
151
152
153
            this.topMenuStyle.headerIndexRight = {}
            this.topMenuStyle.headerIndexLeft = {}
          } else {
            let rightWidth = '360px'
            this.topMenuStyle.topNavHeader = { 'min-width': '165px' }
154
            this.topMenuStyle.topSmenuStyle = { 'width': 'calc(100% - 165px)' }
155
156
157
158
            this.topMenuStyle.headerIndexRight = { 'min-width': rightWidth }
            this.topMenuStyle.headerIndexLeft = { 'width': `calc(100% - ${rightWidth})` }
          }
        }
159
      }
160
      //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
161
162
163
164
    }
  }
</script>
165
<style lang="less" scoped>
166
  /* update_begin author:scott date:20190220 for: 缩小首页布局顶部的高度*/
167
168
  @height: 59px;
169
170
171
172
173
174
175
176
177

  .layout {

    .top-nav-header-index {

      .header-index-wide {
        margin-left: 10px;

        .ant-menu.ant-menu-horizontal {
178
179
          height: @height;
          line-height: @height;
180
181
182
183
184
185
186
187
188
189
190
191
192
        }
      }
      .trigger {
        line-height: 64px;
        &:hover {
          background: rgba(0, 0, 0, 0.05);
        }
      }
    }

    .header {
      z-index: 2;
      color: white;
193
194
      height: @height;
      background-color: @primary-color;
195
196
197
198
199
200
      transition: background 300ms;

      /* dark 样式 */
      &.dark {
        color: #000000;
        box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
201
        background-color: white !important;
202
203
204
205
206
207
208
209
      }
    }

    .header, .top-nav-header-index {
      &.dark .trigger:hover {
        background: rgba(0, 0, 0, 0.05);
      }
    }
210
  }
211
212
  .ant-layout-header {
213
214
    height: @height;
    line-height: @height;
215
  }
216
217
  /* update_end author:scott date:20190220 for: 缩小首页布局顶部的高度*/
218
219
</style>