效果图

页面
<cell
title="安全设置"
note="手机号/密码"
>
</cell>
<cell
cell-class="mycell"
title="通用"
>
</cell>
<cell
url="/news/pages/article/article"
title="首页"
icon="/images/home.png"
>
</cell>
<cell
title="我的"
icon="/images/me.png"
>
</cell>
<cell
title="听筒模式"
toggle="{{true}}"
bindch="chang"
>
</cell>
<cell
title="搜索"
>
<icon slot="iconright" size="20" type="search"></icon>
</cell>
<cell url="/pages/logs/logs">
<view slot="title"><text>通知</text><text class="dot"></text></view>
</cell>
<cell url="/pages/logs/logs">
<view slot="title"><text>优惠</text><text class="com">10元优惠劵</text></view>
</cell>
页面js
chang(e){
let msg=e.detail.value?'开启':'关闭'
wx.showToast({
title: '听筒模式已'+msg,
})
},
页面css
.mycell{
height: 100rpx !important;
color:red !important;
}
.dot{
display: inline-block;
width: 15rpx;
height: 15rpx;
border-radius: 50%;
background-color: red;
margin-left: 10rpx;
}
.com{
display: inline-block;
width: 150rpx;
height: 40rpx;
line-height: 40rpx;
text-align: center;
background-color: orange;
color: #ffffff;
margin-left: 10rpx;
border-radius: 4rpx;
}
组件页面
<view class="cell cell-class" bindtap="changeHd">
<view class="icon">
<image mode="widthFix" wx:if="{{icon!=''}}" src="{{icon}}"/>
</view>
<view class="content">
<view wx:if="{{title}}" class="title">{{title}}</view>
<slot wx:else name="title"/>
<view class="tip">
<view class="note">{{note}}</view>
<view wx:if="{{toggle}}" class="toggle">
<switch bindchange="toggleChange"></switch>
</view>
<view wx:else>
<view class="arrow" wx:if="{{url}}"></view>
<slot name="iconright" wx:else class="iconright"/>
</view>
</view>
</view>
</view>
组件js
Component({
options:{
multipleSlots:true,
},
externalClasses:["cell-class"],
properties: {
title:{type:String,value:''},
note:{type:String,value:''},
icon:{type:String,value:''},
url:{type:String,value:''},
toggle:{type:Boolean,value:false}
},
methods: {
changeHd(){
console.log(this.data.url)
if(this.data.url){
wx.navigateTo({
url:this.data.url,
})
}
},
toggleChange(e){
this.triggerEvent("ch",{value:e.detail.value})
}
}
})
.cell{
display: flex;
height: 88rpx;
background-color: #ffffff;
border-bottom: 1rpx solid #f0f0f0;
}
.cell .icon{
display: flex;
align-items: center;
margin-left: 30rpx;
}
.cell .icon image{
width: 40rpx;
height: 40rpx;
}
.cell .content{
flex: 1;
display: flex;
justify-content: space-between;
align-items: center;
}
.tip{
display: flex;
padding-right: 30rpx;
}
.arrow{
height: 26rpx;
width: 26rpx;
border-top: 1rpx solid #ddd;
border-right: 1rpx solid #ddd;
transform: rotate(45deg) translate(0,13rpx);
margin-left: 30rpx;
}
.note{
font-size: 28rpx;
color: #999;
}