fix: titlebar 文字无法居中的问题

This commit is contained in:
2025-08-27 11:43:38 +08:00
parent 9b813b399f
commit 1e21aaeda0

View File

@@ -1,10 +1,12 @@
<template> <template>
<view class="top" :class="[sticky ? 'sticky': '']"> <view class="top" :class="[sticky ? 'sticky': '']">
<view v-show="showBack" class="top-back" @click="toBack()"> <view v-show="showBack" class="top-back" @click="toBack()">
<!-- <u-icon color="#333" size="20" name="arrow-left"></u-icon>--> <!-- <u-icon color="#333" size="20" name="arrow-left"></u-icon>-->
< <
</view> </view>
<view class="top-title"><slot></slot></view> <view class="top-title">
<slot></slot>
</view>
<view @click="topgae()" style="color: #387DF7;"> <view @click="topgae()" style="color: #387DF7;">
<slot name="right"></slot> <slot name="right"></slot>
</view> </view>
@@ -12,19 +14,19 @@
</template> </template>
<script> <script>
export default { export default {
props:{ props: {
backUrl:{ backUrl: {
type:String, type: String,
default:'' default: ''
}, },
showBack:{ showBack: {
type:Boolean, type: Boolean,
default:false default: false
}, },
goPgae:{ goPgae: {
type:String, type: String,
default:'' default: ''
}, },
// 启用粘性滚动 // 启用粘性滚动
sticky: { sticky: {
@@ -33,73 +35,75 @@
} }
}, },
data() { data() {
return { return {}
}
}, },
methods: { methods: {
topgae() { topgae() {
if(this.goPgae!=''){ if (this.goPgae != '') {
uni.navigateTo({ uni.navigateTo({
url:this.goPgae url: this.goPgae
}); });
} }
}, },
toBack(){ toBack() {
// 如果定义的有 go 事件,优先处理这个 // 如果定义的有 go 事件,优先处理这个
if( this.$listeners['go'] ) { if (this.$listeners['go']) {
this.$emit('go') this.$emit('go')
return return
} }
if(this.backUrl!=''){ if (this.backUrl != '') {
if(this.backUrl == '/pages/my/index'){ if (this.backUrl == '/pages/my/index') {
uni.switchTab({ uni.switchTab({
url:this.backUrl url: this.backUrl
}) })
}else{ } else {
uni.navigateTo({ uni.navigateTo({
url:this.backUrl url: this.backUrl
}); });
} }
}else{ } else {
let pages =getCurrentPages(); let pages = getCurrentPages();
//console.log(pages); //console.log(pages);
const prevPage=pages[pages.length-2]; const prevPage = pages[pages.length - 2];
if(!prevPage){ if (!prevPage) {
uni.switchTab({ uni.switchTab({
url:'/pages/index/index' url: '/pages/index/index'
}) })
}else{ } else {
uni.navigateBack(); uni.navigateBack();
} }
} }
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.top{ .top {
height: 40px; height: 40px;
background-color: #fff; background-color: #fff;
display: flex; display: flex;
align-items: center; align-items: center;
// justify-content: space-between; justify-content: space-between;
.top-back{ position: relative;
.top-back {
color: #333; color: #333;
//padding-top:10px; //padding-top:10px;
height: 40px; height: 40px;
line-height: 40px; line-height: 40px;
padding-left: 15px; padding-left: 15px;
} }
.top-title{
.top-title {
width: 100%;
text-align: center; text-align: center;
position: absolute;
font-size: 16px; font-size: 16px;
font-weight: 550; font-weight: 550;
color: #333; color: #333;
height: 40px; height: 40px;
text-align: center;
width: 80%;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
@@ -112,19 +116,20 @@
//防止其他元素遮盖 //防止其他元素遮盖
z-index: 99; z-index: 99;
} }
} }
// .arrow:before {
// content: " "; // .arrow:before {
// display: inline-block; // content: " ";
// -webkit-transform: rotate(45deg); // display: inline-block;
// -ms-transform: rotate(45deg); // -webkit-transform: rotate(45deg);
// transform: rotate(45deg); // -ms-transform: rotate(45deg);
// height: .5rem; // transform: rotate(45deg);
// width: .5rem; // height: .5rem;
// border-width: 0 0 2px 2px; // width: .5rem;
// border-color: #FFFFFF; // border-width: 0 0 2px 2px;
// border-style: solid; // border-color: #FFFFFF;
// position: relative; // border-style: solid;
// top: 0 // position: relative;
// } // top: 0
// }
</style> </style>