Commit a1c2eb1a by luyt

feat:滚动添加

1 parent 67c85b30
......@@ -425,6 +425,7 @@ Page({
this.setData({
hasUserInfo: true,
});
let _this = this;
// 推荐使用 wx.getUserProfile 获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
......@@ -444,10 +445,23 @@ Page({
};
// console.log('obj',obj)
wx.$storage.set("wx_user_info", obj);
// this.onLoad(null);
_this.onLoad(null);
},
});
},
onPageScroll: (function () {
let timer = null;
return function (e) {
// console.log("在滚动");
// 监听页面的滚动开始和结束
clearTimeout(timer);
timer = setTimeout(() => {
// console.log("滚动结束");
wx.$eventbus.emit('evt_page_scroll',{scrollTop:e.scrollTop})
}, 500);
};
})(),
/**
* 生命周期函数--监听页面初次渲染完成
......
......@@ -115,6 +115,7 @@
width: 100%;
height: 120rpx;
background: #ffffff;
z-index: 1;
// border-radius: 8px 8px 0 0;
.top {
display: flex;
......@@ -177,6 +178,6 @@
left: 0;
right: 0;
bottom: 0;
z-index: 2;
z-index: 3;
background-color: transparent;
}
......@@ -37,7 +37,7 @@
</view> -->
<!-- 用于图片加载事件 -->
<image class="img" src="{{IMG_URL}}index/longpic{{actNum+1}}.png" bindload="onloadFn" />
<view class="btns-wrap">
<view class="btns-wrap" wx:if="{{isShow}}">
<view class="top">
<view class="btn" wx:for="{{btnList}}" wx:key="name" bindtap="handleClick" data-index="{{index}}">
<block wx:if="{{index == 1}}">
......
......@@ -49,12 +49,48 @@ Component({
IMGURL: `${IMG_URL}index/`,
videoBaseUrl,
getMoreBtn:false,
showVideo:true //显示视频列表
showVideo:true, //显示视频列表
imgTopArr:[]
},
lifetimes: {
ready: function () {
if(!this.data.outshowVideo){
//获取当前路径
let currentUrl = this.getCurrentPageUrl()
// console.log('currentUrl: ', currentUrl);
if(currentUrl == '/pages/tab/index/index'){
this.setData({
currentUrl:false
})
}
//监听页面滚动的距离
wx.$eventbus.on('evt_page_scroll',async (e)=>{
console.log(e)
// let heightTop = this.data.stickyTop// 90 场景高度,8 场景margin-bottom
// let prodArr = await this.getHeight('.prod-wrap')
// // console.log('prodArr: ', prodArr);
// heightTop += prodArr[0].height
// let imgArr = await this.getHeight('.img-item')
// // console.log('imgArr: ', imgArr);
// let imgHeightArr = []
// imgArr.reduce((pre,cur,index)=>{
// imgHeightArr.push(pre+cur.height)
// return pre+cur.height
// },heightTop)
let imgTopArr = this.data.imgTopArr
if(imgTopArr.length == 0)return
wx.nextTick(()=>{
let idx = imgTopArr.findIndex(item => item > e.scrollTop)
if(idx>-1){
this.setData({
curTabIdx: idx
})
}
})
})
if(!this.data.outshowVideo){
this.setData({
showVideo:false
})
......@@ -68,6 +104,7 @@ Component({
this.getMoreFn();
}
},
},
observers: {
actNum: function (newval, oldval) {
......@@ -127,6 +164,12 @@ Component({
* 组件的方法列表
*/
methods: {
getCurrentPageUrl() {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const url = `/${currentPage.route}`
return url
},
async init() {
try {
const { data, code, message } = await USERAPI.wxCodeLogin();
......@@ -175,43 +218,93 @@ Component({
saleTextChange(e) {},
changeTab(e) {
let idx = e.detail;
this.setData({
intoViewId: `to-${idx}`,
});
let {imgTopArr,stickyTop} = this.data
console.log('idx: ', imgTopArr[idx]);
// this.setData({
// intoViewId: `to-${idx}`,
// });
// wx.$eventbus.emit('evt_page_index',idx)
wx.pageScrollTo({ scrollTop: imgTopArr[idx]-stickyTop+88+34})
},
// async changeTab(e){
// let idx = e.detail
// this.setData({
// intoViewId: `to-${idx}`
// })
// let heightTop = this.data.headerHeight + 90 - 16 - 46 // 90 场景高度,16 可能是误差 , 46 tab高度
// let prodArr = await this.getHeight('.prod-wrap')
// heightTop += prodArr[0].height
// let imgArr = await this.getHeight('.img-item')
// for(let i=0;i<idx;i++){
// heightTop += imgArr[i].height
// }
// wx.pageScrollTo({
// scrollTop: heightTop,
// duration: 0
// })
// },
getHeight(cla){
return new Promise((resolve,reject)=>{
let query = wx.createSelectorQuery().in(this)
query.selectAll(cla).boundingClientRect((rect) => {
resolve(rect)
}).exec()
})
},
changeNav(event) {
this.setData({
activeNavIdx: event.target.dataset.index,
});
},
scrolltoupper(event) {
console.log(event.detail.scrollHeight,event.detail.scrollTop)
const idx = this.data.heightArr.findIndex(
(item) => item > event.detail.scrollHeight
);
console.log('idx',idx)
this.setData({
curTabIdx: idx,
});
// scrolltoupper(event) {
// console.log(event.detail.scrollHeight,event.detail.scrollTop)
// const idx = this.data.heightArr.findIndex(
// (item) => item > event.detail.scrollHeight
// );
// console.log('idx',idx)
// this.setData({
// curTabIdx: idx,
// });
// console.log(this.data.curTabIdx1)
},
// // console.log(this.data.curTabIdx1)
// },
getImgHeight() {
let query = wx.createSelectorQuery().in(this);
let heightArr = [];
let imgTopArr = []
let s = 0;
let top
query
.selectAll(".img-item")
.boundingClientRect((react) => {
react.forEach((item) => {
s += item.height;
heightArr.push(s);
react.forEach((item,index) => {
// if(index == 0){
// console.log('item top: ', item);
// top = item.top
// }
// s = s +item.height;
s = item.top
// heightArr.push(s);
imgTopArr.push(s)
});
this.data.heightArr = heightArr;
// console.log(heightArr[heightArr.length-1])
this.data.allHeight = heightArr[heightArr.length - 1];
console.log('没有处理过的heightArr',heightArr)
// heightArr = heightArr.map((item)=>{
// item += top
// return item
// })
// this.data.heightArr = heightArr;
// // console.log(heightArr[heightArr.length-1])
// this.data.allHeight = heightArr[heightArr.length - 1];
})
.exec();
this.setData({
imgTopArr
// heightArr,
// allHeight:heightArr[heightArr.length - 1]
})
// let query = wx.createSelectorQuery().in(this);
// let heightArr = [];
// let s = 0;
......
......@@ -348,9 +348,12 @@
.video-list {
display: flex;
flex-wrap: wrap;
padding: 0 32rpx;
padding: 0rpx 32rpx;
font-size: 0;
}
.check-prod .video-list{
padding-bottom: 140rpx;
}
.video-item {
position: relative;
width: calc(50% - 12rpx);
......
<!-- pages/tab/discovery/components/product/product.wxml -->
<view class="prod-wrap">
<view class="big-title">特色产品</view>
<view class="prod-wrap" >
<view class="big-title">特色产品 {{origin}}</view>
<scroll-view class="nav-wrap" scroll-x="{{true}}" wx:if="{{!isShare && origin =='home'}}">
<block wx:for="{{navList}}" wx:key="index">
<text class='nav {{activeNavIdx==index ? "active-nav": ""}}' bindtap="changeNav" data-index="{{index}}">{{item}}</text>
......@@ -28,7 +28,7 @@
</view>
</view>
</view>
<view class="project-wrap">
<view class="project-wrap {{currentUrl == ''? '':'check-prod'}}">
<!-- -->
<view class="stickyTab" style="top:{{isShare ? stickyTop+88 : stickyTop}}rpx">
<tab
......
......@@ -635,7 +635,18 @@ Page({
// console.log('this.data.tabBarStyle',this.data.tabBarStyle,this.data.headerHeight)
// })
},
onPageScroll: (function () {
let timer = null;
return function (e) {
// console.log("在滚动");
// 监听页面的滚动开始和结束
clearTimeout(timer);
timer = setTimeout(() => {
// console.log("滚动结束");
wx.$eventbus.emit('evt_page_scroll',{scrollTop:e.scrollTop})
}, 500);
};
})(),
/**
* 生命周期函数--监听页面隐藏
*/
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!