You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
923 B
51 lines
923 B
1 year ago
|
import {
|
||
|
onLoad,
|
||
|
onShow,
|
||
|
onHide,
|
||
|
onUnload,
|
||
|
onReachBottom,
|
||
|
onPullDownRefresh
|
||
|
} from '@dcloudio/uni-app'
|
||
|
|
||
|
const commonJs = () => {
|
||
|
// 页面初始化执行
|
||
|
onLoad((_info) => {
|
||
|
uni.startPullDownRefresh()
|
||
|
})
|
||
|
|
||
|
// 添加防抖函数
|
||
|
let antiShake: any = null
|
||
|
// 触底加载
|
||
|
onReachBottom(() => {
|
||
|
// 数据请求完毕, 不再请求
|
||
|
if (isEnd) return
|
||
|
if (antiShake) return clearTimeout(antiShake)
|
||
|
antiShake = setTimeout(() => {
|
||
|
// 当前页码 +1
|
||
|
details.page.current += 1
|
||
|
// 请求页面数据
|
||
|
initPage()
|
||
|
}, 500)
|
||
|
})
|
||
|
|
||
|
// 下拉刷新
|
||
|
onPullDownRefresh(async () => {
|
||
|
// 重置页码
|
||
|
details.page.current = 1
|
||
|
// 恢复结束状态
|
||
|
details.isEnd = false
|
||
|
// 清空渲染列表
|
||
|
details.renderList = []
|
||
|
|
||
|
const res = await initPage()
|
||
|
if (res) {
|
||
|
setTimeout(() => {
|
||
|
// 关闭刷新动画
|
||
|
uni.stopPullDownRefresh()
|
||
|
}, 1000)
|
||
|
}
|
||
|
})
|
||
|
return {}
|
||
|
}
|
||
|
|
||
|
export default commonJs
|