通用自定义导航栏封装,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> <template>
<view class="layout"> <view class="layout">
<view class="navbar"> <view :style="{ background: backgroundColor }" class="navbar">
<view :style="{ height: getStatusBarHeight() + 'px' }" class="statusBar"></view> <view :style="{ height: getStatusBarHeight() + 'px' }" class="statusBar"></view>
<view <view
:style="{ height: getTitleBarHeight() + 'px', marginLeft: getLeftIconLeft() + 'px' }" :style="{ height: getTitleBarHeight() + 'px', marginLeft: getLeftIconLeft() + 'px' }"
class="titleBar" class="titleBar"
> >
<view class="title">{{ title }}</view> <!-- 返回按钮 -->
<!-- <navigator class="search" url="/pages/search/search">--> <view v-if="showBack" class="back-button" @click="goBack">
<!-- <uni-icons class="icon" color="#888" size="18" type="search"></uni-icons>--> <image :src="commonEnum.BACK" class="left-icon"></image>
<!-- <text class="text">></text>--> </view>
<!-- </navigator>-->
<!-- 标题 -->
<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>
</view> </view>
@ -26,13 +36,79 @@ import {
getNavBarHeight, getNavBarHeight,
getLeftIconLeft, getLeftIconLeft,
} from '@/utils/system.js' } 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: { title: {
type: String, 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> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -43,43 +119,79 @@ defineProps({
left: 0; left: 0;
width: 100%; width: 100%;
z-index: 10; z-index: 10;
background: #ffddca;
.statusBar { .statusBar {
//
} }
.titleBar { .titleBar {
display: flex; display: flex;
align-items: center; align-items: center;
padding: 0 30rpx; padding: 0 30rpx;
position: relative;
.title { .title {
font-size: 32rpx; font-size: 36rpx;
font-weight: 500; font-weight: 400;
color: #3d3d3d; 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 { .search {
width: 220rpx; position: absolute;
right: 0;
width: 80rpx;
height: 50rpx; height: 50rpx;
margin-left: 10rpx;
color: #3d3d3d;
font-size: 28rpx;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center;
z-index: 1;
.icon { .icon {
margin-left: 5rpx; margin-right: 5rpx;
} }
.text { .text {
padding-left: 10rpx; padding-left: 5rpx;
font-size: 24rpx;
} }
} }
} }
} }
.fill { .fill {
//
} }
} }
</style> </style>

View File

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

View File

@ -1,7 +1,8 @@
<template> <template>
<view class="lease-page"> <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"> <view class="header">
<image <image
:src="commonEnum.FIRE_BACKGROUND_FULL" :src="commonEnum.FIRE_BACKGROUND_FULL"
@ -420,7 +421,7 @@ export default {
.lease-page { .lease-page {
position: relative; position: relative;
background: #f3f5f6; background: #f3f5f6;
border: #120d0d solid 2rpx; //border: #120d0d solid 2rpx;
} }
// //