Skip to content

Commit 6a276a4

Browse files
committed
新增:tabs标签卡增加badge徽标数设置
1 parent 0c771f2 commit 6a276a4

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

uview-ui/components/u-tabs-swiper/u-tabs-swiper.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<view class="u-tabs-scroll-box" :class="{'u-tabs-scorll-flex': !isScroll}">
88
<view class="u-tabs-item" :style="[tabItemStyle(index)]"
99
v-for="(item, index) in getTabs" :key="index" :class="[preId + index]" @tap="emit(index)">
10+
<u-badge :count="item[count] || item['count'] || 0" :offset="offset" size="mini"></u-badge>
1011
{{ item[name] || item['name']}}
1112
</view>
1213
<view v-if="showBar" class="u-scroll-bar" :style="[tabBarStyle]"></view>
@@ -18,9 +19,7 @@
1819
<script>
1920
import colorGradient from '../../libs/function/colorGradient';
2021
let color = colorGradient;
21-
const {
22-
windowWidth
23-
} = uni.getSystemInfoSync();
22+
const { windowWidth } = uni.getSystemInfoSync();
2423
const preId = 'UEl_';
2524
2625
/**
@@ -43,6 +42,8 @@
4342
* @property {String Number} gutter 单个tab标签的左右内边距之和,单位rpx(默认40)
4443
* @property {String} bg-color tabs导航栏的背景颜色(默认#ffffff)
4544
* @property {String} name 组件内部读取的list参数中的属性名,见官网说明(默认name)
45+
* @property {String} count 组件内部读取的list参数中的属性名(badge徽标数),同name属性的使用,见官网说明(默认count)
46+
* @property {Array} offset 设置badge徽标数的位置偏移,格式为 [x, y],也即设置的为top和right的值,单位rpx(默认[5, 20])
4647
* @property {Boolean} bold 激活选项的字体是否加粗(默认true)
4748
* @event {Function} change 点击标签时触发
4849
* @example <u-tabs-swiper ref="tabs" :list="list" :is-scroll="false"></u-tabs-swiper>
@@ -127,11 +128,23 @@
127128
type: String,
128129
default: 'window'
129130
},
130-
// 读取传入的数组对象的属性
131+
// 读取传入的数组对象的属性(tab名称)
131132
name: {
132133
type: String,
133134
default: 'name'
134135
},
136+
// 读取传入的数组对象的属性(徽标数)
137+
count: {
138+
type: String,
139+
default: 'count'
140+
},
141+
// 徽标数位置偏移
142+
offset: {
143+
type: Array,
144+
default: () => {
145+
return [5, 20]
146+
}
147+
},
135148
// 活动tab字体是否加粗
136149
bold: {
137150
type: Boolean,

uview-ui/components/u-tabs/u-tabs.vue

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<view class="u-scroll-box" :class="{'u-tabs-scorll-flex': !isScroll}">
99
<view class="u-tab-item u-line-1" :id="'u-tab-item-' + index" v-for="(item, index) in list" :key="index" @tap="clickTab(index)"
1010
:style="[tabItemStyle(index)]">
11+
<u-badge :count="item[count] || item['count'] || 0" :offset="offset" size="mini"></u-badge>
1112
{{ item[name] || item['name']}}
1213
</view>
1314
<view v-if="showBar" class="u-tab-bar" :style="[tabBarStyle]"></view>
@@ -20,7 +21,7 @@
2021
<script>
2122
/**
2223
* tabs 标签
23-
* @description 该组件,是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
24+
* @description 该组件,是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
2425
* @tutorial https://www.uviewui.com/components/tabs.html
2526
* @property {Boolean} is-scroll tabs是否可以左右拖动(默认true)
2627
* @property {Array} list 标签数组,元素为对象,如[{name: '推荐'}]
@@ -38,7 +39,9 @@
3839
* @property {String Number} item-width 标签的宽度(默认auto)
3940
* @property {String Number} gutter 单个tab标签的左右内边距之和,单位rpx(默认40)
4041
* @property {String} bg-color tabs导航栏的背景颜色(默认#ffffff)
41-
* @property {String} name 组件内部读取的list参数中的属性名,见官网说明(默认name)
42+
* @property {String} name 组件内部读取的list参数中的属性名(tab名称),见官网说明(默认name)
43+
* @property {String} count 组件内部读取的list参数中的属性名(badge徽标数),同name属性的使用,见官网说明(默认count)
44+
* @property {Array} offset 设置badge徽标数的位置偏移,格式为 [x, y],也即设置的为top和right的值,单位rpx(默认[5, 20])
4245
* @property {Boolean} bold 激活选项的字体是否加粗(默认true)
4346
* @event {Function} change 点击标签时触发
4447
* @example <u-tabs ref="tabs" :list="list" :is-scroll="false"></u-tabs>
@@ -108,11 +111,23 @@
108111
type: String,
109112
default: '#ffffff'
110113
},
111-
// 读取传入的数组对象的属性
114+
// 读取传入的数组对象的属性(tab名称)
112115
name: {
113116
type: String,
114117
default: 'name'
115118
},
119+
// 读取传入的数组对象的属性(徽标数)
120+
count: {
121+
type: String,
122+
default: 'count'
123+
},
124+
// 徽标数位置偏移
125+
offset: {
126+
type: Array,
127+
default: () => {
128+
return [5, 20]
129+
}
130+
},
116131
// 活动tab字体是否加粗
117132
bold: {
118133
type: Boolean,
@@ -290,7 +305,7 @@
290305

291306
<style lang="scss" scoped>
292307
@import "../../libs/css/style.components.scss";
293-
308+
294309
view,
295310
scroll-view {
296311
box-sizing: border-box;

0 commit comments

Comments
 (0)