通用自定义导航栏封装,2/4页面使用

This commit is contained in:
WindowBird 2025-08-26 16:48:58 +08:00
parent 3e2bdb482e
commit 85befc2a71
3 changed files with 134 additions and 21 deletions

View File

@ -1,16 +1,26 @@
<template>
<view class="layout">
<view class="navbar">
<view :style="{ background: backgroundColor }" class="navbar">
<view :style="{ height: getStatusBarHeight() + 'px' }" class="statusBar"></view>
<view
:style="{ height: getTitleBarHeight() + 'px', marginLeft: getLeftIconLeft() + 'px' }"
class="titleBar"
>
<view class="title">{{ title }}</view>
<!-- <navigator class="search" url="/pages/search/search">-->
<!-- <uni-icons class="icon" color="#888" size="18" type="search"></uni-icons>-->
<!-- <text class="text">></text>-->
<!-- </navigator>-->
<!-- 返回按钮 -->
<view v-if="showBack" class="back-button" @click="goBack">
<image :src="commonEnum.BACK" class="left-icon"></image>
</view>
<!-- 标题 -->
<view :style="{ color: titleColor, textAlign: titleAlign }" class="title"
>{{ title }}
</view>
<!-- 右侧搜索按钮 -->
<view v-if="showSearch" class="search" @click="handleSearch">
<uni-icons :color="iconColor" class="icon" size="18" type="search"></uni-icons>
<text :style="{ color: iconColor }" class="text">></text>
</view>
</view>
</view>
@ -26,13 +36,79 @@ import {
getNavBarHeight,
getLeftIconLeft,
} from '@/utils/system.js'
import commonEnum from '../../enum/commonEnum'
import { navigateBack } from '../../utils/router'
import UniIcons from '../../uni_modules/uni-icons/components/uni-icons/uni-icons.vue'
defineProps({
//
const props = defineProps({
//
title: {
type: String,
default: '壁纸',
default: '标题',
},
//
backgroundColor: {
type: String,
default: '#ffddca',
},
//
titleColor: {
type: String,
default: '#3d3d3d',
},
//
iconColor: {
type: String,
default: '#888',
},
//
showBack: {
type: Boolean,
default: false,
},
//
showSearch: {
type: Boolean,
default: false,
},
//
titleAlign: {
type: String,
default: 'center', // 'left', 'center', 'right'
},
//
onBack: {
type: Function,
default: null,
},
//
onSearch: {
type: Function,
default: null,
},
})
//
const emit = defineEmits(['back', 'search'])
//
function goBack() {
if (props.onBack) {
props.onBack()
} else {
navigateBack(1)
}
emit('back')
}
//
function handleSearch() {
if (props.onSearch) {
props.onSearch()
}
emit('search')
}
</script>
<style lang="scss" scoped>
@ -43,43 +119,79 @@ defineProps({
left: 0;
width: 100%;
z-index: 10;
background: #ffddca;
.statusBar {
//
}
.titleBar {
display: flex;
align-items: center;
padding: 0 30rpx;
position: relative;
.title {
font-size: 32rpx;
font-weight: 500;
color: #3d3d3d;
font-size: 36rpx;
font-weight: 400;
flex: 1;
text-align: center;
//
&.title-left {
text-align: left;
margin-left: 80rpx; //
}
&.title-center {
text-align: center;
}
&.title-right {
text-align: right;
margin-right: 80rpx; //
}
}
.back-button {
position: absolute;
left: 0;
width: 80rpx;
height: 50rpx;
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
.left-icon {
width: 18rpx;
height: 32rpx;
}
}
.search {
width: 220rpx;
position: absolute;
right: 0;
width: 80rpx;
height: 50rpx;
margin-left: 10rpx;
color: #3d3d3d;
font-size: 28rpx;
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
.icon {
margin-left: 5rpx;
margin-right: 5rpx;
}
.text {
padding-left: 10rpx;
padding-left: 5rpx;
font-size: 24rpx;
}
}
}
}
.fill {
//
}
}
</style>

View File

@ -2,7 +2,7 @@
<view class="home-container">
<!-- 头部信息 -->
<custom-nav-bar title="福鼎创特物联科技有限公司"></custom-nav-bar>
<custom-nav-bar title="福鼎创特物联科技有限公司" title-align="left"></custom-nav-bar>
<!-- 公告栏 -->
<announcement-bar

View File

@ -1,7 +1,8 @@
<template>
<view class="lease-page">
<!-- 头部区域 -->
<custom-nav-bar2 color="#FFDECB" title="租赁申请"></custom-nav-bar2>
<custom-nav-bar background-color="#FFDECB" title="租赁申请" title-align="center" />
<view class="header">
<image
:src="commonEnum.FIRE_BACKGROUND_FULL"
@ -420,7 +421,7 @@ export default {
.lease-page {
position: relative;
background: #f3f5f6;
border: #120d0d solid 2rpx;
//border: #120d0d solid 2rpx;
}
//