微信小程序自定义状态栏组件,提取自(colorui)

<view class="cu-custom" style="height:{{CustomBar}}px">
  <view class="cu-bar fixed {{bgImage!=''?'none-bg text-white bg-img':''}} {{bgColor}}" style="height:{{CustomBar}}px;padding-top:{{StatusBar}}px;{{bgImage?'background-image:url(' + bgImage+')':''}}">
    <view class="action" bindtap="BackPage" wx:if="{{isBack}}">
      <view class="icon iconfont icon-fenxiang"></view>
      <slot name="backText"></slot>
    </view>
    <view class="action border-custom"  wx:if="{{isCustom}}" style="width:{{Custom.width}}px;height:{{Custom.height}}px;margin-left:calc(750rpx - {{Custom.right}}px)">
      <view class="icon iconfont icon-fenxiang" bindtap="BackPage"></view>
      <view class="icon iconfont icon-home" bindtap="toHome"></view>
    </view>
    <view class="content" style="top:{{StatusBar}}px">
      <slot name="content"></slot>
    </view>
    <slot name="right"></slot>
  </view>
</view>

 

const app = getApp();
Component({
   /**
    * 组件的一些选项
    */
   options: {
      addGlobalClass: true,
      multipleSlots: true
   },
   /**
    * 组件的对外属性
    */
   properties: {
      bgColor: {
         type: String,
         default: '#ff0000'
      },
      isCustom: {
         type: [Boolean, String],
         default: false
      },
      isBack: {
         type: [Boolean, String],
         default: false
      },
      bgImage: {
         type: String,
         default: ''
      },
   },
   /**
    * 组件的初始数据
    */
   data: {
      StatusBar: '',
      CustomBar: '',
      Custom: ''
   },
   /**
    * 组件的方法列表
    */
   methods: {
      BackPage() {
         console.log(1);
         wx.navigateBack();
      },
      toHome() {
         console.log(2);
         wx.reLaunch({
            url: '/pages/index/index',
         })
      }
   },
   attached() {
      wx.getSystemInfo({
         success: e => {
            let custom = wx.getMenuButtonBoundingClientRect();
            this.setData({
               StatusBar: e.statusBarHeight,
               CustomBar: custom.bottom + custom.top - e.statusBarHeight,
               Custom: custom
            })
         }
      })
   }
})
{
   "component": true,
   "usingComponents": {}
}
/* components/custom/index.wxss */
@font-face {
   font-family: 'iconfont';
   src: url('data:font/ttf;charset=utf-8;base64,AAEAAAANAIAAAwBQRkZUTZLmH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vAC8AZgBvAG4AdABlAGwAbABvAC4AYwBvAG0AAGh0dHA6Ly9mb250ZWxsby5jb20AAAAAAgAAAAAAAAAKAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAFAAAAAQACAQIBAwRob21lCGZlbnhpYW5nAAAAAAAB//8AAgABAAAADAAAABYAAAACAAEAAwAEAAEABAAAAAIAAAAAAAAAAQAAAADVpCcIAAAAAN6g+q8AAAAA3qD6rw==') format('truetype');
   font-weight: normal;
   font-style: normal;
   font-display: swap;
}

.iconfont {
   font-family: "iconfont" !important;
   font-size: 38rpx;
   font-style: normal;
   color: #FFFFFF;
   -webkit-font-smoothing: antialiased;
   -moz-osx-font-smoothing: grayscale;
 }

 .icon-fenxiang:before {
   content: "\f016f";
 }
 
 .icon-home:before {
   content: "\e821";
 }

.cu-custom {
	display: block;
   position: fixed;
   top: 0;
   z-index: 9999;
   pointer-events: none;
}

.cu-custom .cu-bar .content {
	width: calc(100% - 440rpx);
}


.cu-custom .cu-bar .content image {
	height: 60rpx;
	width: 240rpx;
}

.cu-custom .cu-bar {
	min-height: 0px;
	padding-right: 220rpx;
	box-shadow: 0rpx 0rpx 0rpx;
   z-index: 9999;
}

.cu-custom .cu-bar .border-custom {
	position: relative;
	background: rgba(0, 0, 0, 0.15);
	border-radius: 1000rpx;
	height: 30px;
}

.cu-custom .cu-bar .border-custom::after {
	content: " ";
	width: 200%;
	height: 200%;
	position: absolute;
	top: 0;
	left: 0;
	border-radius: inherit;
	transform: scale(0.5);
	transform-origin: 0 0;
	pointer-events: none;
	box-sizing: border-box;
	border: 1rpx solid #FFFFFF;
	opacity: 0.5;
}

.cu-custom .cu-bar .border-custom::before {
	content: " ";
	width: 1rpx;
	height: 110%;
	position: absolute;
	top: 22.5%;
	left: 0;
	right: 0;
	margin: auto;
	transform: scale(0.5);
	transform-origin: 0 0;
	pointer-events: none;
	box-sizing: border-box;
	opacity: 0.6;
	background-color: #FFFFFF;
}

.cu-custom .cu-bar .border-custom text {
	display: block;
	flex: 1;
	margin: auto !important;
	text-align: center;
	font-size: 34rpx;
}



.cu-bar {
	display: flex;
	position: relative;
	align-items: center;
	min-height: 100rpx;
	justify-content: space-between;
}

.cu-bar .action {
	display: flex;
	align-items: center;
	height: 100%;
	justify-content: space-evenly;
   max-width: 100%;
   pointer-events: auto;
}

.cu-bar .action.border-title {
	position: relative;
	top: -10rpx;
}

.cu-bar .action.border-title text[class*="bg-"]:last-child {
	position: absolute;
	bottom: -0.5rem;
	min-width: 2rem;
	height: 6rpx;
	left: 0;
}

.cu-bar .action.sub-title {
	position: relative;
	top: -0.2rem;
}

.cu-bar .action.sub-title text {
	position: relative;
	z-index: 1;
}

.cu-bar .action.sub-title text[class*="bg-"]:last-child {
	position: absolute;
	display: inline-block;
	bottom: -0.2rem;
	border-radius: 6rpx;
	width: 100%;
	height: 0.6rem;
	left: 0.6rem;
	opacity: 0.3;
	z-index: 0;
}

.cu-bar .action.sub-title text[class*="text-"]:last-child {
	position: absolute;
	display: inline-block;
	bottom: -0.7rem;
	left: 0.5rem;
	opacity: 0.2;
	z-index: 0;
	text-align: right;
	font-weight: 900;
	font-size: 36rpx;
}

.cu-bar.justify-center .action.border-title text:last-child,
.cu-bar.justify-center .action.sub-title text:last-child {
	left: 0;
	right: 0;
	margin: auto;
	text-align: center;
}

.cu-bar .action:first-child {
	margin-left: 30rpx;
	font-size: 30rpx;
}

.cu-bar .action text.text-cut {
	text-align: left;
	width: 100%;
}

.cu-bar .cu-avatar:first-child {
	margin-left: 20rpx;
}

.cu-bar .action:first-child>text[class*="cuIcon-"] {
	margin-left: -0.3em;
	margin-right: 0.3em;
}

.cu-bar .action:last-child {
	margin-right: 30rpx;
}

.cu-bar .action>text[class*="cuIcon-"],
.cu-bar .action>view[class*="cuIcon-"] {
	font-size: 36rpx;
}

.cu-bar .action>text[class*="cuIcon-"]+text[class*="cuIcon-"] {
	margin-left: 0.5em;
}

.cu-bar .content {
	position: absolute;
	text-align: center;
	width: calc(100% - 340rpx);
	left: 0;
	right: 0;
	bottom: 0;
	top: 0;
	margin: auto;
	height: 60rpx;
	font-size: 32rpx;
	line-height: 60rpx;
	cursor: none;
	pointer-events: none;
	text-overflow: ellipsis;
	white-space: nowrap;
	overflow: hidden;
}

.cu-bar.ios .content {
	bottom: 7px;
	height: 30px;
	font-size: 32rpx;
	line-height: 30px;
}

.cu-bar.btn-group {
	justify-content: space-around;
}

.cu-bar.btn-group button {
	padding: 20rpx 32rpx;
}

.cu-bar.btn-group button {
	flex: 1;
	margin: 0 20rpx;
	max-width: 50%;
}

.cu-bar .search-form {
	background-color: #f5f5f5;
	line-height: 64rpx;
	height: 64rpx;
	font-size: 24rpx;
	color: var(--black);
	flex: 1;
	display: flex;
	align-items: center;
	margin: 0 30rpx;
}

.cu-bar .search-form+.action {
	margin-right: 30rpx;
}

.cu-bar .search-form input {
	flex: 1;
	padding-right: 30rpx;
	height: 64rpx;
	line-height: 64rpx;
	font-size: 26rpx;
	background-color: transparent;
}

.cu-bar .search-form [class*="cuIcon-"] {
	margin: 0 0.5em 0 0.8em;
}

.cu-bar .search-form [class*="cuIcon-"]::before {
	top: 0rpx;
}

.cu-bar.fixed,
.nav.fixed {
	position: fixed;
	width: 100%;
	top: 0;
	z-index: 1024;
	/* box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0.1); */
}

.cu-bar.foot {
	position: fixed;
	width: 100%;
	bottom: 0;
	z-index: 1024;
	box-shadow: 0 -1rpx 6rpx rgba(0, 0, 0, 0.1);
}

.cu-bar.tabbar {
	padding: 0;
	height: calc(100rpx + env(safe-area-inset-bottom) / 2);
	padding-bottom: calc(env(safe-area-inset-bottom) / 2);
}

.cu-tabbar-height {
	min-height: 100rpx;
	height: calc(100rpx + env(safe-area-inset-bottom) / 2);
}

.cu-bar.tabbar.shadow {
	box-shadow: 0 -1rpx 6rpx rgba(0, 0, 0, 0.1);
}

.cu-bar.tabbar .action {
	font-size: 22rpx;
	position: relative;
	flex: 1;
	text-align: center;
	padding: 0;
	display: block;
	height: auto;
	line-height: 1;
	margin: 0;
	overflow: initial;
}

.cu-bar.tabbar.shop .action {
	width: 140rpx;
	flex: initial;
}

.cu-bar.tabbar .action.add-action {
	position: relative;
	z-index: 2;
	padding-top: 50rpx;
	background-color: inherit;
}

.cu-bar.tabbar .action.add-action [class*="cuIcon-"] {
	position: absolute;
	width: 70rpx;
	z-index: 2;
	height: 70rpx;
	border-radius: 50%;
	line-height: 70rpx;
	font-size: 50rpx;
	top: -35rpx;
	left: 0;
	right: 0;
	margin: auto;
	padding: 0;
}

.cu-bar.tabbar .action.add-action::after {
	content: "";
	position: absolute;
	width: 100rpx;
	height: 100rpx;
	top: -50rpx;
	left: 0;
	right: 0;
	margin: auto;
	box-shadow: 0 -3rpx 8rpx rgba(0, 0, 0, 0.08);
	border-radius: 50rpx;
	background-color: inherit;
	z-index: 0;
}

.cu-bar.tabbar .action.add-action::before {
	content: "";
	position: absolute;
	width: 100rpx;
	height: 30rpx;
	bottom: 30rpx;
	left: 0;
	right: 0;
	margin: auto;
	background-color: inherit;
	z-index: 1;
}

.cu-bar.tabbar .btn-group {
	flex: 1;
	display: flex;
	justify-content: space-around;
	align-items: center;
	padding: 0 10rpx;
}

.cu-bar.tabbar button.action::after {
	border: 0;
}

.cu-bar.tabbar .action [class*="cuIcon-"] {
	width: 100rpx;
	position: relative;
	display: block;
	height: auto;
	margin: 0 auto 10rpx;
	text-align: center;
	font-size: 40rpx;
}

.cu-bar.tabbar .action .cuIcon-cu-image {
	margin: 0 auto;
}

.cu-bar.tabbar .action .cuIcon-cu-image image {
	width: 50rpx;
	height: 50rpx;
	display: inline-block;
}

.cu-bar.tabbar .submit {
	align-items: center;
	display: flex;
	justify-content: center;
	text-align: center;
	position: relative;
	flex: 2;
	align-self: stretch;
}

.cu-bar.tabbar .submit:last-child {
	flex: 2.6;
}

.cu-bar.tabbar .submit+.submit {
	flex: 2;
}

.cu-bar.tabbar.border .action::before {
	content: " ";
	width: 200%;
	height: 200%;
	position: absolute;
	top: 0;
	left: 0;
	transform: scale(0.5);
	transform-origin: 0 0;
	border-right: 1rpx solid rgba(0, 0, 0, 0.1);
	z-index: 3;
}

.cu-bar.tabbar.border .action:last-child:before {
	display: none;
}

.cu-bar.input {
	padding-right: 20rpx;
	background-color: #FFFFFF;
}

.cu-bar.input input {
	overflow: initial;
	line-height: 64rpx;
	height: 64rpx;
	min-height: 64rpx;
	flex: 1;
	font-size: 30rpx;
	margin: 0 20rpx;
}

.cu-bar.input .action {
	margin-left: 20rpx;
}

.cu-bar.input .action [class*="cuIcon-"] {
	font-size: 48rpx;
}

.cu-bar.input input+.action {
	margin-right: 20rpx;
	margin-left: 0rpx;
}

.cu-bar.input .action:first-child [class*="cuIcon-"] {
	margin-left: 0rpx;
}

.svg_icon {
   display: inline-flex;
   width: 60rpx;
   height: 60rpx;
   overflow: hidden;
  }
   
  .svg_icon-inner {
   width: 100%;
   height: 100%;
   transform: translateY(-100%);
   filter: drop-shadow(0 100% 0 #ffffff);
  }

使用

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值