peng
2026-03-18 b89df58e3b783f3d718bd85a3e4c6a3bd9ee353c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<template>
  <a-layout-header
    v-if="!headerBarFixed"
    :class="[
      fixedHeader && 'ant-header-fixed-header',
      sidebarOpened ? 'ant-header-side-opened' : 'ant-header-side-closed'
    ]"
    :style="{ padding: '0' }"
  >
    <div v-if="mode === 'side-menu'" class="header">
      <a-icon
        v-if="device === 'mobile'"
        class="trigger"
        :type="collapsed ? 'menu-fold' : 'menu-unfold'"
        @click="toggle"
      ></a-icon>
      <a-icon v-else class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="toggle" />
 
      <!--<span v-if="device === 'desktop'"> 欢迎进入天翼快速开发平台 —— "魔方" </span>-->
      <span v-else>cube</span>
 
      <user-menu />
    </div>
    <!-- 顶部导航栏模式 -->
    <div v-else-if="mode === 'top-menu'" class="top-nav-header-index">
      <div class="header-index-wide">
        <div class="header-index-left" :style="topMenuStyle.headerIndexLeft">
          <logo class="top-nav-header" :show-title="showTitle" :style="topMenuStyle.topNavHeader" />
          <div v-if="device !== 'mobile'" :style="topMenuStyle.topSMenuStyle">
            <s-menu mode="horizontal" :menu="menus"></s-menu>
          </div>
          <a-icon v-else class="trigger" :type="collapsed ? 'menu-fold' : 'menu-unfold'" @click="toggle"></a-icon>
        </div>
        <user-menu class="header-index-right" :style="topMenuStyle.headerIndexRight" />
      </div>
    </div>
  </a-layout-header>
</template>
 
<script>
import { mixin } from '@tievd/cube-block/lib/utils/mixin.js'
import UserMenu from '@/components/tools/UserMenu'
import SMenu from '@/components/menu/index'
import Logo from '@/components/tools/Logo'
import skinLayoutMixin from '@/mixins/skin-layout-mixin'
 
export default {
  name: 'GlobalHeader',
 
  components: {
    UserMenu,
    SMenu,
    Logo
  },
 
  mixins: [mixin, skinLayoutMixin],
 
  props: {
    mode: {
      type: String,
      default: 'side-menu'
    },
    menus: {
      type: Array,
      required: true
    },
    collapsed: {
      type: Boolean,
      required: false,
      default: false
    },
    device: {
      type: String,
      required: false,
      default: 'desktop'
    }
  },
 
  data() {
    return {
      platform_alias: process.env.VUE_APP_PLATFORM_ALIAS,
      headerBarFixed: false,
      //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
      topMenuStyle: {
        headerIndexLeft: {},
        topNavHeader: {},
        headerIndexRight: {},
        topSMenuStyle: {}
      },
      chatStatus: ''
    }
  },
 
  computed: {
    showTitle() {
      return this.device !== 'mobile'
    }
  },
 
  watch: {
    /** 监听设备变化 */
    device() {
      if (this.mode === 'top-menu') {
        this.buildTopMenuStyle()
      }
    },
    /** 监听导航栏模式变化 */
    mode(newVal) {
      if (newVal === 'top-menu') {
        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 === 'top-menu') {
      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
        } else {
          this.headerBarFixed = false
        }
      } else {
        this.headerBarFixed = false
      }
    },
    toggle() {
      this.$emit('toggle')
    },
    //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
    buildTopMenuStyle() {
      if (this.mode === 'top-menu') {
        if (this.device === 'mobile') {
          // 手机端需要清空样式,否则显示会错乱
          this.topMenuStyle.topNavHeader = {}
          this.topMenuStyle.topSMenuStyle = {}
          this.topMenuStyle.headerIndexRight = {}
          this.topMenuStyle.headerIndexLeft = {}
        } else {
          const rightWidth = '380px' // 右侧用户操作栏宽度
          const topNavHeaderWidth = '180px' // 左侧logo和title宽度
          this.topMenuStyle.topNavHeader = { 'min-width': topNavHeaderWidth }
          this.topMenuStyle.topSMenuStyle = { width: `calc(100% - ${topNavHeaderWidth})` }
          this.topMenuStyle.headerIndexRight = { 'min-width': rightWidth }
          this.topMenuStyle.headerIndexLeft = { width: `calc(100% - ${rightWidth})` }
        }
      }
    }
    //update-begin--author:sunjianlei---date:20190508------for: 顶部导航栏过长时显示更多按钮-----
  }
}
</script>
 
<style lang="less" scoped>
// 顶部菜单
.top-nav-header-index {
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  position: relative;
  transition: background 0.3s, width 0.2s;
  color: @layout-header-color;
 
  .header-index-wide {
    width: 100%;
    margin: auto;
    padding: 0 20px 0 0;
    display: flex;
    height: @layout-header-height;
    margin-left: 10px;
 
    .ant-menu.ant-menu-horizontal {
      height: @layout-header-height;
      line-height: @layout-header-height;
    }
 
    .ant-menu.ant-menu-horizontal {
      border: none;
      height: @layout-header-height;
      line-height: @layout-header-height;
    }
 
    .header-index-left {
      flex: 1 1;
      display: flex;
 
      .logo.top-nav-header {
        width: 165px;
        height: @layout-header-height;
        position: relative;
        line-height: @layout-header-height;
        transition: all 0.3s;
        overflow: hidden;
 
        img {
          display: inline-block;
          vertical-align: middle;
          height: 32px;
        }
 
        h1 {
          // color: #fff;
          display: inline-block;
          vertical-align: top;
          font-size: 16px;
          margin: 0 0 0 12px;
          font-weight: 400;
        }
      }
    }
 
    .header-index-right {
      float: right;
      height: @layout-header-height;
      overflow: hidden;
      .action:hover {
        background-color: @item-hover-bg;
      }
    }
  }
}
 
// 侧边菜单
.header {
  position: relative;
  z-index: 2;
  color: @layout-header-color;
  height: @layout-header-height;
  background: @layout-header-background;
  transition: background 300ms;
  // box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
 
  .trigger {
    height: 42px;
    line-height: 42px;
    font-size: 22px;
    padding: 0 16px;
    cursor: pointer;
    transition: color 300ms, background 300ms;
 
    &:hover {
      background: @item-hover-bg;
    }
  }
}
</style>