Explorar o código

app改为小程序

tanxue hai 1 mes
pai
achega
c991533014
Modificáronse 1 ficheiros con 65 adicións e 0 borrados
  1. 65 0
      components/custom-navbar/custom-navbar.vue

+ 65 - 0
components/custom-navbar/custom-navbar.vue

@@ -0,0 +1,65 @@
+<template>
+  <view class="icon-title-navBar-box">
+	  <!-- 状态栏填充(兼容刘海屏) -->
+	  <view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
+	  <view class="icon-title-box">
+		  <view class="nav-bar-box" v-if="showBackBtn" @click="handleBack">
+			  <view class="nav-bar-icon"></view>
+		  </view>
+		  <!-- 标题区域 -->
+		  <view class="nav-bar-title" :style="{fontSize: titleSize + 'rpx', color: titleColor}">
+			{{ title }}
+		  </view>
+	  </view>
+  </view>
+</template>
+
+<script>
+export default {
+  props: {
+    title: String,
+    titleSize: { type: Number, default: 32 }, // 默认字号
+    titleColor: { type: String, default: '#333' },
+	showBackBtn:{type:Boolean, default: false}
+  },
+  data() {
+    return {
+      statusBarHeight: 0
+    };
+  },
+  methods: {
+	  handleBack() {
+		  this.$emit('back')
+	  }
+  },
+  mounted() {
+    // 获取状态栏高度(兼容不同设备)
+    uni.getSystemInfo({
+      success: (res) => {
+        this.statusBarHeight = res.statusBarHeight;
+      }
+    });
+  }
+};
+</script>
+
+<style>
+.custom-nav {
+  width: 100%;
+  background-color: #FFFFFF; /* 背景色 */
+  display: flex;
+  flex-direction: column;
+}
+.status-bar {
+  width: 100%;
+}
+.nav-content {
+  height: 44px; /* 导航栏主体高度 */
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+.nav-title {
+  font-weight: bold; /* 可加粗 */
+}
+</style>