Skip to content

Commit 2fbc366

Browse files
committed
v2.7.13-update z-tabs & z-paging兼容模式
1 parent 2207bbe commit 2fbc366

File tree

11 files changed

+188
-94
lines changed

11 files changed

+188
-94
lines changed

demo/z-paging-demo/uni_modules/z-paging/components/z-paging/z-paging.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ by ZXLee
9898
<view class="zp-list-container" :style="[innerListStyle]">
9999
<template v-if="finalUseVirtualList">
100100
<view class="zp-list-cell" :style="[innerCellStyle]" :id="`zp-id-${item[virtualCellIndexKey]}`" v-for="(item,index) in virtualList" :key="item['zp_unique_index']" @click="_innerCellClick(item,virtualTopRangeIndex+index)">
101-
<!-- <view v-if="useCompatibilityMode">使用兼容模式请在组件源码z-paging.vue第101行中注释这一行,并打开下面一行注释</view> -->
102-
<zp-public-virtual-cell v-if="useCompatibilityMode" :extraData="extraData" :item="item" :index="virtualTopRangeIndex+index" />
101+
<view v-if="useCompatibilityMode">使用兼容模式请在组件源码z-paging.vue第101行中注释这一行,并打开下面一行注释</view>
102+
<!-- <zp-public-virtual-cell v-if="useCompatibilityMode" :extraData="extraData" :item="item" :index="virtualTopRangeIndex+index" /> -->
103103
<slot v-else name="cell" :item="item" :index="virtualTopRangeIndex+index"/>
104104
</view>
105105
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
## 0.3.0(2024-10-21)
2+
支持鸿蒙Next
3+
## 0.2.7(2024-07-18)
4+
1.`新增` 支持切换rpx&px
5+
2.`修复` 宽度小于屏幕时底部tabs位置不正确的问题
6+
3.`修复` 偶现的Cannot read property 'left' of undefind的问题
7+
18
## 0.2.5(2023-01-09)
29
修复可能出现的可能出现的与swiper联动时报错node不存在的bug

demo/z-paging-demo/uni_modules/z-tabs/components/z-tabs/z-tabs.vue

Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<!-- z-tabs v0.2.5 by-ZXLee -->
1+
<!-- z-tabs v0.3.0 by-ZXLee -->
22
<!-- github地址:https://github.com/SmileZXLee/uni-z-tabs -->
33
<!-- dcloud地址:https://ext.dcloud.net.cn/plugin?name=z-tabs -->
4-
<!-- 反馈QQ群:790460711 -->
4+
<!-- 反馈QQ群:371624008 -->
55

66
<template name="z-tabs">
7-
<view class="z-tabs-conatiner" :style="[{background:bgColor}, tabsStyle]">
7+
<view class="z-tabs-conatiner" :style="[{background:bgColor}, {height: unit==='rpx' ? '80rpx' : '40px'}, tabsStyle]">
88
<view class="z-tabs-left">
99
<slot name="left" />
1010
</view>
@@ -14,11 +14,11 @@
1414
<view class="z-tabs-list" :style="[tabsListStyle, {marginTop: -finalBottomSpace+'px'}]">
1515
<view :ref="`z-tabs-item-${index}`" :id="`z-tabs-item-${index}`" class="z-tabs-item" :style="[tabStyle]" v-for="(item,index) in list" :key="index" @click="tabsClick(index,item)">
1616
<view class="z-tabs-item-title-container">
17-
<text :class="{'z-tabs-item-title':true,'z-tabs-item-title-disabled':item.disabled}"
17+
<text :class="{'z-tabs-item-title-rpx':unit==='rpx','z-tabs-item-title-px':unit==='px','z-tabs-item-title-disabled':item.disabled}"
1818
:style="[{color:item.disabled?disabledColor:(currentIndex===index?activeColor:inactiveColor)},item.disabled?disabledStyle:(currentIndex===index?activeStyle:inactiveStyle)]">
1919
{{item[nameKey]||item}}
2020
</text>
21-
<text v-if="item.badge&&_formatCount(item.badge.count).length" class="z-tabs-item-badge" :style="[badgeStyle]">{{_formatCount(item.badge.count)}}</text>
21+
<text v-if="item.badge&&_formatCount(item.badge.count).length" class="z-tabs-item-badge" :class="{'z-tabs-item-badge-rpx':unit==='rpx','z-tabs-item-badge-px':unit==='px'}" :style="[badgeStyle]">{{_formatCount(item.badge.count)}}</text>
2222
</view>
2323
</view>
2424
</view>
@@ -47,14 +47,12 @@
4747
const weexDom = weex.requireModule('dom');
4848
const weexAnimation = weex.requireModule('animation');
4949
// #endif
50+
import zTabsConfig from './config/index'
5051
5152
// #ifdef APP-HARMONY
5253
let screenWidth = 0;
5354
// #endif
54-
55-
import zTabsConfig from './config/index'
56-
57-
//获取默认配置信息
55+
// 获取默认配置信息
5856
function _gc(key, defaultValue) {
5957
let config = null;
6058
if (zTabsConfig && Object.keys(zTabsConfig).length) {
@@ -65,10 +63,22 @@
6563
const value = config[_toKebab(key)];
6664
return value === undefined ? defaultValue : value;
6765
}
68-
//驼峰转短横线
66+
// 驼峰转短横线
6967
function _toKebab(value) {
7068
return value.replace(/([A-Z])/g, "-$1").toLowerCase();
7169
}
70+
// rpx => px,兼容鸿蒙
71+
function rpx2px(rpx) {
72+
// #ifdef APP-HARMONY
73+
if (!screenWidth) {
74+
screenWidth = uni.getSystemInfoSync().screenWidth;
75+
}
76+
return (screenWidth * Number.parseFloat(rpx)) / 750;
77+
// #endif
78+
// #ifndef APP-HARMONY
79+
return uni.upx2px(rpx);
80+
// #endif
81+
}
7282
7383
/**
7484
* z-tabs 标签
@@ -96,6 +106,7 @@
96106
* @property {String} bg-color z-tabs背景色
97107
* @property {Object} tabs-style z-tabs样式
98108
* @property {Boolean} init-trigger-change 初始化时是否自动触发change事件
109+
* @property {String} unit z-tabs中布局的单位,默认为rpx
99110
* @event {Function(index,value)} change tabs改变时触发,index:当前切换到的index;value:当前切换到的value
100111
* @example <z-tabs :list="list"></z-tabs>
101112
*/
@@ -113,9 +124,9 @@
113124
barCalcedWidth: 0,
114125
pxBarWidth: 0,
115126
scrollLeft: 0,
116-
tabsSuperWidth: this.rpx2px(750),
117-
tabsWidth: this.rpx2px(750),
118-
tabsHeight: this.rpx2px(80),
127+
tabsSuperWidth: rpx2px(750),
128+
tabsWidth: rpx2px(750),
129+
tabsHeight: rpx2px(80),
119130
tabsLeft: 0,
120131
tabsContainerWidth: 0,
121132
itemNodeInfos: [],
@@ -165,6 +176,11 @@
165176
type: [Number, String],
166177
default: _gc('barHeight',8)
167178
},
179+
//swiper的宽度,单位rpx,支持传100、"100px"或"100rpx",默认为"750rpx"
180+
swiperWidth: {
181+
type: [Number, String],
182+
default: _gc('swiperWidth',750)
183+
},
168184
//滑块样式,其中的width和height将被barWidth和barHeight覆盖
169185
barStyle: {
170186
type: Object,
@@ -249,6 +265,11 @@
249265
initTriggerChange: {
250266
type: Boolean,
251267
default: _gc('initTriggerChange',false)
268+
},
269+
//z-tabs中布局的单位,默认为rpx
270+
unit: {
271+
type: String,
272+
default: _gc('unit', 'rpx')
252273
}
253274
},
254275
mounted() {
@@ -344,35 +365,25 @@
344365
return this._convertTextToPx(this.tabWidth);
345366
},
346367
finalBarWidth(){
347-
return this._convertTextToPx(this.barWidth);
368+
return this._convertTextToPx(this._addUnit(this.barWidth, this.unit));
348369
},
349370
finalBarHeight(){
350-
return this._convertTextToPx(this.barHeight);
371+
return this._convertTextToPx(this._addUnit(this.barHeight, this.unit));
372+
},
373+
finalSwiperWidth(){
374+
return this._convertTextToPx(this.swiperWidth);
351375
},
352376
finalBottomSpace(){
353-
return this._convertTextToPx(this.bottomSpace);
377+
return this._convertTextToPx(this._addUnit(this.bottomSpace, this.unit));
354378
}
355379
},
356380
methods: {
357-
// rpx => px,兼容鸿蒙
358-
rpx2px(rpx) {
359-
// #ifdef APP-HARMONY
360-
if (!screenWidth) {
361-
screenWidth = uni.getSystemInfoSync().screenWidth;
362-
}
363-
return (screenWidth * Number.parseFloat(rpx)) / 750;
364-
// #endif
365-
// #ifndef APP-HARMONY
366-
return uni.upx2px(rpx);
367-
// #endif
368-
},
369-
370381
//根据swiper的@transition实时更新底部dot位置
371382
setDx(dx) {
372383
if (!this.shouldSetDx) return;
373384
const isLineMode = this.barAnimateMode === 'line';
374385
const isWormMode = this.barAnimateMode === 'worm';
375-
let dxRate = dx / this.tabsSuperWidth;
386+
let dxRate = dx / this.finalSwiperWidth;
376387
this.currentSwiperIndex = this.currentIndex + parseInt(dxRate);
377388
const isRight = dxRate > 0;
378389
const barWidth = this.pxBarWidth;
@@ -389,7 +400,7 @@
389400
nextIndex = Math.min(nextIndex, this.itemNodeInfos.length - 1);
390401
const currentNodeInfo = this.itemNodeInfos[currentIndex];
391402
const nextNodeInfo = this.itemNodeInfos[nextIndex];
392-
const nextBottomX = nextNodeInfo ? this._getBottomDotX(nextNodeInfo, barWidth) : 0;
403+
const nextBottomX = this._getBottomDotX(nextNodeInfo, barWidth);
393404
if (isLineMode){
394405
this.bottomDotX = this.bottomDotXForIndex + (nextBottomX - this.bottomDotXForIndex) * Math.abs(dxRate);
395406
} else if (isWormMode) {
@@ -505,15 +516,17 @@
505516
if (nodeRes) {
506517
node = nodeRes[0];
507518
offset = this.currentScrollLeft;
508-
this.tabsHeight = Math.max(node.height + this.rpx2px(28), this.tabsHeight);
519+
this.tabsHeight = Math.max(node.height + rpx2px(28), this.tabsHeight);
509520
tabsContainerWidth = 0;
510521
for(let i = 0;i < this.itemNodeInfos.length;i++){
511522
let oldNode = this.itemNodeInfos[i];
512523
tabsContainerWidth += i === index ? node.width : oldNode.width;
513524
}
514525
}
515526
}
516-
this.bottomDotX = this._getBottomDotX(node, this.finalBarWidth, offset);
527+
if (node) {
528+
this.bottomDotX = this._getBottomDotX(node, this.finalBarWidth, offset);
529+
}
517530
this.bottomDotXForIndex = this.bottomDotX;
518531
if (this.tabsWidth) {
519532
setTimeout(()=>{
@@ -610,7 +623,7 @@
610623
_convertTextToPx(text) {
611624
const dataType = Object.prototype.toString.call(text);
612625
if (dataType === '[object Number]') {
613-
return this.rpx2px(text);
626+
return rpx2px(text);
614627
}
615628
let isRpx = false;
616629
if (text.indexOf('rpx') !== -1 || text.indexOf('upx') !== -1) {
@@ -619,13 +632,25 @@
619632
} else if (text.indexOf('px') !== -1) {
620633
text = text.replace('px', '');
621634
} else {
622-
text = this.rpx2px(text);
635+
text = rpx2px(text);
623636
}
624637
if (!isNaN(text)) {
625-
if (isRpx) return Number(this.rpx2px(text));
638+
if (isRpx) return Number(rpx2px(text));
626639
return Number(text);
627640
}
628641
return 0;
642+
},
643+
// 添加单位
644+
_addUnit(value, unit) {
645+
if (Object.prototype.toString.call(value) === '[object String]') {
646+
let tempValue = value;
647+
tempValue = tempValue.replace('rpx', '').replace('upx', '').replace('px', '');
648+
if (value.indexOf('rpx') === -1 && value.indexOf('upx') === -1 && value.indexOf('px') !== -1) {
649+
tempValue = parseFloat(tempValue) * 2;
650+
}
651+
value = tempValue;
652+
}
653+
return unit === 'rpx' ? value + 'rpx' : (value / 2) + 'px';
629654
}
630655
}
631656
@@ -643,7 +668,6 @@
643668
width: 750rpx;
644669
/* #endif */
645670
flex-direction: row;
646-
height: 80rpx;
647671
}
648672
649673
.z-tabs-scroll-view-conatiner{
@@ -713,25 +737,38 @@
713737
align-items: center;
714738
}
715739
716-
.z-tabs-item-title{
740+
.z-tabs-item-title-rpx{
717741
font-size: 30rpx;
718742
}
719743
744+
.z-tabs-item-title-px{
745+
font-size: 15px;
746+
}
747+
720748
.z-tabs-item-title-disabled{
721749
/* #ifndef APP-NVUE */
722750
cursor: not-allowed;
723751
/* #endif */
724752
}
725753
726754
.z-tabs-item-badge{
727-
margin-left: 8rpx;
728755
background-color: #ec5b56;
729756
color: white;
730-
font-size: 22rpx;
731757
border-radius: 100px;
758+
}
759+
760+
.z-tabs-item-badge-rpx{
761+
margin-left: 8rpx;
762+
font-size: 22rpx;
732763
padding: 0rpx 10rpx;
733764
}
734765
766+
.z-tabs-item-badge-px{
767+
margin-left: 4px;
768+
font-size: 11px;
769+
padding: 0px 5px;
770+
}
771+
735772
.z-tabs-bottom{
736773
position: absolute;
737774
bottom: 0;

demo/z-paging-demo/uni_modules/z-tabs/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "z-tabs",
33
"name": "z-tabs",
44
"displayName": "【z-tabs】一个简单轻量的tabs组件",
5-
"version": "0.2.5",
5+
"version": "0.3.0",
66
"description": "全平台兼容,支持nvue、vue3",
77
"keywords": [
88
"tabs"
@@ -37,7 +37,8 @@
3737
"platforms": {
3838
"cloud": {
3939
"tcb": "y",
40-
"aliyun": "y"
40+
"aliyun": "y",
41+
"alipay": "n"
4142
},
4243
"client": {
4344
"App": {

demo/z-paging-demo/uni_modules/z-tabs/readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# z-tabs
22

3-
[![version](https://img.shields.io/badge/version-0.2.5-blue)](https://github.com/SmileZXLee/uni-z-tabs)
3+
[![version](https://img.shields.io/badge/version-0.3.0-blue)](https://github.com/SmileZXLee/uni-z-tabs)
44
[![license](https://img.shields.io/github/license/SmileZXLee/uni-z-tabs)](https://en.wikipedia.org/wiki/MIT_License)
55

66
***
77

8-
### 反馈qq群(点击加群):[790460711](https://jq.qq.com/?_wv=1027&k=vU2fKZZH)
8+
### 反馈qq群(点击加群):[371624008](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=avPmibADf2TNi4LxkIwjCE5vbfXpa-r1&authKey=dQ%2FVDAR87ONxI4b32Py%2BvmXbhnopjHN7%2FJPtdsqJdsCPFZB6zDQ17L06Uh0kITUZ&noverify=0&group_code=371624008)
99

1010
***
1111

@@ -102,6 +102,8 @@ npm update @zxlee/z-tabs
102102
| bg-color | z-tabs背景色 | String | white | - |
103103
| tabs-style | z-tabs样式 | Object | {} | - |
104104
| init-trigger-change | 初始化时是否自动触发change事件 | Boolean | true | false |
105+
| unit | z-tabs中布局的单位,默认为rpx | String | rpx | px |
106+
105107

106108

107109
### events

demo/z-paging-vue3-demo/uni_modules/z-paging/components/z-paging/z-paging.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ by ZXLee
9898
<view class="zp-list-container" :style="[innerListStyle]">
9999
<template v-if="finalUseVirtualList">
100100
<view class="zp-list-cell" :style="[innerCellStyle]" :id="`zp-id-${item[virtualCellIndexKey]}`" v-for="(item,index) in virtualList" :key="item['zp_unique_index']" @click="_innerCellClick(item,virtualTopRangeIndex+index)">
101-
<!-- <view v-if="useCompatibilityMode">使用兼容模式请在组件源码z-paging.vue第101行中注释这一行,并打开下面一行注释</view> -->
102-
<zp-public-virtual-cell v-if="useCompatibilityMode" :extraData="extraData" :item="item" :index="virtualTopRangeIndex+index" />
101+
<view v-if="useCompatibilityMode">使用兼容模式请在组件源码z-paging.vue第101行中注释这一行,并打开下面一行注释</view>
102+
<!-- <zp-public-virtual-cell v-if="useCompatibilityMode" :extraData="extraData" :item="item" :index="virtualTopRangeIndex+index" /> -->
103103
<slot v-else name="cell" :item="item" :index="virtualTopRangeIndex+index"/>
104104
</view>
105105
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
## 0.3.0(2024-10-21)
2+
支持鸿蒙Next
3+
## 0.2.7(2024-07-18)
4+
1.`新增` 支持切换rpx&px
5+
2.`修复` 宽度小于屏幕时底部tabs位置不正确的问题
6+
3.`修复` 偶现的Cannot read property 'left' of undefind的问题
7+
18
## 0.2.5(2023-01-09)
29
修复可能出现的可能出现的与swiper联动时报错node不存在的bug

0 commit comments

Comments
 (0)