12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <template>
- <view class="nav-bar">
- <view class="nav-bar-status" :style="{ height: statusBarHeight + 'px' }">
- </view>
- <view class="nav-bar-title" :style="{ height: titleBarHeight +'px' }">
- <template v-if="title">
- <view class="btn-back" @click="goBack">
- <van-icon v-if="hasParent" name="arrow-left" />
- </view>
- <view class="nav-bar-title-text">{{ title }}</view>
- <view></view>
- </template>
- <template v-else>
- <view><slot></slot></view>
- </template>
- </view>
- </view>
- </template>
- <script>
- export default {
- props: {
- title: String
- },
- computed: {
- hasParent() {
- return getCurrentPages().length > 1
- }
- },
- data() {
- return {
- titleBarHeight: 0,
- statusBarHeight: 0,
- isNotchScreen: false
- }
- },
- created() {
- const windowInfo = uni.getWindowInfo()
- this.statusBarHeight = windowInfo.statusBarHeight
- const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
- this.titleBarHeight = (menuButtonInfo.top - this.statusBarHeight) * 2 + menuButtonInfo.height + (windowInfo.screenWidth / 750 * 16)
- this.$emit('init', {
- detail: {
- navbarHeight: this.statusBarHeight + this.titleBarHeight,
- pageHeight: windowInfo.screenHeight - (this.statusBarHeight + this.titleBarHeight)
- }
- })
- },
- methods: {
- goBack() {
- wx.navigateBack()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .nav-bar {
- background: linear-gradient( 270deg, #2b2359 9%, #405491 44%, #2b2359 92%), rgba(0,0,0,0.2);
- }
- .nav-bar-title{
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0 32rpx;
- view{
- color: #ffffff;
- }
- }
- .nav-bar-title-text{
- flex: 1;
- font-weight: 500;
- font-size: $fontSize5;
- line-height: 42rpx;
- text-align: left;
- text-transform: none;
- padding-left: 8rpx;
- }
- .btn-back{
- padding: 0 6rpx;
- }
- </style>
|