gaoluyang
3 天以前 7eebd7981c1f5d2c569556d1e87f7818cef18cce
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
<template>
    <view class="page-header">
        <view class="header-left">
            <up-icon 
                name="arrow-left" 
                size="20" 
                color="#333" 
                @click="handleBack"
            ></up-icon>
        </view>
        <view class="header-center">
            <text class="page-title">{{ title }}</text>
        </view>
        <view class="header-right" v-if="$slots.right">
            <slot name="right"></slot>
        </view>
    </view>
</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
    }
});
 
// 定义事件
const emit = defineEmits(['back']);
 
// 处理返回事件
const handleBack = () => {
    if (props.customBack) {
        props.customBack();
    } else {
        emit('back');
        uni.navigateBack();
    }
};
</script>
 
<style scoped lang="scss">
.page-header {
    background: #ffffff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #f0f0f0;
    position: sticky;
    /* 兼容 iOS 刘海/灵动岛安全区 */
    padding-top: calc(env(safe-area-inset-top));
    top: 0;
    z-index: 100;
    position: relative;
}
 
.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 30px; /* 确保点击区域足够大 */
}
 
.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    left: 0;
    right: 0;
    pointer-events: none;
}
 
.page-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    pointer-events: auto;
}
 
.header-right {
    display: flex;
    align-items: center;
    min-width: 44px; /* 确保右侧区域有足够空间 */
    justify-content: flex-end;
}
</style>