tabbar 支持 iconpath selectedIconPath传入

This commit is contained in:
Wang Kejun 2023-11-03 19:05:24 +08:00
parent 28830909a0
commit fc7bc6a4ec
3 changed files with 31 additions and 6 deletions

View File

@ -37,8 +37,8 @@
.@{component}__item-image {
display: block;
width: 52rpx;
height: 52rpx;
width: 22px;
height: 22px;
}
.@{component}__item-text {

View File

@ -4,11 +4,20 @@ export default OakComponent({
// 背景色
bgColor: '',
// 背景图
bgImg: '',
bgImgUrl: '',
// 当前选中索引
selectedIndex: 0,
// tab 项
list: [] as { redDot: boolean; text: string; pagePath: string }[],
list: [] as {
redDot: boolean;
text: string;
pagePath: string;
iconName?: string;
selectedIconName?: string;
iconPath?: string;
selectedIconPath?: string;
iconSize?: string;
}[],
color: '#666',
selectedColor: '',
},

View File

@ -1,10 +1,26 @@
<view wx:if="{{showTabBar}}" class="tab-bar"
style="{{bgColor?'background-color:'+bgColor+';':''}} {{bgImg?'background-image: url('+bgImg+');':''}}">
style="{{bgColor?'background-color:'+bgColor+';':''}} {{bgImg?'background-image: url('+bgImgUrl+');':''}}">
<view class="tab-bar__item-wrapper" data-index="{{index}}" mut-bind:tap="onTapItem" style="width:{{750/list.length}}rpx" wx:for="{{list}}" wx:key="index">
<view class="tab-bar__item-container">
<!-- 标签图标 -->
<l-badge show="{{item.redDot}}" dot="{{item.redDot===true}}" value="{{item.redDot}}" data-index="{{index}}" mut-bind:lintap="onTapItem">
<oak-icon name="{{selectedIndex===index?item.selectedIconName:item.iconName}}" size="{{item.iconSize || 22}}" color="{{selectedIndex===index? selectedColor : color}}" />
<block wx:if="{{selectedIndex===index}}">
<block wx:if="{{item.selectedIconPath}}">
<image class="tab-bar__item-image" src={{item.selectedIconPath}} style="{{item.iconSize ? 'width: '+item.iconSize+ 'px;' : ''}} {{item.iconSize ? 'height: '+item.iconSize+ 'px;' : ''}}" />
</block>
<block wx:else>
<oak-icon name="{{item.selectedIconName}}" size="{{item.iconSize || 22}}" color="{{selectedColor}}" />
</block>
</block>
<block wx:else>
<block wx:if="{{item.iconPath}}">
<image class="tab-bar__item-image" src={{item.iconPath}} style="{{item.iconSize ? 'width: '+item.iconSize+ 'px;' : ''}} {{item.iconSize ? 'height: '+item.iconSize+ 'px;' : ''}}" />
</block>
<block wx:else>
<oak-icon name="{{item.iconName}}" size="{{item.iconSize || 22}}" color="{{color}}" />
</block>
</block>
</l-badge>
<!-- 标签文字 -->
<view wx:if="{{item.text}}" class="tab-bar__item-text {{ selectedIndex===index ? 'tab-bar__item--selected' : '' }}" style="color: {{selectedIndex===index ? selectedColor : color}}">