104 lines
2.0 KiB
Vue
104 lines
2.0 KiB
Vue
<template>
|
|
<view class="nav-header" :style="{ paddingTop: statusBarHeight + 'px' }">
|
|
<view class="header-content">
|
|
<view class="back-btn" v-if="showBack" @click="handleBack">
|
|
<image
|
|
class="back-icon"
|
|
:src="backIcon"
|
|
mode="aspectFill"
|
|
></image>
|
|
</view>
|
|
<text class="header-title">{{ title }}</text>
|
|
<view class="header-placeholder" v-if="showPlaceholder"></view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: 'NavHeader',
|
|
props: {
|
|
// 标题
|
|
title: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
// 是否显示返回按钮
|
|
showBack: {
|
|
type: Boolean,
|
|
default: true
|
|
},
|
|
// 返回按钮图标
|
|
backIcon: {
|
|
type: String,
|
|
default: '/static/service/goBack_icon.png'
|
|
},
|
|
// 是否显示右侧占位(用于居中标题)
|
|
showPlaceholder: {
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
statusBarHeight: 0
|
|
}
|
|
},
|
|
mounted() {
|
|
this.getSystemInfo()
|
|
},
|
|
methods: {
|
|
// 获取系统信息
|
|
getSystemInfo() {
|
|
const systemInfo = uni.getSystemInfoSync()
|
|
this.statusBarHeight = systemInfo.statusBarHeight || 0
|
|
},
|
|
// 返回
|
|
handleBack() {
|
|
this.$emit('back')
|
|
uni.navigateBack()
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.nav-header {
|
|
.header-content {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
height: 88rpx;
|
|
padding: 0 30rpx;
|
|
position: relative;
|
|
|
|
.back-btn {
|
|
position: absolute;
|
|
left: 22rpx;
|
|
width: 17rpx;
|
|
height: 30rpx;
|
|
cursor: pointer;
|
|
z-index: 10;
|
|
|
|
.back-icon {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
}
|
|
|
|
.header-title {
|
|
flex: 1;
|
|
text-align: center;
|
|
font-family: PingFang-SC, PingFang-SC;
|
|
font-weight: bold;
|
|
font-size: 36rpx;
|
|
color: #1a1819;
|
|
}
|
|
|
|
.header-placeholder {
|
|
width: 60rpx;
|
|
}
|
|
}
|
|
}
|
|
</style>
|