head.vue
6.9 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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<template name="head">
<!-- 头部内容 -->
<view class="headBoxBox" :style="{height: headHeight + 'px'}">
<view class="headBox" :style="{height: headHeight + 'px',background:'#'+ bgColor}">
<!-- 状态栏 -->
<view class="state" :style="{height: statusHeight + 'px'}"></view>
<!-- 导航栏 -->
<view class="nav" :style="{height: navHeight + 'px'}">
<!-- 返回按钮 -->
<view :class="[backBtnColor ? 'backBtnWhite' : 'backBtnBlack']" v-if="backBtn" @click="backDefault">
</view>
<!-- 定位 -->
<view class="address" v-if="bottomBtn" @click="toAddress">
<view class="addressText">
{{address}}
</view>
<view class="bottomBtn"></view>
</view>
<!-- 首页搜索框 -->
<view class="search" :style="{height: ellipse + 'px'}" v-if="search" @click="toNewPage">
<image class="searchImg" src="/static/mine/ic_search.png" mode="widthFix"></image>
<input type="text" :focus="true" placeholder="搜索" placeholder-class="placeholder" />
</view>
<!-- 地址搜索框 -->
<view class="searchTwo" :style="{height: ellipse + 'px'}" v-if="addressSearch" @click="toNewPage">
<image class="searchImg" src="/static/mine/ic_search.png" mode="widthFix"></image>
<input class="overdian" type="text" :value="searchContent" :placeholder="placeholder" placeholder-class="placeholderTwo" @input="iptContent"/>
</view>
<!-- 顶部标题 -->
<view class="title" v-if="showTitle">
{{title}}
</view>
</view>
</view>
</view>
</template>
<script>
export default {
name: "head",
data() {
return {
headHeight: '',
//状态栏高度
statusHeight: '',
//导航栏高度
navHeight: '',
// 胶囊高度
ellipse: '',
};
},
props: {
//背景色
bgColor: String,
// 标题
title: String, //内容
showTitle: Boolean, //显隐
// 返回按钮
backBtnColor: Boolean, //颜色 默认黑色 true为白色
backBtn: Boolean, // 按钮显隐
howBack: Boolean, //返回方式 默认返回上一页 true为自定义返回页面
customURL: String, //自定义返回路径 绝对路径
// 搜索框
search: Boolean, //首页搜索框显隐
addressSearch: Boolean, //普通搜索框显隐
searchContent: String, // 搜索值
placeholder: String, //输入框提示信息
toNewUrl: String, //点击跳转页面路径
// 地址
bottomBtn: Boolean, //显隐
address: String, //地址信息
newAddress: String, //地址跳转
// 定位搜索
showSearhcInput: Boolean
},
mounted() {
// 设备信息
let detail = uni.getSystemInfoSync()
// 获取设备的系统
let system = detail.system
//获取状态栏高度
this.statusHeight = detail.statusBarHeight
// 胶囊信息
let ellipse = uni.getMenuButtonBoundingClientRect()
//获取胶囊高度
this.ellipse = ellipse.height
//获取胶囊距顶部距离
let absTop = ellipse.top
//计算导航栏高度 = (胶囊距顶部距离 - 状态栏高度) * 2 + 胶囊高度
this.navHeight = (absTop - this.statusHeight) * 2 + this.ellipse
//计算整体高度
let cheack = /iOS/
//判断设备型号
if (cheack.test(system)) {
// iOS
this.headHeight = this.statusHeight + this.navHeight + 4
} else {
//Android
this.headHeight = this.statusHeight + this.navHeight
}
},
methods: {
//返回上一页
backDefault() {
if (this.howBack) {
uni.reLaunch({
url: this.customURL
})
console.log("请填写指定路径");
console.log(this.customURL);
} else {
uni.navigateBack({
delta: 1
})
}
},
// 搜索框点击
toNewPage() {
uni.navigateTo({
url: this.toNewUrl
})
},
//地址跳转
toAddress() {
let that = this
uni.authorize({
scope: 'scope.userLocation',
success() {
uni.navigateTo({
url: that.newAddress
})
},
fail(err){
console.log(err)
that.$emit('alertModel',true)
}
})
},
//监听输入内容
iptContent(e){
// console.log(e)
this.$emit('getChild',e)
let val = e.detail.value
if(/^[\x00-\xff]/.test(val)){
let v = {
first:val
}
this.$myRequest('/api/index/cit',v).then(res =>{
this.$emit('getRes',res)
})
}else{
let v = {
shortname:val
}
this.$myRequest('/api/index/keywords',v).then(res =>{
this.$emit('getRes',res)
})
}
}
},
}
</script>
<style>
.headBoxBox {
width: 100%;
}
.headBox,
.state,
.nav {
width: 750rpx;
}
/* 头部整体内容 */
.headBox {
position: fixed;
top: 0;
left: 0;
z-index: 100;
}
/* 状态栏 */
.state {
position: relative;
}
/* 导航栏 */
.nav {
display: flex;
align-items: center;
position: relative;
}
/* 搜索框 */
.search {
width: 400rpx;
border-radius: 200rpx;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-55%, -50%);
background: rgba(255, 255, 255, 0.8);
}
.searchTwo {
padding-left: 32rpx;
width: 448rpx;
border-radius: 200rpx;
display: flex;
justify-content: flex-start;
align-items: center;
position: absolute;
top: 50%;
left: 48%;
transform: translate(-60%, -50%);
background: rgba(247, 248, 250, 0.8);
}
.searchImg {
width: 32rpx;
height: 32rpx;
}
.search>input {
width: 60rpx;
color: #323233;
}
.searchTwo>input {
color: #323233;
margin-left: 8rpx;
}
.placeholder {
color: #969799;
text-align: center;
font-size: 28rpx;
}
.placeholderTwo {
font-size: 28rpx;
color: #C8C9CC;
}
.backBtnBlack {
margin-left: 32rpx;
right: 50rpx;
top: 150rpx;
content: "";
display: inline-block;
height: 20rpx;
width: 20rpx;
border-width: 0 0 2px 2px;
border-color: #000;
border-style: solid;
transform: matrix(0.71, 0.71, -.71, 0.71, 0, 0);
-webkit-transform: matrix(0.71, 0.71, -.71, 0.71, 0, 0);
}
.backBtnWhite {
margin-left: 32rpx;
right: 50rpx;
top: 150rpx;
content: "";
display: inline-block;
height: 20rpx;
width: 20rpx;
border-width: 0 0 2px 2px;
border-color: #fff;
border-style: solid;
transform: matrix(0.71, 0.71, -.71, 0.71, 0, 0);
-webkit-transform: matrix(0.71, 0.71, -.71, 0.71, 0, 0);
}
.bottomBtn {
right: 50rpx;
top: 150rpx;
content: "";
display: inline-block;
height: 16rpx;
width: 16rpx;
border-width: 0 2px 2px 0;
border-color: #fff;
border-style: solid;
transform: matrix(0.71, 0.71, -.71, 0.71, 0, 0);
-webkit-transform: matrix(0.71, 0.71, -.71, 0.71, 0, 0);
}
.address {
display: flex;
align-items: center;
margin-left: 32rpx;
}
.addressText {
color: #fff;
font-weight: 600;
width: 96rpx;
overflow: hidden;
white-space: nowrap;
}
.title {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.overdian{
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
}
</style>