NafmHeader.vue
3.3 KB
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
<template>
<section>
<div class="nav_bar" :class="{bgImgClass:isBgImg}" :style="navObj.barStyle">
<!-- 左侧 自定义 -->
<div class="nav_left" v-if="$slots.left" slot="left">
<slot name="left" />
</div>
<!-- 左侧 默认 箭头以及文字描述 -->
<div class="nav_left" v-else @click="handleBack">
<i v-if="navObj.barLeftArrow" class="iconfont iconpreviewleft"></i>
{{navObj.barLeftText}}
</div>
<!-- 标题栏 默认 自定义 -->
<div class="nav_title" v-if="$slots.default">
<slot />
</div>
<!-- 标题栏 -->
<div class="nav_title" v-else>{{navObj.barTitle}}</div>
<!-- 右侧插槽 -->
<div class="nav_right" v-if="$slots.right" slot="right">
<slot name="right" />
</div>
</div>
</section>
</template>
<script>
export default {
name: 'NafmHeader',
props: {
bgColor: {
type: String,
},
isBgImg: {
type: Boolean,
default: true
},
color: {
type: String
},
leftText: {
type: String
},
leftArrow: {
type: Boolean,
default: undefined
},
title: {
type: String
},
showBack: {
type: Boolean,
default: false
},
onBack: {
type: Function,
}
},
computed: {
navObj() {
const meta = this.$route.meta
let leftArrowStatus = true
if (this.leftArrow != undefined) {
leftArrowStatus = this.leftArrow
} else if (meta.leftArrow != undefined) {
leftArrowStatus = meta.leftArrow
}
// 如果设置了背景图片 则不用设置 背景颜色了
// console.log('this.isBgImg',this.isBgImg)
const barStyleBg = this.isBgImg ? {} : { background: this.bgColor || meta.bgColor || '#729ae0' }
// console.log('meta',meta)
return {
barStyle: {
...barStyleBg,
color: this.color || meta.color || '#fff'
},
barLeftText: this.leftText || meta.leftText || '',
barTitle: this.title || meta.title || '',
barLeftArrow: leftArrowStatus
}
},
},
methods: {
handleBack() {
if (this.showBack) {
this.onBack()
} else {
this.$router.back()
}
}
}
}
</script>
<style lang="less" scoped>
@NavHeight: 45px;
section {
height: @NavHeight;
width: 100%;
position: relative;
z-index: 10;
.nav_bar {
height: @NavHeight;
position: fixed;
left: 0;
top: 0;
width: 100%;
display: flex;
justify-content: space-between;
box-sizing: border-box;
padding: 0 20px;
}
.bgImgClass {
background: url(../assets/icon/bg_navigation.png) !important;
background-repeat: no-repeat;
background-size: 100% !important;
background-position: center center;
}
.nav_left {
display: flex;
align-items: center;
:active {
opacity: 0.5;
}
.iconpreviewleft {
font-size: 25px;
}
img {
width: 51px;
height: 51px;
}
}
.nav_title {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
z-index: -1;
}
.nav_right {
min-width: 100px;
display: flex;
align-items: center;
justify-content: flex-end;
}
}
</style>