Init project
This commit is contained in:
@@ -0,0 +1,240 @@
|
||||
# hx-navbar 适用于 uni-app 项目的头部导航组件
|
||||
|
||||
导航栏组件,主要用于头部导航,组件名:hx-navbar
|
||||
|
||||
本组件目前兼容微信小程序、H5、5+APP。
|
||||
|
||||
### 本组件支持模式:
|
||||
1. 普通固定顶部导航
|
||||
2. 透明导航
|
||||
3. 透明固定顶部导航
|
||||
4. 不固定普通导航
|
||||
5. 背景颜色线性渐变
|
||||
6. 滑动显示背景
|
||||
7. 左、中、右3个插槽;可关闭左右插槽使中间插槽铺满导航,实现高度自定义的导航需求
|
||||
|
||||
### 使用前提
|
||||
|
||||
需要先安装·uniapp·官方的```uni-icons``` 图标组件,```uni-icons```官方组件下载地址:[https://ext.dcloud.net.cn/plugin?id=28](https://ext.dcloud.net.cn/plugin?id=28)
|
||||
|
||||
### 使用方式
|
||||
页面使用需在 ``` script ``` 中引用组件
|
||||
``` javascript
|
||||
import hxNavbar from "@/components/hx-navbar/hx-navbar.vue"
|
||||
export default {
|
||||
components: {hxNavbar}
|
||||
}
|
||||
```
|
||||
|
||||
全局使用需在 ``` main.js ``` 中注册组件
|
||||
``` javascript
|
||||
import hxNavbar from "./components/hx-navbar/hx-navbar.vue"
|
||||
Vue.component('hx-navbar',hxNavbar)
|
||||
|
||||
```
|
||||
|
||||
|
||||
### 属性
|
||||
#### 基本属性
|
||||
| 名称 | 类型 | 默认值 | 描述 |
|
||||
| ----------------------------|--------------- | ---------------------- | ---------------------------------------------------|
|
||||
| back | Boolean | true | 返回上一页,(设置后,```leftIcon```属性,和```click-left```事件将失效|
|
||||
| height | String | 44px | 导航栏高度(不包含状态栏高度)|
|
||||
| barPlaceholder | String | auto | 导航栏占位符 显示(show),隐藏(hidden),自动(auto:如果头部为固定fixed ,则显示占位符) |
|
||||
| title | String | - | 导航标题(当设置了标题,中间插槽将失效) |
|
||||
| fixed | Boolean | false | 固定头部 |
|
||||
| color | String | #000000 | 导航文字颜色(如果需要屏幕滑动后变色,参数则为数组,例子:`['#000000','#ffffff']`) |
|
||||
| backgroundColor | Array | [255, 255, 255] | 导航背景颜色为RGB 编号(单色背景数组为```[255,255,255]```,线性渐变背景```[[236, 0, 140],[103, 57, 182],...]```) |
|
||||
| pageScroll | Object | {} | 屏幕滑动距离顶部的对象```滑动渐变必要参数``` |
|
||||
| backgroundColorLinearDeg | String | 45 | 导航背景线性渐变角度 |
|
||||
| backgroundImg | String | - | 导航背景图片(背景图片优先级高于背景颜色) |
|
||||
| transparent | String | show | 背景透明(show 不透明,hidden 透明,auto 自动:滑动逐渐显示背景颜色,当头部固定时生效) 兼容性:头条小程序必须在页面上加 onPageScroll(e){} ,才能滑动显示背景,可参考dome7|
|
||||
| shadow | Boolean | false | 导航栏阴影 |
|
||||
| border | Boolean | false | 导航栏边框 |
|
||||
|
||||
#### 关于状态栏的属性
|
||||
| 名称 | 类型 | 默认值 | 描述 |
|
||||
| ----------------------------|--------------- | ---------------------- | ---------------------------------------------------|
|
||||
| statusBar | Boolean | true | 包含状态栏 |
|
||||
| statusBarFontColor | Array,String | #000000 | 状态栏字体颜色,只支持```#000000 ```和```#FFFFFF```(如果需要屏幕滑动变色,参数则为数组,例子:```['#000000','#ffffff']```)|
|
||||
| statusBarBackground | String | - | 状态栏背景颜色,如果你想单独设置状态栏颜色,该属性是个不错的选择
|
||||
|
||||
#### 关于插槽的属性
|
||||
| 名称 | 类型 | 默认值 | 描述 |
|
||||
| ----------------------------|--------------- | ---------------------- | ---------------------------------------------------|
|
||||
| leftIcon | String | - | 左插槽图标,必须为 ```uni-icons``` 图标 |
|
||||
| rightIcon | String | - | 右插槽图标,必须为 ```uni-icons``` 图标 |
|
||||
| leftSlot | Boolean | true | 开启左插槽 |
|
||||
| rightSlot | Boolean | true | 开启右插槽 |
|
||||
| leftSlidiSwitch | Boolean | false | 屏幕滑动后 `left`插槽切换为`leftAfter`插槽 |
|
||||
| centerSlidiSwitch | Boolean | false | 屏幕滑动后 `default`插槽切换为`centerAfter`插槽 |
|
||||
| rightSlidiSwitch | Boolean | false | 屏幕滑动后 `right`插槽切换为`rightAfter`插槽 |
|
||||
|
||||
|
||||
#### 返回上一页为空时的处理属性
|
||||
| 名称 | 类型 | 默认值 | 描述 |
|
||||
| ----------------------------|--------------- | ---------------------- | ---------------------------------------------------|
|
||||
| backTabbarUrl | String | /pages/index/index | 返回至指定的tabber页面(返回首页),当上一页为空时生效;全局使用推荐进组件修改`backTabbarUrl`的默认值|
|
||||
| defaultBackUrl | String | - | 返回至指定的普通页面,当上一页为空时生效;`defaultBackUrl`优先级高于`backTabbarUrl`;主要应用在返回失效时|
|
||||
|
||||
``` html
|
||||
<!-- 使用场景:假如刷新了当前页面,那么返回事件将失效。
|
||||
这时用上 `defaultBackUrl` 或 `backTabbarUrl` 则能返回至指定页面-->
|
||||
<hx-navbar left-text="关于" defaultBackUrl="/pages/user/setting/setting" />
|
||||
```
|
||||
|
||||
|
||||
### 插槽
|
||||
| 名称 | 描述 |
|
||||
| ----------------------|-------------------------------------------------------------------|
|
||||
| left | 左插槽 (可关闭该插槽 ```leftSlot``` 属性) |
|
||||
| default | 中间插槽(当设置了标题,中间插槽将失效) |
|
||||
| right | 右插槽 (可关闭该插槽 ```rightSlot``` 属性) |
|
||||
| leftAfter | 屏幕滑动后的左插槽 (需要开启`leftSlidiSwitch`属性才生效) |
|
||||
| centerAfter | 屏幕滑动后的中插槽 (需要开启`centerSlidiSwitch`属性才生效) |
|
||||
| rightAfter | 屏幕滑动后的右插槽 (需要开启`rightSlidiSwitch`属性才生效) |
|
||||
|
||||
|
||||
``` html
|
||||
<hx-navbar>
|
||||
<view>标题栏(中间插槽)</view>
|
||||
<view slot="left">left(左插槽)</view>
|
||||
<view slot="right">right(右插槽)</view>
|
||||
</hx-navbar>
|
||||
```
|
||||
|
||||
|
||||
### 事件
|
||||
| 名称 | 参数 | 描述 |
|
||||
| -----------------|------------------| --------------------------|
|
||||
| click-left | - | 左侧按钮点击时触发,此事件将覆盖 `返回` |
|
||||
| click-right | - | 右侧按钮点击时触发 |
|
||||
| scroll | - | 监听滚动条,回调参数为滚动距离;固定头部时生效;应用场景:如滚动到多少时触发某些事件 |
|
||||
|
||||
## 使用例子
|
||||
|
||||
### 简单使用
|
||||
``` html
|
||||
<hx-navbar title="我爱新疆" left-text="返回" />
|
||||
```
|
||||
|
||||
### 背景颜色线性渐变、头部固定
|
||||
``` html
|
||||
<hx-navbar
|
||||
title="颜色渐变"
|
||||
:back="false"
|
||||
:fixed="true"
|
||||
color="#ffffff"
|
||||
:background-color="[[28, 187, 180],[141, 198, 63]]">
|
||||
</hx-navbar>
|
||||
```
|
||||
|
||||
### 滑动显示背景
|
||||
``` html
|
||||
<!-- 该例子取消了导航占位符 -->
|
||||
<hx-navbar
|
||||
title="颜色渐变"
|
||||
:back="false"
|
||||
:fixed="true"
|
||||
color="#ffffff"
|
||||
barPlaceholder="hidden"
|
||||
transparent="auto"
|
||||
:background-color="[[28, 187, 180],[141, 198, 63]]"
|
||||
:pageScroll.sync="scrollData">
|
||||
</hx-navbar>
|
||||
|
||||
```
|
||||
``` javascript
|
||||
data() {
|
||||
return {
|
||||
scrollData: {},
|
||||
}
|
||||
},
|
||||
//必须在页面加 onPageScroll(e){} ,才能滑动显示背景
|
||||
onPageScroll(e){
|
||||
this.scrollData = e;
|
||||
},
|
||||
```
|
||||
|
||||
### 左中插槽演示
|
||||
``` html
|
||||
<hx-navbar
|
||||
:back="false"
|
||||
:fixed="true"
|
||||
right-icon="scan">
|
||||
<block slot="left">
|
||||
<view class="city">
|
||||
<view>新疆</view>
|
||||
<uni-icons type="arrowdown" color="#333333" size="22" />
|
||||
</view>
|
||||
</block>
|
||||
<view class="input-view">
|
||||
<uni-icons type="search" size="22" color="#666666" />
|
||||
<input confirm-type="search" class="input" type="text" placeholder="输入搜索关键词" @confirm="confirm">
|
||||
</view>
|
||||
</hx-navbar>
|
||||
|
||||
|
||||
/*css 用于演示插槽自定义样式*/
|
||||
<style>
|
||||
.city{
|
||||
display: flex;flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
margin-left: 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
### 关闭左右插槽演示
|
||||
``` html
|
||||
<hx-navbar :back="false" :fixed="true" :leftSlot='false' :rightSlot='false'>
|
||||
<view style="display: flex;">
|
||||
<view class="city">
|
||||
<view>新疆</view>
|
||||
<uni-icons type="arrowdown" size="22" />
|
||||
</view>
|
||||
<view class="input-view" style="width: 100%;">
|
||||
<uni-icons type="search" size="22" color="#666666" />
|
||||
<input confirm-type="search" class="input" type="text" placeholder="输入搜索关键词" @confirm="confirm">
|
||||
</view>
|
||||
<uni-icons type="scan" size="22" style="line-height: 44px;padding-left: 8px;"/>
|
||||
</view>
|
||||
</hx-navbar>
|
||||
/*css 用于演示插槽自定义样式*/
|
||||
<style>
|
||||
.city{
|
||||
display: flex;flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
margin-left: 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
### 屏幕滑动切换显示插槽
|
||||
``` html
|
||||
<!-- 该例子演示中间插槽、右插槽屏幕滑动后的变换 -->
|
||||
<hx-navbar
|
||||
:border="true"
|
||||
:centerSlidiSwitch="true"
|
||||
:rightSlidiSwitch="true"
|
||||
:fixed="true">
|
||||
<view style="text-align: center;width: 100%;">
|
||||
<text>帮助反馈</text>
|
||||
</view>
|
||||
<view slot="centerAfter" style="text-align: center;width: 100%;">
|
||||
<text>咨询</text>
|
||||
</view>
|
||||
<block slot="right">
|
||||
<uni-icons type="qq" size="30" ></uni-icons>
|
||||
</block>
|
||||
<block slot="rightAfter">
|
||||
<uni-icons type="chat" size="30" ></uni-icons>
|
||||
</block>
|
||||
</hx-navbar>
|
||||
```
|
||||
@@ -0,0 +1,650 @@
|
||||
<template>
|
||||
|
||||
<view class="hx-navbar" >
|
||||
|
||||
<view
|
||||
:class="{'hx-navbar--fixed': fixed,'hx-navbar--shadow':shadow,'hx-navbar--border':border}"
|
||||
:style="{'background': backgroundColorRgba}"
|
||||
class="hx-navbar__content">
|
||||
<block v-if="backgroundImg">
|
||||
<image class="navbgimg" :style="bgImgHeight?`height:${bgImgHeight}`:''" :src="backgroundImg" :mode="bgImgHeight=='auto'?'widthFix':''"></image>
|
||||
</block>
|
||||
|
||||
<view :style="{ height: statusBarHeight ,'background': statusBarBackground}" class="hx-status-bar" v-if="statusBar" ></view>
|
||||
<view :style="{color:colorInfo,height: height,'line-height':height}" class="hd hx-navbar__header hx-navbar__content_view">
|
||||
<view class="hx-navbar__header-btns hx-navbar__content_view" @tap="onClickLeft" v-if="leftSlot" :style="{'color': colorInfo}">
|
||||
<block v-if="leftText.length || leftIcon.length || back">
|
||||
<view
|
||||
v-if="leftIcon.length || back"
|
||||
:class="back ? 'left_back' : ''"
|
||||
class="hx-navbar__content_view" >
|
||||
<uni-icons :type="back ? 'arrowleft' : leftIcon" :color="colorInfo" size="28"/>
|
||||
</view>
|
||||
<view
|
||||
v-if="leftText.length"
|
||||
:class="{'hx-navbar-btn-icon-left':!leftIcon.length}"
|
||||
class="hx-navbar-btn-text hx-navbar__content_view">{{ leftText }}</view>
|
||||
|
||||
</block>
|
||||
<block v-else>
|
||||
<slot name="leftAfter" v-if="leftSlidiSwitch && slotSlidiSwitch == 1" />
|
||||
<slot name="left" v-else/>
|
||||
|
||||
</block>
|
||||
</view>
|
||||
|
||||
|
||||
<view class="hx-navbar__header-container hx-navbar__content_view">
|
||||
<view
|
||||
v-if="title.length"
|
||||
class="hx-navbar__header-container-inner hx-navbar__content_view" style="position: relative;">{{ title }}
|
||||
</view>
|
||||
<!-- 标题插槽 -->
|
||||
|
||||
<block v-else>
|
||||
<slot name="centerAfter" v-if="centerSlidiSwitch && slotSlidiSwitch == 1"/>
|
||||
<slot v-else/>
|
||||
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<view :class="title.length?'hx-navbar__header-btns-right':''"
|
||||
class="hx-navbar__header-btns hx-navbar__content_view"
|
||||
@tap="onClickRight"
|
||||
v-if="rightSlot">
|
||||
<!-- 优先显示图标 -->
|
||||
<block v-if="rightIcon.length || rightText.length">
|
||||
<view class="hx-navbar__content_view" v-if="rightIcon.length">
|
||||
<uni-icons :type="rightIcon" :color="colorInfo" size="28"/>
|
||||
</view>
|
||||
<view v-if="rightText.length" class="hx-navbar-btn-text hx-navbar__content_view">{{ rightText }}</view>
|
||||
</block>
|
||||
<block v-else>
|
||||
<slot name="rightAfter" v-if="rightSlidiSwitch && slotSlidiSwitch == 1"/>
|
||||
<slot name="right" v-else/>
|
||||
</block>
|
||||
|
||||
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view
|
||||
v-if="placeholder"
|
||||
class="hx-navbar__placeholder">
|
||||
<view :style="{ height: statusBarHeight}" class="hx-status-bar" v-if="statusBar" ></view>
|
||||
|
||||
<view :style="{ height: height}" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import uniIcons from "@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue"
|
||||
//获取系统状态栏高度
|
||||
var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
|
||||
export default {
|
||||
name: "hx-navbar",
|
||||
components: {
|
||||
uniIcons
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
statusBarHeight: statusBarHeight,
|
||||
transparentValue: 0,
|
||||
navTransparentFixedFontColor: '#fff',
|
||||
|
||||
statusBarFontColorInfo: [],
|
||||
backgroundColorRgba: 'rgba(255,255,255,1)',
|
||||
backgroundColorRgb: 'rgb(222,222,222)',
|
||||
colorInfo: '#000000',
|
||||
placeholder: false,
|
||||
colorContainer: null,
|
||||
slotSlidiSwitch: 0
|
||||
|
||||
};
|
||||
},
|
||||
props:{
|
||||
height:{
|
||||
type: String,
|
||||
default: "44px"
|
||||
},
|
||||
//导航栏占位符 显示(show),隐藏(hidden),自动(auto:如果头部为固定fiexd ,则显示占位符)
|
||||
barPlaceholder:{
|
||||
type: String,
|
||||
default: "auto"
|
||||
},
|
||||
//返回上一页
|
||||
back:{
|
||||
type: [Boolean, String],
|
||||
default: true
|
||||
},
|
||||
//标题
|
||||
title: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
//是否开启左插槽
|
||||
leftSlot:{
|
||||
type: [Boolean, String],
|
||||
default: true
|
||||
},
|
||||
//是否开启右插槽
|
||||
rightSlot:{
|
||||
type: [Boolean, String],
|
||||
default: true
|
||||
},
|
||||
|
||||
//左边文字
|
||||
leftText: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
//右插槽文字
|
||||
rightText: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
//左插槽图标
|
||||
leftIcon: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
//右插槽图标
|
||||
rightIcon: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
//是否固定头
|
||||
fixed: {
|
||||
type: [Boolean, String],
|
||||
default: false
|
||||
},
|
||||
//文字颜色
|
||||
color: {
|
||||
type: [Array,String],
|
||||
default: "#000000"
|
||||
},
|
||||
//导航栏背景颜色
|
||||
backgroundColor: {
|
||||
type: Array,
|
||||
default: function(){
|
||||
return new Array([255,255,255],[255,255,255]);
|
||||
}
|
||||
},
|
||||
//线性渐变角度
|
||||
backgroundColorLinearDeg: {
|
||||
type: String,
|
||||
default: '45'
|
||||
},
|
||||
//背景图片
|
||||
backgroundImg: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
bgImgHeight:{
|
||||
type:String,
|
||||
default:'auto'
|
||||
},
|
||||
//背景透明(show,hidden,auto)
|
||||
transparent: {
|
||||
type: String,
|
||||
default: 'show'
|
||||
},
|
||||
//状态栏字体颜色,只支持黑(#000000)和白(#FFFFFF)两种颜色。(,)
|
||||
statusBarFontColor:{
|
||||
type: [Array,String],
|
||||
default:function(){
|
||||
return new Array("#000000","#000000");
|
||||
}
|
||||
},
|
||||
//是否包含状态栏
|
||||
statusBar: {
|
||||
type: [Boolean, String],
|
||||
default: true
|
||||
},
|
||||
//状态栏背景颜色
|
||||
statusBarBackground:{
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
//导航栏阴影
|
||||
shadow: {
|
||||
type: [String, Boolean],
|
||||
default: false
|
||||
},
|
||||
//导航栏边框
|
||||
border: {
|
||||
type: [String, Boolean],
|
||||
default: false
|
||||
},
|
||||
//跳至普通页面
|
||||
defaultBackUrl: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
//跳至tabber页面
|
||||
backTabbarUrl: {
|
||||
type: String,
|
||||
default: '/pages/home/index'
|
||||
},
|
||||
//滑动后切换左插槽
|
||||
leftSlidiSwitch:{
|
||||
type: [Boolean,String],
|
||||
default: false,
|
||||
},
|
||||
//滑动后切换中间插槽
|
||||
centerSlidiSwitch:{
|
||||
type: [Boolean,String],
|
||||
default: false
|
||||
},
|
||||
//滑动后切换右插槽
|
||||
rightSlidiSwitch:{
|
||||
type: [Boolean,String],
|
||||
default: false
|
||||
},
|
||||
//页面的onPageScroll
|
||||
pageScroll:{
|
||||
type: Object,
|
||||
default:function(){
|
||||
return {}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
},
|
||||
created(){
|
||||
var that = this;
|
||||
//是否添加占位符
|
||||
switch (that.barPlaceholder){
|
||||
case 'show':
|
||||
that.placeholder = true;
|
||||
break;
|
||||
case 'hidden':
|
||||
that.placeholder = false;
|
||||
break;
|
||||
case 'auto':
|
||||
if(that.fixed){
|
||||
that.placeholder = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//设置状态栏文字颜色
|
||||
that.setStatusBarFontColor();
|
||||
|
||||
//文字颜色
|
||||
that.colorContainer = typeof that.color == 'object' ? that.color : [that.color,that.color];
|
||||
that.colorInfo = that.colorContainer[0];
|
||||
//导航栏透明设置 及监听滚动
|
||||
switch (that.transparent){
|
||||
case 'show':
|
||||
that.transparentValue = 1;
|
||||
break;
|
||||
case 'hidden':
|
||||
that.transparentValue = 0;
|
||||
break;
|
||||
case 'auto':
|
||||
this.setTVAuto(that.pageScroll)
|
||||
break;
|
||||
}
|
||||
that.setBgColor();
|
||||
|
||||
//滑动切换
|
||||
if(that.fixed && (that.leftSlidiSwitch || that.centerSlidiSwitch || that.rightSlidiSwitch)){
|
||||
that.doScroll(that.pageScroll);
|
||||
}
|
||||
|
||||
},
|
||||
watch:{
|
||||
pageScroll(val,oldVal){
|
||||
var that = this;
|
||||
//导航栏透明设置 及监听滚动
|
||||
switch (that.transparent){
|
||||
case 'show':
|
||||
that.transparentValue = 1;
|
||||
break;
|
||||
case 'hidden':
|
||||
that.transparentValue = 0;
|
||||
break;
|
||||
case 'auto':
|
||||
this.setTVAuto(val)
|
||||
break;
|
||||
}
|
||||
//滑动切换
|
||||
if(that.fixed && (that.leftSlidiSwitch || that.centerSlidiSwitch || that.rightSlidiSwitch)){
|
||||
that.doScroll(val);
|
||||
}
|
||||
},
|
||||
//监控透明度变化
|
||||
transparentValue(val,oldVal) {
|
||||
var that = this;
|
||||
//this.settingColor();
|
||||
|
||||
//头条小程序不支持setNavigationBarColor方法
|
||||
// #ifndef MP-TOUTIAO || H5
|
||||
if(oldVal > 0.8){
|
||||
uni.setNavigationBarColor({
|
||||
frontColor: that.statusBarFontColorInfo[1],
|
||||
backgroundColor: that.backgroundColorRgb
|
||||
});
|
||||
}else if(oldVal < 0.2){
|
||||
uni.setNavigationBarColor({
|
||||
frontColor: that.statusBarFontColorInfo[0],
|
||||
backgroundColor: that.backgroundColorRgb
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-TOUTIAO
|
||||
if (tt.setNavigationBarColor) {
|
||||
if(oldVal > 0.8){
|
||||
tt.setNavigationBarColor({
|
||||
frontColor: that.statusBarFontColorInfo[1],
|
||||
backgroundColor: that.backgroundColorRgb,
|
||||
success(res) {},
|
||||
fail(res) {}
|
||||
});
|
||||
}else if(oldVal < 0.2){
|
||||
tt.setNavigationBarColor({
|
||||
frontColor: that.statusBarFontColorInfo[0],
|
||||
backgroundColor: that.backgroundColorRgb,
|
||||
success(res) {},
|
||||
fail(res) {}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log("hx-navbar 提示:当前客户端版本过低,无法使用状态栏颜色修改功能,请升级(基础库1.40+)。")
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
//监听背景颜色
|
||||
backgroundColor(val,old){
|
||||
var that = this;
|
||||
that.setBgColor()
|
||||
},
|
||||
|
||||
color(val,old){
|
||||
var that = this;
|
||||
//文字颜色
|
||||
/* that.colorContainer = typeof val == 'object' ? val : [val,val];
|
||||
that.colorInfo = that.colorContainer[0]; */
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
onClickLeft () {
|
||||
if(this.back){
|
||||
if(getCurrentPages().length>1){
|
||||
uni.navigateBack();
|
||||
}else{
|
||||
// #ifdef H5
|
||||
history.back()
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
if(this.defaultBackUrl){
|
||||
uni.redirectTo({
|
||||
url:this.defaultBackUrl
|
||||
})
|
||||
}else{
|
||||
if(this.backTabbarUrl){
|
||||
uni.reLaunch({
|
||||
url: this.backTabbarUrl
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
}else{
|
||||
this.$emit('click-left')
|
||||
}
|
||||
},
|
||||
onClickRight () {
|
||||
this.$emit('click-right')
|
||||
},
|
||||
|
||||
//监听滚动后的操作
|
||||
doScroll(e){
|
||||
let that = this;
|
||||
that.$emit('scroll', e);
|
||||
if (e.scrollTop > 100) {
|
||||
that.slotSlidiSwitch = 1;
|
||||
} else {
|
||||
that.slotSlidiSwitch = 0
|
||||
}
|
||||
},
|
||||
//滑动渐变
|
||||
setTVAuto(e){
|
||||
let that = this;
|
||||
that.$emit('scroll', e);
|
||||
if (e.scrollTop > 100) {
|
||||
that.transparentValue = 1;
|
||||
that.colorInfo = that.colorContainer[1];
|
||||
} else {
|
||||
that.transparentValue = e.scrollTop / 100;
|
||||
that.colorInfo = that.colorContainer[0];
|
||||
}
|
||||
that.setBgColor();
|
||||
},
|
||||
//背景颜色
|
||||
setBgColor(){
|
||||
|
||||
var that = this;
|
||||
//如果存在背景图片则背景颜色失效
|
||||
// if(that.backgroundImg){
|
||||
// that.backgroundColorRgba = "url(" + that.backgroundImg + ")";
|
||||
// return;
|
||||
// }
|
||||
|
||||
//背景颜色
|
||||
if(typeof that.backgroundColor[0] == 'object'){
|
||||
let l = that.backgroundColor.length;
|
||||
if( l >= 2){
|
||||
let rgbStr = "linear-gradient("+ that.backgroundColorLinearDeg +"deg,";
|
||||
let c = null;
|
||||
for(var i in that.backgroundColor){
|
||||
c = that.backgroundColor[i];
|
||||
rgbStr += "rgba("+ c[0] + "," + c[1] + "," + c[2] +"," + that.transparentValue+")";
|
||||
|
||||
if(l != (i*1)+1){
|
||||
rgbStr += ",";
|
||||
}
|
||||
}
|
||||
rgbStr += ")";
|
||||
that.backgroundColorRgba = rgbStr;
|
||||
}
|
||||
|
||||
}else{
|
||||
let rgbStr = that.backgroundColor[0] + ','+ that.backgroundColor[1] + ','+ that.backgroundColor[2];
|
||||
that.backgroundColorRgb= 'rgb('+ rgbStr + ')';
|
||||
that.backgroundColorRgba = 'rgba('+ rgbStr +',' + that.transparentValue+')';
|
||||
}
|
||||
},
|
||||
setStatusBarFontColor(){
|
||||
var that = this;
|
||||
if(typeof that.statusBarFontColor == 'string'){
|
||||
that.statusBarFontColorInfo = [that.statusBarFontColor,that.statusBarFontColor];
|
||||
}else if(typeof that.statusBarFontColor == 'object'){
|
||||
if (that.statusBarFontColor.length==1){
|
||||
that.statusBarFontColorInfo = [that.statusBarFontColor[0],that.statusBarFontColor[0]];
|
||||
}else if(that.statusBarFontColor.length>=2){
|
||||
that.statusBarFontColorInfo = [that.statusBarFontColor[0],that.statusBarFontColor[1]];
|
||||
}
|
||||
}
|
||||
// #ifndef MP-TOUTIAO || H5
|
||||
uni.setNavigationBarColor({
|
||||
frontColor: that.statusBarFontColorInfo[0],
|
||||
backgroundColor: that.backgroundColorRgb
|
||||
});
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-TOUTIAO
|
||||
if (tt.setNavigationBarColor) {
|
||||
tt.setNavigationBarColor({
|
||||
frontColor: that.statusBarFontColorInfo[0],
|
||||
backgroundColor: that.backgroundColorRgb
|
||||
});
|
||||
} else {
|
||||
console.log("hx-navbar 提示:当前客户端版本过低,无法使用状态栏颜色修改功能,请升级(基础库1.40+)。")
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
|
||||
},
|
||||
destroyed(){
|
||||
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
$nav-height: 44px;
|
||||
|
||||
.hd{
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
//防止其他ui影响
|
||||
// .hx-navbar uni-view,
|
||||
// .hx-navbar uni-scroll-view,
|
||||
// .hx-navbar uni-swiper,
|
||||
// .hx-navbar uni-button,
|
||||
// .hx-navbar uni-input,
|
||||
// .hx-navbar uni-textarea,
|
||||
// .hx-navbar uni-label,
|
||||
// .hx-navbar uni-navigator,
|
||||
// .hx-navbar uni-image {
|
||||
// box-sizing: unset;
|
||||
// }
|
||||
.hx-navbar {
|
||||
position: relative;
|
||||
padding-top: 0;
|
||||
overflow: hidden;
|
||||
|
||||
&__content {
|
||||
display: block;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
/*background-color: $uni-bg-color*/;
|
||||
overflow: hidden;
|
||||
.navbgimg{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.hx-navbar__content_view {
|
||||
// line-height: $nav-height;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
}
|
||||
.hx-status-bar {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
height: var(--status-bar-height);
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
}
|
||||
|
||||
&__header {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
height: $nav-height;
|
||||
line-height: $nav-height;
|
||||
font-size: 36upx;
|
||||
transition: color 0.5s ease 0s;
|
||||
&-btns {
|
||||
display: inline-flex;
|
||||
flex-wrap: nowrap;
|
||||
flex-shrink: 0;
|
||||
min-width: 30px;
|
||||
padding: 0 6px;
|
||||
|
||||
&:first-child {
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
min-width: 54px;
|
||||
}
|
||||
|
||||
&-right:last-child{
|
||||
width: 120upx;
|
||||
text-align: right;
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
}
|
||||
|
||||
&-container {
|
||||
width: 100%;
|
||||
margin: 0 10upx;
|
||||
|
||||
&-inner {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
font-size: 36upx;
|
||||
|
||||
// padding-right: 60upx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__placeholder {
|
||||
&-view {
|
||||
height: $nav-height;
|
||||
}
|
||||
}
|
||||
|
||||
&--fixed {
|
||||
position: fixed;
|
||||
top:0;
|
||||
z-index: 998;
|
||||
}
|
||||
|
||||
&--shadow {
|
||||
box-shadow: 0 2upx 12upx #ccc;
|
||||
}
|
||||
|
||||
&--border:after {
|
||||
position: absolute;
|
||||
z-index: 3;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 1px;
|
||||
content: '';
|
||||
-webkit-transform: scaleY(.5);
|
||||
transform: scaleY(.5);
|
||||
background-color: #efefef;
|
||||
}
|
||||
}
|
||||
.left_back{
|
||||
padding-left: 12upx;
|
||||
padding-right: 12upx;
|
||||
}
|
||||
.pink-dot{
|
||||
width:24rpx;
|
||||
height:24px;
|
||||
background:rgba(255,86,74,0.4);
|
||||
border-radius:50%;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user