index.vue
3.5 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
<template>
<view>
<view class="CustomReturn-container" :style="{height: titleHeight, paddingTop: paddingTop, backgroundColor: bgColor}">
<view class="CustomReturn">
<view v-if="isShowBreak" class="CustomReturn-r">
<u-icon name="home" v-if="isFirstPage && !isCustomReturn" @click="toBreak()" size="23" :color="color"></u-icon>
<u-icon name="arrow-left" v-else @click="toBreak()" size="20" :color="color"></u-icon>
</view>
<view style="width: 200rpx;" v-else ></view>
<view class="CustomReturn-title" :style="{'color': color}"></view>
<view style="width: 200rpx;"></view>
</view>
<view class="other">
<slot></slot>
</view>
</view>
</view>
</template>
<script>
export default {
name:"CustomReturn",
components: {
},
props: {
color: {
type: String,
default: '#fff'
},
isShowOtherIcon: {
type: Boolean,
default: true
},
bgColor: {
type: String,
default: 'none'
},
breakUrl: {
type: String,
default: ''
},
isShowBreak: {
type: Boolean,
default: true
},
title: {
type: [String, Number],
default: '标题'
},
isCustomReturn: {
type: Boolean,
default: false
}
},
data() {
return {
show: false,
titleHeight: 0,
paddingTop: 0,
otherHeight: 0,
isFirstPage: false,
entityHeight: 0
};
},
mounted() {
this.getHeight()
this.getOther()
this.identifyPages()
},
methods: {
toExamination() {
uni.reLaunch({
url: '/pages/examination/examination'
})
},
toPersonalCenter() {
uni.reLaunch({
url: '/pages/personalCenter/personalCenter'
})
},
// 获取除顶部导航栏以外的高度
getOtherHeight() {
return this.otherHeight
},
getOther() {
uni.createSelectorQuery().in(this).select('.other')
.fields({ size: true }, (res) => {
if (res) {
this.otherHeight = res.height
console.log('元素高度', res.height);
this.$emit('init', {otherHeight: this.otherHeight, entityHeight: this.entityHeight})
}
}).exec();
},
// 辨别页面
identifyPages() {
let result = getCurrentPages()
if(result.length === 1) {
this.isFirstPage = true
} else {
this.isFirstPage = false
}
},
getHeight() {
this.titleHeight = 88 + 'rpx';
this.paddingTop = uni.getSystemInfoSync().statusBarHeight + 'px'
// #ifdef MP-WEIXIN
let res = wx.getMenuButtonBoundingClientRect();
this.paddingTop = res.top + 'px'
this.titleHeight = res.height + 10 + 'px';
this.entityHeight = res.top + res.height
// #endif
},
toBreak(){
if(!this.isCustomReturn) {
let result = getCurrentPages()
if(result.length === 1) {
uni.reLaunch({
url: '/pages/examination/examination'
})
} else {
uni.navigateBack({
delta: 1
})
}
} else {
this.$emit('goBack')
}
}
}
}
</script>
<style lang="scss" scoped>
.CustomReturn-container{
position: fixed;
top: 0;
width: 100%;
z-index: 1002;
transition: all .5s;
box-sizing: content-box;
}
.CustomReturn{
display: flex;
align-items: center;
flex-grow: 1;
padding: 24rpx 24rpx;
justify-content: space-between;
position: relative;
z-index: 1002;
height: 100%;
padding-bottom: 10px;
box-sizing: border-box;
.CustomReturn-title{
font-size: 36rpx;
}
.CustomReturn-r{
display: flex;
width: 200rpx;
align-items: center;
.CustomReturn-i{
height: 36rpx;
width: 36rpx;
margin-left: 30rpx;
}
}
}
</style>