You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

670 lines
18 KiB

7 months ago
<template>
<view class="topnav">
<view :class="{ 'header_fixed': navFixed, 'header_absolute': type == 'transparent', 'header_shadow': navShadow, 'header_colorWhite': isWhite, themeBgColor: themeBgColor}"
:style="{ paddingTop: statusBarHeight + 'px', backgroundImage: navBgColor, color: navFontColor, opacity: transparentValue }">
<view class="header_content">
<view class="header_left_box">
<slot name="left">
<view class="header_left_info" :class="{ 'header_btnMongol':isTwoBtn,'header_colorWhite_btnMongol': isWhite && isTwoBtn}"v-if="back || $slots.left || home">
<view class="header_left_back" :class="{'header_btnMongol_left_back':isTwoBtn}" v-if="back && !firstPage">
<image v-if="!isblack" class="header_icon" @click="toback" src="/static/zhouWei-navBar/njdts-zy-zuojiantou-bai.png" mode="aspectFit"></image>
<image v-if="isblack" class="header_icon" @click="toback" src="/static/zhouWei-navBar/njdts-zy-zuojiantou-hei.png" mode="aspectFit"></image>
<view class="zjx"></view>
<image class="header_icon" @click="toindex" src="/static/zhouWei-navBar/njdts-zy-zhuye-hei.png" v-if="isblack" mode="aspectFit"></image>
<image class="header_icon" @click="toindex" src="/static/zhouWei-navBar/njdts-zy-zhuye-bai.png" v-if="!isblack" mode="aspectFit"></image>
</view>
<text class="header_left_line" :class="{'header_colorWhite_left_line': isWhite}" v-if="isTwoBtn"></text>
<view class="header_left_home" :class="{'header_btnMongol_left_home':isTwoBtn}" v-if="(firstPage && back) || home"
@click="onBackHome">
<image class="header_icon" v-if="isWhite" src="/static/zhouWei-navBar/icon_home_white.png" mode="aspectFit"></image>
<image class="header_icon" v-else src="/static/zhouWei-navBar/icon_home_black.png" mode="aspectFit"></image>
</view>
</view>
</slot>
<view class="header_title" v-if="!titleCenter && ($slots.default || navTitle)" :style="{color: navFontColor}">
<slot><text :style="{color: navFontColor}">{{ navTitle }}</text></slot>
</view>
</view>
<view class="sy-tq" @click="nato('/pages/keliu/keliu')">
<view class="tb"><image class="img" :src="gettqImg(cond_code)" mode=""></image></view>
<view class="wz">
<text class="t1">{{ tmp }}</text>
<text class="t2"></text>
</view>
</view>
<!-- <view class="klinfo">
<swiper :autoplay="true" :interval="4000" :duration="1000" easing-function="linear">
<swiper-item v-for="(el,ind) in jqdatas" v-if="ind<3" >
<view class="swiper-item">
<view class="kltitle">{{el.name}}</view>
<view class="kltit">
<view class="klvalue">当前客流</view>
<view class="klvalue">{{el.value}}</view>
</view>
</view>
</swiper-item>
</swiper>
</view> -->
<view class="header_title header_title_center" v-if="titleCenter && ($slots.default || navTitle)" :style="{color: navFontColor}">
<slot><text :style="{color: navFontColor}">{{ navTitle }}</text></slot>
</view>
<view class="header_right_info">
<slot name="right"></slot>
</view>
</view>
</view>
<view class="header_transparentFixed header_fixed" v-if="type == 'transparentFixed'" :style="{ paddingTop: statusBarHeight + 'px', color: navTransparentFixedFontColor, opacity: 1 - transparentValue, zIndex: transparentValue < 0.3 ? 100 : 90 }">
<view class="header_content">
<view class="header_left_box">
<slot name="transparentFixedLeft">
<view class="header_left_info header_transparentFixed_left_info" :class="{'header_transparentFixed_colorWhite_left_info': isWhite}"
v-if="back || $slots.left || home">
<view class="header_left_back" :class="{'header_btnMongol_left_back':isTwoBtn}" v-if="back && !firstPage" @click="onBackPage">
<image class="header_icon" v-if="isWhite" src="/static/zhouWei-navBar/icon_back_white.png" mode="aspectFit"></image>
<image class="header_icon" v-else src="/static/zhouWei-navBar/icon_back_black.png" mode="aspectFit"></image>
</view>
<text class="header_left_line" v-if="isTwoBtn"></text>
<view class="header_left_home" :class="{'header_btnMongol_left_home':isTwoBtn}" v-if="(firstPage && back) || home"
@click="onBackHome">
<image class="header_icon" v-if="isWhite" src="/static/zhouWei-navBar/icon_home_white.png" mode="aspectFit"></image>
<image class="header_icon" v-else src="/static/zhouWei-navBar/icon_home_black.png" mode="aspectFit"></image>
</view>
</view>
</slot>
<view class="header_title" v-if="!titleCenter && (navTitle || $slots.transparentFixed)" :style="{ color: navTransparentFixedFontColor}">
<slot name="transparentFixed">
<text :style="{color: navTransparentFixedFontColor}">{{ navTitle }}</text>
</slot>
</view>
</view>
<view class="header_title header_title_center" v-if="titleCenter && (navTitle || $slots.transparentFixed)" :style="{color: navTransparentFixedFontColor}">
<slot name="transparentFixed"><text :style="{color: navTransparentFixedFontColor}">{{ navTitle }}</text></slot>
</view>
<view class="header_right_info">
<slot name="transparentFixedRight"></slot>
</view>
</view>
</view>
<view v-if="type == 'fixed'" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="header_station"></view>
</view>
</view>
</template>
<script>
// 主页页面的页面路径
// 关联功能:打开的页面只有一个的时候右上角自动显示返回首页按钮,下面这个数组是排除显示返回首页的页面。
// 主页使用场景:小程序分享出去的页面,用户点击开是分享页面,很多情况下是没有返回首页按钮的
const mainPagePath = ['pages/navList', 'pages/demo6'];
//返回首页的地址
const homePath = '/pages/index/index';
//白色表达值
const whiteList = ['#FFF', '#FFFFFF', 'white', 'rgb(255,255,255)', 'rgba(255,255,255,1)'];
export default {
props: {
tmp : {
type: String,
default: function() {
return '';
}
},
cond_code : {
type: String,
default: function() {
return '';
}
},
jqdatas : [],
//是否显示返回按钮
// 1000 显示返回按钮
// 2000 不显示返回按钮
// 3000 自定义返回按钮方法,点击返回箭头后会发送一个backClick事件
isblack:{
type: Boolean,
default: function() {
return false;
}
},
backState: {
default: function() {
return 1000;
}
},
//是否显示返回首页按钮
home: {
type: Boolean,
default: function() {
return false;
}
},
//导航背景色,支持渐变
bgColor: {
type: [String, Array],
default: function() {
return '#FFFFFF';
}
},
// 导航背景色渐变角度
bgColorAngle: {
type: [String, Number],
default: function() {
return 45;
}
},
//导航字体颜色,字体颜色为白色的时候会把手机状态栏设置为白色,否则为黑色
fontColor: {
type: String,
default: function() {
return '#000000';
}
},
//标题是否居中
titleCenter: {
type: Boolean,
default: function() {
return true;
}
},
//标题
title: {
type: String,
default: function() {
return '';
}
},
//类型 fixed为固定 默认
// ordinary 普通的 不固定
// transparent 透明不固定的
//transparentFixed 透明固定的
type: {
type: String,
default: function() {
return 'fixed';
}
},
//透明固定的时候字体颜色
transparentFixedFontColor: {
type: String,
default: function() {
return '#000000';
}
},
// 屏幕滑动距离顶部距离(透明固定导航比传)
scrollTop: {
type: Number,
default: function() {
return 0;
}
},
// 是否显示阴影
shadow: {
type: Boolean,
default: function() {
return true;
}
},
},
data() {
return {
//当前页面是否是第一个页面
firstPage: false,
//透明度值
transparentValue: 1,
//标题
navTitle: '',
//字体色
navFontColor: '#000000',
//背景色
navBgColor: 'none',
//透明底字体色
navTransparentFixedFontColor: '#000000',
// 是否使用
themeBgColor: false,
// 导航栏高度
statusBarHeight: 0,
// 上次显示的导航栏颜色
lastFrontColor:"",
};
},
computed: {
back() {
return this.backState == 1000 || this.backState == 3000;
},
//导航固定
navFixed() {
if (this.type == 'transparentFixed' || this.type == 'fixed') {
return true;
} else {
return false;
}
},
//导航底部线是否显示
navShadow() {
if(this.bgColor && typeof(this.bgColor) == "string"){
return this.shadow && this.type !== 'transparent' && whiteList.includes(this.bgColor);
}else{
return false;
}
},
//导航字体是否是白色颜色
isWhite() {
return whiteList.includes(this.navFontColor);
},
//右上角是否有两个按钮
isTwoBtn() {
return (this.backState == 1000 || this.backState == 3000) && this.home && !this.firstPage;
}
},
watch: {
title(val) {
this.navTitle = val;
},
fontColor(val) {
this.navFontColor = val;
this.settingColor();
},
bgColor(val) {
this.getNavBgColor(val);
},
transparentFixedFontColor(val) {
this.navTransparentFixedFontColor = val;
},
scrollTop(val) {
this.pageScroll({
scrollTop: val
});
}
},
//第一次加载
created() {
this.navTitle = this.title;
this.navFontColor = this.fontColor;
this.getNavBgColor(this.bgColor);
this.navTransparentFixedFontColor = this.transparentFixedFontColor;
//获取手机状态栏高度
this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
const _this = this;
this.pageScroll({
scrollTop: this.scrollTop
});
//获取所有页面
let currentPages = getCurrentPages();
let pageLen = currentPages.length;
//判断是否是第一个页面,如果是有设置back为true的页面,将不显示返回箭头,而显示返回首页按钮
if (pageLen == 1 && !mainPagePath.includes(currentPages[0].route)) {
this.firstPage = true;
}
console.log(this.isblack)
},
//方法
methods: {
nato(url){
uni.navigateTo({
url:url
})
},
gettqImg(code) {
return 'https://cs.tour-ma.com/r/cms/www/m/tianqi/' + code + '.png';
},
getimg2(url){
return 'https://cs.tour-ma.com/r/cms/www/m/yushan/' + url;
},
toindex(){
console.log(11111)
uni.reLaunch({
url:'../../pages/index/index'
})
},
toback(){
console.log(2222)
uni.navigateBack();
},
//返回上一页面
onBackPage() {
if (this.backState == 3000) {
this.$emit('backClick');
} else {
uni.navigateBack();
}
},
//返回首页
onBackHome() {
uni.switchTab({
url: homePath
});
},
pageScroll(e) {
if (this.type == 'transparentFixed') {
if (e.scrollTop && e.scrollTop > 0) {
if (e.scrollTop > 180) {
this.transparentValue = 1;
} else {
this.transparentValue = e.scrollTop / 180;
}
} else {
this.transparentValue = 0;
}
this.settingColor();
}
},
// 获取导航背景颜色
getNavBgColor(val) {
if (val == 'themeBgColor') {
this.themeBgColor = true;
this.navBgColor = 'none';
} else if (this.type == 'transparent') {
this.themeBgColor = false;
this.navBgColor = 'none';
} else {
if (typeof val == 'string') {
this.navBgColor = 'linear-gradient(90deg,' + val + ',' + val + ')';
} else if (Array.isArray(val) && val.length >= 2) {
let navBgColor = 'linear-gradient(' + this.bgColorAngle + 'deg';
val.forEach((item,ind) => {
if (typeof item == 'string') {
if(ind==1){
navBgColor += ' 0%,' + item;
}else{
navBgColor += ',' + item;
}
} else if (typeof item == 'object') {
navBgColor += ',' + item.color + ' ' + item.scale;
}
});
console.log(navBgColor)
navBgColor += ' 88%)';
this.navBgColor = navBgColor;
}
}
},
//设置手机状态栏颜色
settingColor() {
let navColor = this.navFontColor;
if (this.type == 'transparentFixed' && this.transparentValue <= 0.5) {
navColor = this.navTransparentFixedFontColor;
}
let frontColor = "#000000";
if (whiteList.includes(navColor)) {
frontColor = '#ffffff';
}
if (this.lastFrontColor == frontColor) {
return;
}
setTimeout(() => {
this.lastFrontColor = frontColor;
// 改变手机状态栏颜色
uni.setNavigationBarColor({
frontColor: frontColor,
backgroundColor: "#FFFFFF"
});
}, 150);
}
}
};
</script>
<style lang="scss">
/* #ifdef APP-PLUS-NVUE */
@function unit($num) {
@return $num + 0rpx;
}
/* #endif */
/* #ifndef APP-PLUS-NVUE */
@function unit($num) {
@return $num + 0upx;
}
/* #endif */
.header_content {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
/* #ifdef MP */
padding-right: unit(190);
box-sizing: border-box;
/* #endif */
width: unit(750);
align-items: flex-end;
justify-content: space-between;
flex-direction: row;
height: unit(88);
position: relative;
}
.header_station {
height: unit(88);
}
.header_shadow {
// border-style: solid;
// border-width: unit(2);
// border-color: #f5f5f5;
box-shadow: 0 0 unit(6) 0 #ddd;
}
.header_fixed {
position: fixed;
top: 0;
left: 0;
width: unit(750);
z-index: 99;
}
.header_absolute {
position: absolute;
top: 0;
left: 0;
z-index: 99;
width: unit(750);
background: transparent!important;
// background-image: url(../../static/banner.png) !important;
}
.header_left_box {
/* #ifndef APP-PLUS-NVUE */
display: flex;
/* #endif */
flex-direction: row;
align-items: center;
height: unit(88);
flex: 1;
}
.header_left_line {
height: unit(30);
width: unit(2);
background-color: rgba(255, 255, 255, 0.4);
}
.header_left_back {
width: unit(120);
border-radius: unit(33);
border-style: solid;
border-width: unit(1);
border-color: #EBEBEB;
height: 100%;
/* #ifndef APP-PLUS-NVUE */
display: flex;
/* #endif */
align-items: center;
justify-content: space-between;
padding: 0 25upx;
.zjx{
width: unit(2);
height: 60%;
position: absolute;
top: 20%;
left: 50%;
background: #CCCCCC;
}
}
.header_icon {
width: unit(34);
height: unit(34);
}
.header_left_home {
width: unit(56);
height: 100%;
/* #ifndef APP-PLUS-NVUE */
display: flex;
/* #endif */
align-items: center;
justify-content: center;
}
.header_left_info {
/* #ifndef APP-PLUS-NVUE */
display: flex;
/* #endif */
flex-direction: row;
align-items: center;
height: unit(65);
margin-left: unit(16);
position: fixed;
}
.header_title {
height: unit(88);
font-size: unit(32);
padding-left: unit(30);
padding-right: unit(30);
font-weight: 700;
text-overflow: ellipsis;
/* #ifndef APP-PLUS-NVUE */
white-space: nowrap;
display: flex;
overflow: hidden;
/* #endif */
/* #ifdef APP-PLUS-NVUE */
lines: 1;
/* #endif */
flex-direction: row;
align-items: center;
justify-content: center;
/* #ifdef MP */
max-width: calc(100vw - 160upx);
/* #endif */
}
.header_title_center {
position: absolute;
bottom: unit(0);
left: unit(375);
transform: translateX(-50%);
}
.header_right_info {
height: unit(88);
/* #ifndef APP-PLUS-NVUE */
display: flex;
flex-shrink: 0;
/* #endif */
flex-direction: row;
align-items: center;
}
.header_btnMongol {
border-radius: unit(33);
border-style: solid;
border-width: unit(2);
border-color: rgba(0, 0, 0, 0.1);
background-color: rgba(255, 255, 255, 0.7);
/* #ifndef APP-PLUS-NVUE */
box-sizing: border-box;
/* #endif */
}
.header_btnMongol_left_back,
.header_btnMongol_left_home {
width: unit(70);
}
.header_transparentFixed {
border-bottom-width: 0;
background-color: transparent;
background-image: transparent;
}
.header_transparentFixed_left_info {
border-style: solid;
border-width: unit(2);
border-color: rgba(0, 0, 0, 0.1);
background-color: rgba(255, 255, 255, 0.7);
border-radius: unit(33);
/* #ifndef APP-PLUS-NVUE */
box-sizing: border-box;
/* #endif */
}
.header_transparentFixed_colorWhite_left_info {
border-style: solid;
border-width: unit(2);
border-color: rgba(255, 255, 255, 0.3);
background-color: rgba(0, 0, 0, 0.2);
}
//颜色白色
.header_colorWhite_btnMongol {
border-style: solid;
border-width: unit(2);
border-color: rgba(255, 255, 255, 0.3);
background-color: rgba(0, 0, 0, 0.2);
}
.header_colorWhite_left_line {
background-color: rgba(255, 255, 255, 0.3);
}
.sy-tq{
position: absolute;
top:0%;
left: unit(30);
z-index: 999;
display: flex;
height: unit(88);
line-height: unit(88);
}
.tb{
display: flex;
align-items: center;
justify-content: center;
margin: unit(0) unit(10) unit(0) unit(0);
}
.tb .img{
width: unit(50);
height: unit(50);
margin-top: unit(-5);
}
.wz{
color: #fff;
}
.klinfo{
position: absolute;
top: 80%;
left: 5%;
width: 65%;
height: 85upx;
font-size: 26upx;
color: #fff;
swiper{
width: 100%;
height: 100%;
swiper-item{
.swiper-item{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: start;
.kltit{
display: flex;
justify-content: start;
}
.kltitle{
margin-right: 30upx;
}
}
}
}
}
</style>