CustomNavbar.vue
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
53
54
55
56
57
58
59
60
61
62
63
64
65
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
110
111
112
<template>
<view class="custom-navbar" :style="navbarStyle">
<uv-navbar
:title="title"
:fixed="fixed"
:autoBack="false"
:bgColor="bgColor"
:titleStyle="titleStyle"
>
<template v-slot:left>
<view class="left-container">
<view v-if="isTab"></view>
<uv-icon v-else name="arrow-left" :color="leftIconColor" size="40rpx" @tap="handleBack" />
<!-- #ifdef MP-WEIXIN -->
<slot name="right"></slot>
<!-- #endif -->
</view>
</template>
<template v-slot:right>
<!-- #ifndef MP-WEIXIN -->
<slot name="right"></slot>
<!-- #endif -->
</template>
</uv-navbar>
</view>
</template>
<script setup>
import { computed } from 'vue';
const props = defineProps({
// 标题
title: {
type: String,
default: ''
},
// 是否固定
fixed: {
type: Boolean,
default: true
},
// 是否为tab页面
isTab: {
type: Boolean,
default: false
},
// 背景颜色
bgColor: {
type: String,
default: '#3277fb'
},
// 标题样式
titleStyle: {
type: String,
default: 'color: #FFFFFF;'
},
// 左侧图标颜色
leftIconColor: {
type: String,
default: '#FFFFFF'
},
// 自定义样式
customStyle: {
type: Object,
default: () => ({})
}
});
const navbarStyle = computed(() => {
const style = { ...props.customStyle };
return Object.keys(style).map(key => `${key}: ${style[key]}`).join(';');
});
const emit = defineEmits(['back']);
// 返回按钮处理
const handleBack = () => {
emit('back');
uni.navigateBack();
};
</script>
<style lang="scss" scoped>
.custom-navbar {
width: 100%;
}
.left-container {
display: flex;
align-items: center;
gap: 20rpx;
}
/* 适配iOS和Android的差异 */
/* #ifdef APP-PLUS */
.custom-navbar {
/* App平台通用样式 */
}
/* #endif */
/* #ifdef APP-PLUS-IOS */
.custom-navbar {
/* iOS特定样式 */
}
/* #endif */
/* #ifdef APP-PLUS-ANDROID */
.custom-navbar {
/* Android特定样式 */
}
/* #endif */
</style>