AppHeader.vue
1.59 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
<!--
* @Date: 2025-08-27 17:45:12
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-27 18:05:42
* @FilePath: /lls_program/src/components/AppHeader.vue
* @Description: 文件描述
-->
<template>
<view class="relative px-4 py-5 flex items-center justify-center bg-white bg-opacity-70 backdrop-blur-md border-b border-gray-100">
<button
v-if="showBack && !isRootPath"
@click="goBack"
class="absolute left-4 p-2 rounded-full hover:bg-gray-100 transition-colors"
aria-label="返回"
>
<Left size="24" />
</button>
<h1 class="text-xl font-medium">{{ title }}</h1>
<button
v-if="showHome && !isRootPath"
@click="goHome"
class="absolute right-4 p-2 rounded-full hover:bg-gray-100 transition-colors"
aria-label="首页"
>
<Home size="24" />
</button>
</view>
</template>
<script setup>
import { computed } from 'vue';
import Taro from '@tarojs/taro';
import { Left, Home } from '@nutui/icons-vue-taro';
defineProps({
title: {
type: String,
required: true
},
showBack: {
type: Boolean,
default: true
},
showHome: {
type: Boolean,
default: false
}
});
const currentPage = computed(() => {
const pages = Taro.getCurrentPages();
return pages.length > 0 ? '/' + pages[pages.length - 1].route : '';
});
const isRootPath = computed(() => {
return currentPage.value === '/pages/index/index' || currentPage.value === '/pages/Dashboard/index';
});
const goBack = () => {
Taro.navigateBack();
};
const goHome = () => {
Taro.switchTab({ url: '/pages/index/index' });
};
</script>