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

<script>
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  import iconpath from "./uniicons.ttf";
  export default {
    name: "uni-navbar",
    props: {
      title: {
        type: String,
        default: "",
      },
      isLeft: {
        type: Boolean,
        default: false,
      },
      textColor: {
        type: String,
        default: "#000",
38 39 40 41 42
      },
      statusBar: {
        type: Boolean,
        default: false,
      }
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    },
    data() {
      return {
        statusBarHeight: 0,
      };
    },
    computed: {
      unicode() : string {
        return "\ue600";
      },
    },
    created() {
      uni.loadFontFace({
        global: false,
        family: "UniIconsFontFamily",
        source: `url("${iconpath}")`,
        success() { },
        fail(err) {
          console.log(err);
M
mehaotian 已提交
62
        },
63 64 65
      });
    },
    mounted() {
66 67
      uni.setNavigationBarColor({
        frontColor: "#000000",
68
        backgroundColor: "#ffffff",
69
      });
70 71 72 73 74 75 76
    },
    methods: {
      back() {
        uni.navigateBack({});
      },
    },
  };
M
mehaotian 已提交
77 78 79
</script>

<style>
80 81
  .uni-icons {
    font-family: "UniIconsFontFamily" !important;
82
    font-size: 26px;
83 84 85
    font-style: normal;
    color: #333;
  }
86 87 88 89

  .status-bar {
    height: var(--status-bar-height);
  }
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  .uni-navbar {
    background-color: #007aff;
  }

  .uni-navbar-inner {
    position: relative;
    flex-direction: row;
    justify-content: space-between;
    height: 45px;
  }

  .left-content,
  .right-content {
    justify-content: center;
    align-items: center;
105
    width: 40px;
106 107
    height: 100%;
  }
M
mehaotian 已提交
108

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

121 122 123
  .is-left {
    justify-content: flex-start;
  }
124
</style>