mini/miniprogram_npm/@beefast-wxmp/list-view/index.js
2025-04-15 20:23:27 +08:00

85 lines
1.7 KiB
JavaScript

// components/listView/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
refresherTriggered:{
type:Boolean,
value:false
},
height:{
type:Number,
value:0
},
loadMoreText:{
type:String,
value:'已经到底了'
},
showLoadMore:{
type:Boolean,
value:true
},
loadAll:{
type:Boolean,
value:false
}
},
/**
* 组件的初始数据
*/
data: {
heightStyle:'',
scrollHeight:0
},
lifetimes:{
attached(){
this.createSelectorQuery().select('#scrollView').boundingClientRect((res)=>{
this.data.scrollHeight = res.height;
}).exec();
const windowInfo = wx.getWindowInfo();
}
},
/**
* 组件的方法列表
*/
methods: {
refreshList(){
this.triggerEvent('refresh');
},
scrolling(event){
//scrollTop scrollHeight
const bottomHeight = event.detail.scrollHeight-event.detail.scrollTop-this.data.scrollHeight;
if(bottomHeight<100){
this.triggerEvent('loadMore');
}
},
loadMoreIfNeed(){
const query = this.createSelectorQuery();
query.select('#scrollView').scrollOffset();
query.exec((res)=>{
const bottomHeight = res[0].scrollHeight-res[0].scrollTop-this.data.scrollHeight;
if(bottomHeight<100){
this.triggerEvent('loadMore');
}
})
}
},
observers:{
height(h){
let heightStyle = '';
if(h){
if(typeof h == 'string'){
heightStyle = `height:${h}`
}else{
heightStyle = `height:${this.properties.height*2}rpx`
}
this.setData({
heightStyle:heightStyle
})
}
}
}
})