Files
kangyuan-mobile/components/card_navbar/inner-navbar.vue
T

126 lines
2.8 KiB
Vue

<template>
<view class="cardTitle p-x-20" :style="{ background: backgroundColor }">
<view :style="{height: statusBarHeight + 'px'}"></view>
<view class="flex-center ju-between h_88">
<view class="cardLeft" v-if="props.showLeftButton || $slots.left">
<view v-if="props.showLeftButton" @tap="onClickLeft">
<uni-icons type="left" :color="textColor" />
</view>
<slot name="left" />
</view>
<view class="title size36 flex1 center" :style="[{ color: textColor }]">{{ props.title }}</view>
<view class="cardRight" :style="{ color: textColor }">
<slot name="right" />
</view>
</view>
</view>
</template>
<script setup lang="ts">
import { getCurrentInstance, defineProps, defineEmits, ref } from 'vue';
import {onPageScroll} from '@dcloudio/uni-app';
import sheep from '@/sheep';
const { proxy } = getCurrentInstance() as any;
let props = defineProps({
title: {
type: String,
default: '',
},
bg: {
type: String,
default: '',
},
scrollbg: {
type: String,
default: '#ffffff',
},
scrollTop: {
type: Number,
default: 20
},
showLeftButton: {
type: Boolean,
default: true,
},
color: {
type: String,
default: '#333333',
},
scrollColor:{
type: String,
default: '#333333'
},
goLeft: {
type: Boolean,
default: true,
},
url: {
type: String,
default: '/pages/index/index',
},
back:{
type: Number,
default: 1
},
index:{
type: Number,
default: 0
}
});
let statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
const hasHistory = sheep.$router.hasHistory();
const emits = defineEmits(['navback', 'clickLeft']);
const onClickLeft = () => {
if (props.goLeft && props.showLeftButton) {
if (hasHistory) {
uni.navigateBack({ delta: props.back })
} else {
sheep.$router.go(props.url);
}
} else {
emits('clickLeft');
}
};
// 监听滚动事件
let scrollTop = ref(0)
let backgroundColor = ref(props.bg)
let textColor = ref(props.color)
onPageScroll(e=>{
scrollTop.value = e.scrollTop
if(e.scrollTop > props.scrollTop){
backgroundColor.value = props.scrollbg
textColor.value = props.scrollColor
}else{
backgroundColor.value = props.bg
textColor.value = props.color
}
})
</script>
<style scoped lang="scss">
.cardTitle {
position: fixed;
top:0;
left:0;
width: 100%;
z-index: 98;
}
:deep(.uniui-left){
font-size: 44rpx !important;
}
.cardLeft{
position: absolute;
bottom: 44rpx;
left: 20rpx;
transform: translateY(50%);
}
.cardRight {
position: absolute;
bottom: 44rpx;
right: 20rpx;
transform: translateY(50%);
}
</style>