mac 2 years ago
parent
commit
eb833545fb
  1. 425
      components/NavBar/NavBar.vue

425
components/NavBar/NavBar.vue

@ -1,208 +1,219 @@
<template>
<view>
<!-- 左侧布局 -->
<view v-if="navStyle==='left'" class="_navLayout"
:style="{'background': navBackground,'height':navStatusHeight}">
<!-- 状态栏 -->
<view :style="{'height':statusBarHeight}"></view>
<!-- 导航栏,去掉了不可用的宽度 -->
<view class="_nav-real" :style="{'height':navHeight,'width':enableWidth}">
<view class="_navIcon2" >
<image src="../../static/wx_back.png" style="width: 20px;height: 20px;"></image>
</view>
<!-- 标题布局 -->
<view style="font-size: 17px;padding-left: 4px;">首页</view>
</view>
</view>
<!-- 居中布局 -->
<!-- 这里不使用props改用data -->
<view v-if="navStyle==='center'" class="_navLayout"
:style="{'background': navBackground,'height':navStatusHeight}">
<!-- 状态栏 -->
<view :style="{'height':statusBarHeight}"></view>
<!-- 导航栏,去掉了不可用的宽度 -->
<view class="_nav-real" :style="{'height':navHeight,'width':enableWidth}">
<!-- 按键区域占用为不可用的宽度 -->
<view class="_navIcon" :style="{'width':disableWidth,'height':navHeight}">
<image src="../../static/wx_back.png" style="width: 23px;height: 23px;"></image>
</view>
<!-- 标题布局 -->
<view class="_nav-title" :style="{'height':navHeight,'line-height':navHeight,'font-size':fontSize}">
{{navTitle}}
</view>
</view>
</view>
<view v-if="!supportChange" :style="{'height':navStatusHeight}"></view>
</view>
</template>
<script>
/**
* 全局默认背景透明supportChange= false 会对默认色变成不透明
*/
const defaultTransparentBg = "linear-gradient(89.26deg, rgba(254,144,56,0) 0.75%,rgba(255,177,118,0) 99.78%)";
export default {
name: "NavBar",
props: {
color: {
type: String,
default: "white"
},
//
navTitle: {
type: String,
default: ""
},
//
supportChange: {
type: Boolean,
default: true
},
//
// supportChange=false
navBg: {
type: String,
default: defaultTransparentBg
},
// 0->1
startChangeHeight: {
type: Number,
default: 0
},
//
// ->1
endChangeHeight: {
type: Number,
default: 0
},
// icon
showIcon: {
type: Boolean,
default: true
}
},
data() {
return {
// props
navBackground: this.navBg,
navStatusHeight: 0,
statusBarHeight: 0,
navHeight: 0,
disableWidth: 0,
enableWidth: 0,
enableHeight: 0,
fontSize: 0,
navStyle: 'left'
};
},
mounted() {
// mounteddata
if (!this.supportChange) {
if (this.navBg === defaultTransparentBg) {
// 使
// props
this.navBackground = defaultTransparentBg.replaceAll(",0)", ",1)")
}
}
//
// this.navStyle = getApp().globalData.navInfo.navBar.style
},
created() {
// createprops,使this.
// data
// script,使this使
let navInfo = getApp().globalData.navInfo
//
this.navStatusHeight = navInfo.navStatusHeight + navInfo.unit
this.statusBarHeight = navInfo.statusBarHeight + navInfo.unit
this.navHeight = navInfo.navBar.height + navInfo.unit
this.disableWidth = navInfo.navBar.disableWidth + navInfo.unit
this.enableWidth = navInfo.navBar.enableWidth + navInfo.unit
this.enableHeight = navInfo.navBar.enableHeight + navInfo.unit
this.fontSize = navInfo.navBar.fontSize + navInfo.unit
},
methods: {
/**
* 自定义颜色渐变的值
*/
alpha(res) {
if (!this.supportChange)
return '1.0'
if (res.scrollTop > this.startChangeHeight) {
//
if (res.scrollTop < this.endChangeHeight) {
return (1 - ((this.endChangeHeight - res.scrollTop) / 100)) + ''
} else {
//
return '1.0'
}
} else {
//
return '0.0'
}
},
/**
* 提供默认的颜色变化功能
*/
defaultColorBgAlpha(res) {
let x = this.alpha(res)
this.navBackground = "linear-gradient(89.26deg, rgba(254,144,56," + x +
") 0.75%,rgba(255,177,118," + x + ") 99.78%)"
},
clickIcon() {
uni.navigateBack()
}
}
}
</script>
<style>
._navLayout {
display: flex;
flex-direction: column;
width: 100%;
z-index: 999;
top: 0;
position: fixed;
}
._nav-real {
display: flex;
flex-direction: row;
width: 100%;
align-items: center;
}
._nav-title {
text-align: center;
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
white-space: nowrap;
width: 100%;
color: white;
}
._navIcon {
display: flex;
flex-direction: row;
align-items: center;
padding-left: 3px;
flex-shrink: 0;
}
._navIcon2 {
display: flex;
flex-direction: row;
align-items: center;
margin-left: 10px;
flex-shrink: 0;
padding-right: 4px;
}
<template>
<view>
<!-- 左侧布局 -->
<view v-if="navStyle==='left'" class="_navLayout"
:style="{'background': navBackground,'height':navStatusHeight}">
<!-- 状态栏 -->
<view :style="{'height':statusBarHeight}"></view>
<!-- 导航栏,去掉了不可用的宽度 -->
<view class="_nav-real"
:style="{'height':navHeight,'width':'calc('+enableWidth+' - 9px)' ,'margin-left':'9px','background':'red'}">
<view class="_navIcon2">
<image src="../../static/wx_back.png" style="width: 20px;height: 20px;"></image>
</view>
<!-- 标题布局 -->
<view class="_nav-title2" :style="{'font-size':fontSize}">>{{navTitle}}</view>
</view>
</view>
<!-- 居中布局 -->
<!-- 这里不使用props改用data -->
<view v-if="navStyle==='center'" class="_navLayout"
:style="{'background': navBackground,'height':navStatusHeight}">
<!-- 状态栏 -->
<view :style="{'height':statusBarHeight}"></view>
<!-- 导航栏,去掉了不可用的宽度 -->
<view class="_nav-real" :style="{'height':navHeight,'width':enableWidth}">
<!-- 按键区域占用为不可用的宽度 -->
<view class="_navIcon" :style="{'width':disableWidth,'height':navHeight}">
<image src="../../static/wx_back.png" style="width: 23px;height: 23px;"></image>
</view>
<!-- 标题布局 -->
<view class="_nav-title" :style="{'height':navHeight,'line-height':navHeight,'font-size':fontSize}">
{{navTitle}}
</view>
</view>
</view>
<view v-if="!supportChange" :style="{'height':navStatusHeight}"></view>
</view>
</template>
<script>
/**
* 全局默认背景透明supportChange= false 会对默认色变成不透明
*/
const defaultTransparentBg = "linear-gradient(89.26deg, rgba(254,144,56,0) 0.75%,rgba(255,177,118,0) 99.78%)";
export default {
name: "NavBar",
props: {
color: {
type: String,
default: "white"
},
//
navTitle: {
type: String,
default: ""
},
//
supportChange: {
type: Boolean,
default: true
},
//
// supportChange=false
navBg: {
type: String,
default: defaultTransparentBg
},
// 0->1
startChangeHeight: {
type: Number,
default: 0
},
//
// ->1
endChangeHeight: {
type: Number,
default: 0
},
// icon
showIcon: {
type: Boolean,
default: true
}
},
data() {
return {
// props
navBackground: this.navBg,
navStatusHeight: 0,
statusBarHeight: 0,
navHeight: 0,
disableWidth: 0,
enableWidth: 0,
enableHeight: 0,
fontSize: 0,
navStyle: 'left'
};
},
mounted() {
// mounteddata
if (!this.supportChange) {
if (this.navBg === defaultTransparentBg) {
// 使
// props
this.navBackground = defaultTransparentBg.replaceAll(",0)", ",1)")
}
}
//
this.navStyle = getApp().globalData.navInfo.navBar.style
},
created() {
// createprops,使this.
// data
// script,使this使
let navInfo = getApp().globalData.navInfo
//
this.navStatusHeight = navInfo.navStatusHeight + navInfo.unit
this.statusBarHeight = navInfo.statusBarHeight + navInfo.unit
this.navHeight = navInfo.navBar.height + navInfo.unit
this.disableWidth = navInfo.navBar.disableWidth + navInfo.unit
this.enableWidth = navInfo.navBar.enableWidth + navInfo.unit
this.enableHeight = navInfo.navBar.enableHeight + navInfo.unit
this.fontSize = navInfo.navBar.fontSize + navInfo.unit
},
methods: {
/**
* 自定义颜色渐变的值
*/
alpha(res) {
if (!this.supportChange)
return '1.0'
if (res.scrollTop > this.startChangeHeight) {
//
if (res.scrollTop < this.endChangeHeight) {
return (1 - ((this.endChangeHeight - res.scrollTop) / 100)) + ''
} else {
//
return '1.0'
}
} else {
//
return '0.0'
}
},
/**
* 提供默认的颜色变化功能
*/
defaultColorBgAlpha(res) {
let x = this.alpha(res)
this.navBackground = "linear-gradient(89.26deg, rgba(254,144,56," + x +
") 0.75%,rgba(255,177,118," + x + ") 99.78%)"
},
clickIcon() {
uni.navigateBack()
}
}
}
</script>
<style>
._navLayout {
display: flex;
flex-direction: column;
width: 100%;
z-index: 999;
top: 0;
position: fixed;
}
._nav-real {
display: flex;
flex-direction: row;
width: 100%;
align-items: center;
}
._nav-title {
text-align: center;
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
white-space: nowrap;
width: 100%;
color: white;
}
._nav-title2 {
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
white-space: nowrap;
width: 100%;
color: white;
padding-left: 5px;
flex: 1;
}
._navIcon {
display: flex;
flex-direction: row;
align-items: center;
padding-left: 3px;
flex-shrink: 0;
}
._navIcon2 {
display: flex;
flex-direction: row;
align-items: center;
flex-shrink: 0;
padding-right: 6px;
}
</style>
Loading…
Cancel
Save