初始化
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
|
||||
Component({
|
||||
options: {
|
||||
addGlobalClass: true,
|
||||
pureDataPattern: /^_/,
|
||||
multipleSlots: true
|
||||
},
|
||||
properties: {
|
||||
tabs: {type: Array, value: []},
|
||||
tabClass: {type: String, value: ''},
|
||||
swiperClass: {type: String, value: ''},
|
||||
activeClass: {type: String, value: ''},
|
||||
tabUnderlineColor: {type: String, value: '#07c160'},
|
||||
tabActiveTextColor: {type: String, value: '#000000'},
|
||||
tabInactiveTextColor: {type: String, value: '#000000'},
|
||||
tabBackgroundColor: {type: String, value: '#ffffff'},
|
||||
activeTab: {type: Number, value: 0},
|
||||
swipeable: {type: Boolean, value: true},
|
||||
animation: {type: Boolean, value: true},
|
||||
duration: {type: Number, value: 500},
|
||||
theme: {type: String, value: 'light'} // light dark
|
||||
},
|
||||
data: {
|
||||
currentView: 0
|
||||
},
|
||||
observers: {
|
||||
activeTab: function activeTab(_activeTab) {
|
||||
const len = this.data.tabs.length
|
||||
if (len === 0) return
|
||||
let currentView = _activeTab - 1
|
||||
if (currentView < 0) currentView = 0
|
||||
if (currentView > len - 1) currentView = len - 1
|
||||
this.setData({currentView})
|
||||
}
|
||||
},
|
||||
lifetimes: {
|
||||
created: function created() {}
|
||||
},
|
||||
methods: {
|
||||
handleTabClick: function handleTabClick(e) {
|
||||
const index = e.currentTarget.dataset.index
|
||||
this.setData({activeTab: index})
|
||||
this.triggerEvent('tabclick', {index})
|
||||
},
|
||||
handleSwiperChange: function handleSwiperChange(e) {
|
||||
const index = e.detail.current
|
||||
this.setData({activeTab: index})
|
||||
this.triggerEvent('change', {index})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<view class="weui-tabs">
|
||||
<view class="weui-tabs-bar__wrp">
|
||||
<scroll-view scroll-x scroll-into-view="item_{{currentView}}" scroll-with-animation="{{animation}}">
|
||||
<view class="weui-tabs-bar__content">
|
||||
<block wx:for="{{tabs}}" wx:key="title">
|
||||
<view id="item_{{index}}" class="weui-tabs-bar__item" style="background-color: {{tabBackgroundColor}}; color: {{activeTab === index ? tabActiveTextColor : tabInactiveTextColor}};" bindtap="handleTabClick" data-index="{{index}}">
|
||||
<view class="weui-tabs-bar__title {{tabClass}} {{activeTab === index ? activeClass : ''}}" style="border-bottom-color: {{activeTab === index ? tabUnderlineColor : 'transparent'}}">
|
||||
<text class="">{{item.title}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<swiper class="{{swiperClass}}" current="{{activeTab}}" duration="{{duration}}" bindchange="handleSwiperChange">
|
||||
<swiper-item wx:for="{{tabs}}" wx:key="title">
|
||||
<slot name="tab-content-{{index}}"></slot>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
@@ -0,0 +1,30 @@
|
||||
/* @import '../../../common/lib/weui.wxss'; */
|
||||
|
||||
.weui-tabs {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.weui-tabs-bar__wrp {
|
||||
width: 100%;
|
||||
background: var(--weui-BG-2);
|
||||
margin-top: 0;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.weui-tabs-bar__content {
|
||||
width: 100%;
|
||||
white-space: nowrap
|
||||
}
|
||||
|
||||
.weui-tabs-bar__item {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.weui-tabs-bar__title {
|
||||
display: inline-block;
|
||||
border-bottom-width: 2px;
|
||||
border-bottom-style: solid;
|
||||
border-bottom-color: transparent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user