uni-navbar-lite.uvue 2.9 KB
Newer Older
M
mehaotian 已提交
1 2 3 4 5 6
<template>
    <view class="uni-navbar">
        <view class="uni-navbar-inner" :style="navbarStyle">
            <view class="left-content" @click="back">
                <text class="uni-icons">{{unicode}}</text>
            </view>
7
            <view class="uni-navbar-content" :class="{'is-left':isLeft}">
M
mehaotian 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
                <slot>{{title}}</slot>
            </view>
            <view class="right-content">
                <slot name="right"></slot>
            </view>
        </view>
    </view>
</template>

<script>
    import iconpath from './uniicons.ttf'
    export default {
        name: "uni-navbar",
        props: {
        	title: {
        		type: String,
        		default: ''
        	},
26
        	isLeft: {
M
mehaotian 已提交
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
        		type: Boolean,
        		default: false
        	}
        },
        data() {
            return {
                statusBarHeight: 0
            };
        },
        computed: {
            navbarStyle() : string {
                return `margin-top:${this.statusBarHeight}px`
            },
            unicode() : string {
                return '\ue600'
            }
        },
        created() {
            uni.loadFontFace({
                global: false,
                family: 'UniIconsFontFamily',
                source: iconpath,
                success() { },
                fail(err) {
                    console.log(err);
                },
53
            })
M
mehaotian 已提交
54 55 56
            const sys = uni.getSystemInfoSync()
            const statusBarHeight = sys.statusBarHeight
            this.statusBarHeight = statusBarHeight
57 58 59 60 61 62 63 64 65
        },
        mounted() {
          // TODO 暂时加定时器,否则不生效
          setTimeout(() => {
            uni.setNavigationBarColor({
                frontColor: '#000000',
                backgroundColor: '#ffffff'
            })
          }, 100)
M
mehaotian 已提交
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
        },
        methods: {
            back() {
                uni.navigateBack({})
            }
        },
    }
</script>

<style>
    .uni-icons {
        font-family: "UniIconsFontFamily" !important;
        font-size: 22px;
        font-style: normal;
        color: #333;
    }
    .uni-navbar {
        border: 1px #eee solid;
        background-color: #fff;
    }
    .uni-navbar-inner {
        position: relative;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        height: 45px;
    }

    .left-content,
    .right-content {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 45px;
        height: 100%;
    }

    .uni-navbar-content {
        position: absolute;
        height: 100%;
        top: 0;
        bottom: 0;
        left: 45px;
        right: 45px;
110 111
        display: flex;
        flex-direction: row;
M
mehaotian 已提交
112 113
        justify-content: center;
        align-items: center;
114 115 116
    }
    .is-left {
      justify-content: flex-start;
M
mehaotian 已提交
117
    }
118
</style>