修复寺庙列表加载更多

This commit is contained in:
2022-04-02 10:02:37 +08:00
parent 804efb793b
commit 2857087d3c
4 changed files with 63 additions and 36 deletions
@@ -1,7 +1,7 @@
<template> <template>
<div class="detail-content-expand"> <div class="detail-content-expand">
<div class="content" :class="[contentOverflow && !show && '']" ref="wrapper" :style="{height: (show ? contentHeight : defaultContentHeight) + 'px'}"> <div class="content" :class="[contentOverflow && !show && '']" ref="wrapper" :style="{height: (show ? contentHeight : defaultContentHeight) + 'px'}">
<div ref="content"> <div ref="content" class="ref-content">
<slot></slot> <slot></slot>
</div> </div>
</div> </div>
@@ -37,13 +37,15 @@ export default {
} }
} }
}, },
updated() { watch: {
'$slots'(val){
console.log('slots val',val)
}
}, },
mounted(){ mounted(){
this.wrapperHeight = this.$refs.wrapper.offsetHeight this.wrapperHeight = this.$refs.wrapper.offsetHeight
this.contentHeight = this.$refs.content.offsetHeight
this.$nextTick(() => { this.$nextTick(() => {
this.contentHeight = this.$refs.content.offsetHeight
this.wrapperContainerHeight = this.wrapperHeight; this.wrapperContainerHeight = this.wrapperHeight;
this.refresh(); this.refresh();
}) })
@@ -58,7 +60,6 @@ export default {
this.defaultContentHeight = 100; this.defaultContentHeight = 100;
return return
} }
console.log('selector', selector)
this.defaultContentHeight = selector.offsetHeight / (4/1) this.defaultContentHeight = selector.offsetHeight / (4/1)
} }
} }
+55 -30
View File
@@ -1,5 +1,5 @@
<template> <template>
<div class="temple-list" :style="{height: root.minHeight + 'px'}"> <div class="temple-list" :style="{height: root.minHeight - root.tabHeight + 'px'}">
<div class="topbar" ref="topbar"> <div class="topbar" ref="topbar">
<van-nav-bar left-arrow :title="$route.meta.title" v-if="$route.meta.showNavBar" @click-left="$router.back()" :style="{backgroundColor: $route.meta.navBarBackgroundColor}" /> <van-nav-bar left-arrow :title="$route.meta.title" v-if="$route.meta.showNavBar" @click-left="$router.back()" :style="{backgroundColor: $route.meta.navBarBackgroundColor}" />
<van-search v-model="keyword" show-action action-text="搜索" placeholder="请输入寺院、方丈、监院名称" @search="onSearch" @cancel="onCancel"> <van-search v-model="keyword" show-action action-text="搜索" placeholder="请输入寺院、方丈、监院名称" @search="onSearch" @cancel="onCancel">
@@ -29,17 +29,22 @@
<div > <div >
<div class="temple-list-container" :style="{height: containerHeight + 'px'}" v-if="mode === 'list'" > <div class="temple-list-container" :style="{height: containerHeight + 'px'}" v-if="mode === 'list'" >
<scroll-view <!-- <scroll-view -->
class="temple-container content" <!-- class="temple-container content"-->
:height="containerHeight - 20" <!-- :height="containerHeight - 20" -->
ref="scroll" <!-- ref="scroll"-->
pulldown <!-- pulldown -->
pullup <!-- pullup-->
@pulldown="refresh" <!-- @pulldown="refresh"-->
@pullup="loadMore" <!-- @pullup="loadMore"-->
> <!-- >-->
<!-- <temple v-for="temple in templeList" :key="temple.id" :data="temple" @location-to="onLocationTo"></temple>-->
<!-- </scroll-view>-->
<div class="temple-container content" :style="{height: containerHeight+'px'}" @scroll="onScroll">
<temple v-for="temple in templeList" :key="temple.id" :data="temple" @location-to="onLocationTo"></temple> <temple v-for="temple in templeList" :key="temple.id" :data="temple" @location-to="onLocationTo"></temple>
</scroll-view> <div v-if="loading" class="no-more">正在加载...</div>
<div class="no-more" v-if="!loading && noMore">没有更多了</div>
</div>
</div> </div>
<div class="temple-map" v-show="mode === 'map'" :style="{height: containerHeight + 'px'}"> <div class="temple-map" v-show="mode === 'map'" :style="{height: containerHeight + 'px'}">
<div id="container" style="height: 100%"></div> <div id="container" style="height: 100%"></div>
@@ -62,11 +67,13 @@ export default {
mode: 'list', mode: 'list',
page: 1, page: 1,
templeList: [], templeList: [],
lng: '', lng: '106.45233',
lat: '', lat: '29.507471',
map: null, map: null,
positioning: false, positioning: false,
noMore: false, noMore: false,
timer: null,
loading: false
} }
}, },
inject: ['root', 'parentHeight'], inject: ['root', 'parentHeight'],
@@ -92,6 +99,19 @@ export default {
this.wechatReady() this.wechatReady()
}, },
methods: { methods: {
onScroll(e){
const scrollTop = e.target.scrollTop;
const scrollHeight = e.target.offsetHeight;
const windowHeight = this.templeList.length * 220;
if(scrollTop === 0){
this.page = 1;
this.getTempleList()
return
}
if(((scrollTop + scrollHeight) / windowHeight) > 0.9){
this.loadMore()
}
},
initMap(){ initMap(){
TMAPLoader.load({ TMAPLoader.load({
key: process.env.VUE_APP_TMAP_KEY key: process.env.VUE_APP_TMAP_KEY
@@ -120,35 +140,37 @@ export default {
this.markers = markers; this.markers = markers;
}, },
async getTempleList(){ async getTempleList(){
this.loading = true;
const res = await getTempleList(this.keyword, this.lng, this.lat, this.page); const res = await getTempleList(this.keyword, this.lng, this.lat, this.page);
this.loading = false;
this.total = res.total;
if(this.page === 1){ if(this.page === 1){
this.total = res.total; this.templeList = [];
this.templeList = res.results;
} else {
this.templeList = this.templeList.concat(res.results);
this.noMore = res.results.length < 10;
} }
this.templeList = this.templeList.concat(res.results);
this.noMore = res.results.length < 10;
if(this.mode === 'map'){ if(this.mode === 'map'){
this.setMarker(); this.setMarker();
} }
this.$nextTick(() => {
this.scroll.refresh();
})
}, },
onGetLocation(){ async onGetLocation(){
this.positioning = true; this.positioning = true;
console.log(getLocation)
getLocation().then(res => { getLocation().then(res => {
console.log(res)
this.positioning = false this.positioning = false
this.lng = res.longitude; this.lng = res.longitude;
this.lat = res.latitude; this.lat = res.latitude;
this.page = 1; this.page = 1;
this.templeList = [];
this.getTempleList(); this.getTempleList();
}).catch((a) => { }).catch(() => {
console.log(a)
this.positioning = false; this.positioning = false;
}) })
}, },
refresh(){
this.page = 1;
this.getTempleList()
},
onLocationTo(data){ onLocationTo(data){
openLocation({ openLocation({
longitude: data.lng, longitude: data.lng,
@@ -173,11 +195,11 @@ export default {
}, },
loadMore(){ loadMore(){
if(this.noMore) return; if(this.noMore) return;
this.page += 1; clearTimeout(this.timer)
this.getTempleList(); this.timer = setTimeout(() => {
}, this.page += 1;
refresh(){ this.getTempleList()
console.log('refresh') }, 300)
}, },
} }
} }
@@ -239,6 +261,9 @@ export default {
height: 100%; height: 100%;
background: #f5f5f5; background: #f5f5f5;
} }
.temple-container{
overflow: scroll;
}
} }
} }
+1
View File
@@ -7,6 +7,7 @@ module.exports = {
filenameHashing: true, filenameHashing: true,
devServer: { devServer: {
// https:true, // https:true,
host: '0.0.0.0',
disableHostCheck: false, disableHostCheck: false,
proxy: { proxy: {
'/api': { '/api': {
+1 -1
View File
File diff suppressed because one or more lines are too long