123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <template>
- <view class="custom-navbar" :style="{'background':bgColor,'height':`${(statusBar + customBarH) * 2}rpx`}">
- <view class="custom-navbar-info" :style="{'background':bgColor,'position':isFixed?'fixed':'static',...customNavbarInfo }">
-
- <view class="system" :style="{'height':`${statusBar * 2}rpx`}"></view>
- <view class="navbar" :style="{'height':`${customBarH * 2}rpx`}">
- <view class="left" :style="{...leftStyle}">
-
- <slot name="left">
-
-
- <view v-if="isLeft" @click="back()">
- <u-icon v-if="isPageUp" name="arrow-left" color="unset"></u-icon>
- <u-icon v-if="!isPageUp" name="home" size="22" color="unset"></u-icon>
- {{ isPageUp ? '':leftText }}
- </view>
-
-
-
- <view @click="back()" v-if="isPageUp && isPageUp">返回</view>
- <view @click="homePage()" v-if="!isPageUp && isPageUp">首页</view>
-
- </slot>
- </view>
-
- <view class="content" :style="contentStyle">
- <slot name="content">{{ title }}</slot>
- </view>
-
- <view class="right">
- <slot name="right">
- </slot>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- statusBar: 0,
- customBarH: this.customBar,
- platform: "",
- isPageUp: true,
- }
- },
- props: {
-
- customNavbarInfo: {
- type: Object,
- default: ()=>{
- return {
- borderBottom: '1px solid #ebebeb',
- boxShadow: 'rgba(0, 0, 0, 0.1) 0px 1px 6px 0px'
- }
- }
- },
-
- customBar: {
- type: Number,
- default: 45
- },
- isLeft: {
- type: Boolean,
- default: true
- },
-
- leftStyle: {
- type: Object,
- default: ()=>{
- return {
- color: '#000'
- }
- }
- },
-
- leftText: {
- type: String,
- default: ""
- },
-
- title: {
- type: String,
- default: ""
- },
-
- contentStyle: {
- type: Object,
- default: ()=>{
- return {
- color: '#fff'
- }
- }
- },
-
- rightText: {
- type: String,
- default: ""
- },
-
- bgColor: {
- type: String,
- default: "#fff"
- },
-
- isFixed: {
- type: Boolean,
- default: false
- },
- delta: {
- type: Number,
- default: 1,
- }
- },
- mounted() {
-
- uni.getSystemInfo({
- success: (res) => {
- this.platform = res.platform
-
- this.statusBar = res.statusBarHeight
- const custom = wx.getMenuButtonBoundingClientRect()
- this.customBarH = custom.bottom + custom.top - res.statusBarHeight
-
-
- this.statusBar = res.statusBarHeight
-
- if (res.platform == "android") {
- this.statusBar += 3
- this.customBarH += 3
- }
-
- }
- })
-
- let pages = getCurrentPages()
- if (pages[pages.length - 2]) {
- this.isPageUp = true
- } else {
- this.isPageUp = false
- }
- },
- methods: {
-
- back() {
- console.log("返回上一页!")
- if(this.isPageUp) {
- uni.navigateBack({
- delta: this.delta
- })
- }else {
- this.homePage()
- }
-
- },
-
- homePage() {
- console.log("返回首页!")
- uni.reLaunch({
- url: '/pages/main/index'
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .custom-navbar {
- width: 100vw;
- color: #fff;
- .custom-navbar-info {
- width: 100%;
- z-index: 9999;
- .system {
- width: 100%;
- background: transparent;
- }
-
- .navbar {
- width: 100vw;
- display: flex;
- align-items: center;
- justify-content: space-between;
- box-sizing: border-box;
- position: relative;
- padding: 0 30rpx;
- }
-
- .left,
- .right {
- width: 120rpx;
- }
-
- .left {
- text-align: left;
- font-size: 32rpx;
- >view {
- display: flex;
- }
- }
-
- .content {
- text-align: center;
- font-size: 32rpx;
- }
-
- .right {
- text-align: right;
- }
- }
- }
- </style>
|