WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2025-03-13 a6378a4ecdc99fc8b2193adf193bcac98ddf05f5
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
/**
 * CNavCustomBar - 自定义导航条
 * @author chensi
 */
 
<template>
    <view
        class="c-nav-custom-bar"
        :style="{height:navBarHeight + 'px',paddingTop:statusBarHeight + 'px',boxSizing:'border-box'}"
    >
        <view
            class="c-nav-icon"
            :style="{height:(navBarHeight - statusBarHeight) + 'px'}"
        >
            <view
                v-if="!isNeedBackIcon"
                class="c-nav-menu-icon"
            >
                <slot name="icon"></slot>
            </view>
            <view
                v-if="isNeedBackIcon"
                class="c-nav-back-icon"
                @tap="evt => onBack()"
            >
                <AtIcon
                    value='chevron-left'
                    size='26'
                    color='#000'
                ></AtIcon>
            </view>
        </view>
        <view class="c-nav-title">
            {{ title }}
        </view>
    </view>
</template>
 
<script>
import Taro from '@tarojs/taro';
import { AtIcon } from 'taro-ui-vue';
import './cNavCustomBar.scss';
 
export default {
    name: 'CNavCustomBar',
    components: {
        AtIcon,
    },
    props: {
        isNeedBackIcon: {
            type: Boolean,
            default: false,
        },
        title: {
            type: String,
            default: '',
        },
    },
    computed: {},
    data() {
        return {
            navBarHeight: 0,
            statusBarHeight: 0,
        };
    },
    mounted() {
        this.getNavBarHeight();
    },
    methods: {
        getNavBarHeight() {
            //获取胶囊对象
            let menuButtonObject = Taro.getMenuButtonBoundingClientRect();
            // 获取设备系统对象
            let sysInfo = wx.getSystemInfoSync();
            // 获取状态栏高度
            let statusBarHeight = sysInfo.statusBarHeight;
            // 获取胶囊高度
            let menuButtonHeight = menuButtonObject.height;
            // 获取胶囊距离顶部的高度
            let distanceTop = menuButtonObject.top;
            //计算nav导航栏的高度
            let navBarHeight =
                statusBarHeight + menuButtonHeight + (distanceTop - statusBarHeight) * 2;
            this.navBarHeight = navBarHeight;
            this.statusBarHeight = statusBarHeight;
        },
 
        onBack() {
            Taro.navigateBack({
                delta: 1,
            });
        },
 
        $getStatusBarHeight() {
            return this.statusBarHeight;
        },
 
        //  使用自定义导航时,需要在主页显示的设置padding的值,此值是导航栏的高度,本导航已经使用固定定位为头部
        $getNavBarHeight() {
            return this.navBarHeight;
        },
    },
};
</script>