Files
frontend-app/components/header.vue
T

102 lines
2.1 KiB
Vue
Raw Normal View History

2025-08-05 15:25:23 +08:00
<template>
<!-- 导航栏 -->
<view class="header_" >
<view style="margin-top: 20rpx;" @click="leftJump">
<up-image src="/static/common/left.png" width="18" height="20" bgColor="#f1f6ff00"/>
</view>
<view class="title_">{{leftTitle}}</view>
<view @click="rightJump">{{rightTitle}}</view>
</view>
</template>
<script>
export default {
name:"header",
props: {
leftTitle:{
type: String,
default: null
},
leftPath:{
type: String,
default: null
},
leftPathType:{
type: String,
default: "navigateTo"
},
rightTitle:{
type: String,
default: null
},
rightPath:{
type: String,
default: null
},
rightPathType:{
type: String,
default: "navigateTo"
},
},
data() {
return {
};
},
methods: {
leftJump() {
const leftPath = this.leftPath;
const leftPathType = this.leftPathType;
if(leftPathType === "navigateTo"){
2026-09-23 10:29:41 +08:00
const pages = getCurrentPages();
if (pages && pages.length > 1) {
const prevPage = pages[pages.length - 2];
const route = prevPage ? (prevPage.route || (prevPage.$page && prevPage.$page.route)) : '';
if (!leftPath || (route && leftPath.includes(route))) {
uni.navigateBack();
return;
}
}
if (leftPath) {
uni.redirectTo({
url: leftPath,
fail: () => {
uni.navigateTo({ url: leftPath });
}
});
} else {
uni.navigateBack();
}
2026-07-22 17:18:13 +08:00
}else if(leftPathType === "switchTab" && leftPath){
2025-08-05 15:25:23 +08:00
uni.switchTab({
url: leftPath,
});
2026-09-23 10:29:41 +08:00
}else if(leftPathType === "redirectTo" && leftPath){
uni.redirectTo({
url: leftPath,
});
2025-08-05 15:25:23 +08:00
}
},
rightJump() {
const rightPath = this.rightPath;
if(!rightPath){
return;
}
const rightPathType = this.rightPathType;
if(rightPathType === "navigateTo"){
uni.navigateTo({
url:rightPath,
})
}else if(rightPathType === "switchTab"){
uni.switchTab({
url: rightPath,
});
}
},
}
}
</script>
<style lang="scss" scoped>
2025-05-07 10:09:55 +08:00
</style>