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
| <template>
| <up-navbar
| :title="title"
| :show-back="showBack"
| @leftClick="handleBack"
| :color="color"
| :border="true"
| :fixed="true"
| :placeholder="true"
| >
| <template v-if="$slots.right" #right>
| <slot name="right"></slot>
| </template>
| </up-navbar>
| </template>
|
| <script setup>
| import { defineProps, defineEmits } from 'vue';
|
| // 定义组件属性
| const props = defineProps({
| // 页面标题
| title: {
| type: String,
| default: ''
| },
| // 是否显示返回按钮
| showBack: {
| type: Boolean,
| default: true
| },
| // 自定义返回事件
| customBack: {
| type: Function,
| default: null
| },
| // 背景色
| background: {
| type: String,
| default: '#ffffff'
| },
| // 文字颜色
| color: {
| type: String,
| default: '#333333'
| },
| // 是否显示底部分割线
| borderBottom: {
| type: Boolean,
| default: true
| },
| // 是否固定在顶部
| isFixed: {
| type: Boolean,
| default: true
| }
| });
|
| // 定义事件
| const emit = defineEmits(['back']);
|
| // 处理返回事件
| const handleBack = () => {
| if (props.customBack) {
| props.customBack();
| } else {
| emit('back');
| // uni.navigateBack();
| }
| };
| </script>
|
| <style scoped lang="scss">
| /* up-navbar 组件已经内置了安全区域适配,不需要额外的样式调整 */
|
| /* 暗色模式适配 */
| @media (prefers-color-scheme: dark) {
| :deep(.up-navbar) {
| background: #1e1f24 !important;
| .up-navbar__title {
| color: #e9edf3 !important;
| }
| .up-navbar__back {
| color: #e9edf3 !important;
| }
| }
| }
| </style>
|
|