This commit is contained in:
2024-07-02 11:26:14 +08:00
parent a174c3e4d5
commit 41d03fb4ce
15 changed files with 1603 additions and 1334 deletions

View File

@@ -11,9 +11,24 @@
}"
>
<slot name="tabs" :showTabs="showTabs"></slot>
<u-tabs
<view
:style="{ display: showTabs ? 'block' : 'none', ...tabStyle }"
class="wrapper_tab"
>
<view
:class="`${
currentTab == i ? 'hot wrapper_tab_item' : 'wrapper_tab_item'
}`"
v-for="(v, i) in tabList"
@click="clickItem(v, i)"
>
{{ v.title }}
<slot name="labelSlot" :data="v"></slot>
</view>
</view>
<!-- <u-tabs
keyName="title"
:current="currentTab"
:list="tabList"
@@ -34,10 +49,10 @@
}"
>
<template slot="labelSlot" slot-scope="slotProps">
<!-- <text>{{ slotProps.data.title }}</text> -->
<slot name="labelSlot" :data="slotProps.data"></slot>
</template>
</u-tabs>
</u-tabs> -->
</view>
<slot name="otherContent" :showTabs="showTabs"></slot>
@@ -59,10 +74,11 @@
<view class="content section_content_progress">
<view class="content_list">
<slot
name="contentList"
:name="slotName ? slotName + '_' + v.slotName : 'contentList'"
:showTabs="showTabs"
:dataList="v[dataListKey]"
:data="v"
:index="i"
></slot>
</view>
</view>
@@ -83,6 +99,8 @@ export default {
"titleStyle",
"baseHeight",
"allTabList",
"slotName",
"defaultShowTabs",
],
data() {
return {
@@ -111,8 +129,8 @@ export default {
show: false,
options: {},
showTabs: false, // 默认吸顶的tab不显示
currentTab: -1, // 由于初始化的uview的代码有bug所以默认是-1在第一次显示的时候设置0自动复位防止错误
showTabs: this.defaultShowTabs ? this.defaultShowTabs : false, // 默认吸顶的tab不显示
currentTab: 0, // 由于初始化的uview的代码有bug所以默认是-1在第一次显示的时候设置0自动复位防止错误
distanceArr: [], // 每一个ID对应的scrollTop值
@@ -132,7 +150,13 @@ export default {
async onLoad(options) {
this.options = options;
await this.handleselectCate({ ...this.cateList[0], index: 0 }, 0);
await this.handleselectCate(
{
...this.cateList[0],
index: 0,
},
0
);
},
async onShow() {},
methods: {
@@ -140,10 +164,9 @@ export default {
// console.log("event at line 213:", event);
// const _this = this;
if (this.isTabChange) {
return;
return false;
}
const scrollTop = event.scrollTop;
console.log("scrollTop at line 145:", scrollTop);
const skewY =
Number(this.baseHeight) + 45 + +Number(this.statusBarHeight); // 偏移量由于吸顶的tab、头部的显示信息也有高度素以做了偏移量
// // console.log('skewY at line 130:',this.baseHeight,this.statusBarHeight, skewY)
@@ -156,17 +179,19 @@ export default {
// console.log('this.showTabs at line 141:', this.showTabs)
this.$nextTick(() => {
// const length = this.distanceArr.length;
// const index = this.distanceArr.findIndex(
// (el) => el.top - skewY - scrollTop - 40 > 0
// ); console.log('index at line 15911111111111111:', index)
// // 当index == -1 的时候实际当前滚动的距离超出了最大值也就是在最后一个tab显示的内容
// // 当index > 0 的时候说明能在当前的scrollTop值找到index的前一位
// this.currentTab = index > 0 ? index - 1 : length - 1;
// this.currentTab = null;
const length = this.distanceArr.length;
const index = this.distanceArr.findIndex(
(el) => el.top - skewY - scrollTop - 40 > 0
);
// console.log('index at line 15911111111111111:', index)
// 当index == -1 的时候实际当前滚动的距离超出了最大值也就是在最后一个tab显示的内容
// 当index > 0 的时候说明能在当前的scrollTop值找到即index的前一位
this.currentTab = index > 0 ? index - 1 : length - 1;
});
this.$forceUpdate();
} else {
this.showTabs = false;
this.showTabs = this.defaultShowTabs ? this.defaultShowTabs : false;
this.currentTab = 0;
}
},
@@ -271,7 +296,7 @@ export default {
this.isTabChange = true;
this.$nextTick(() => {
this.currentTab = item.index;
this.currentTab = index;
var data = this.distanceArr.find((e) => e.title == item.title);
console.log(
"111111111111111111111111111111111111111at line 258:",
@@ -280,12 +305,12 @@ export default {
uni.pageScrollTo({
// duration: 100, //过渡时间
scrollTop: data.top - skewY, //到达距离顶部的top值
duration: 100,
duration: 300,
complete: function () {
const timer = setTimeout(() => {
that.isTabChange = false; // 关闭
clearTimeout(timer);
}, 500); // 解决ios和安卓、鸿蒙系统兼容性问题
}, 1000); // 解决ios和安卓、鸿蒙系统兼容性问题
},
//scrollTop:data.top - res.top,//如果置顶
});
@@ -333,22 +358,27 @@ export default {
position: absolute;
min-height: 60vh;
.header {
height: 100rpx;
background: orange;
.bg {
width: 100vw;
height: 200rpx;
}
}
.tabs {
position: fixed !important;
z-index: 970;
// top: 0;
background-color: #fff;
width: 100vw;
.tabsStyle {
box-shadow: 0 2rpx 6rpx 0 rgba(153, 153, 153, 0.2);
::v-deep {
.u-tabs {
box-shadow: 0px 4px 6px 0 rgba(153, 153, 153, 0.2);
@@ -356,16 +386,19 @@ export default {
}
}
}
.section {
width: 100%;
padding: 0 0rpx;
box-sizing: border-box;
.section_top {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
.title {
font-size: 40rpx;
font-family: PingFangSC-Semibold, PingFang SC;
@@ -373,6 +406,7 @@ export default {
color: #333333;
margin-left: 30rpx;
position: relative;
&::before {
position: absolute;
content: "";
@@ -660,5 +694,21 @@ export default {
.hot {
color: #00bb84 !important;
font-weight: bold;
}
.wrapper_tab {
width: 100%;
display: flex;
align-items: center;
justify-content: space-around;
font-size: 34rpx;
}
.wrapper_tab_item {
width: auto;
display: inline-block;
line-height: 60rpx;
padding: 10rpx 20rpx;
}
</style>