Kaynağa Gözat

新增滚动模式

刘拾玖 4 ay önce
ebeveyn
işleme
d968ff6688

+ 19 - 3
components/pub-list-scroll/pub-list-scroll.vue

@@ -1,5 +1,5 @@
 <template>
-	<scroll-view class="scroll-view" @scrolltolower="onScrollTolower" scroll-y>
+	<scroll-view :scroll-top="scrollTop" class="scroll-view" @scrolltolower="onScrollTolower" scroll-y @scroll="scroll">
 		<slot />
 		<uni-load-more v-if="(loaded&&status!='noMore')||(!loaded && status=='noMore')" :status="status"
 			:content-text="contentText" />
@@ -9,7 +9,8 @@
 <script setup>
 	import {
 		ref,
-		computed
+		computed,
+		nextTick
 	} from 'vue';
 	const emit = defineEmits(['next'])
 	const props = defineProps({
@@ -24,7 +25,7 @@
 		text: {
 			type: String,
 			default: "数据加载中..."
-		}
+		},
 	})
 
 	const contentText = computed(() => {
@@ -35,11 +36,26 @@
 		}
 		return _text;
 	})
+	const scrollTop = ref(0)
+	const old = ref({
+		scrollTop: 0
+	})
+	
+	const scroll = (e)=> {
+		old.value.scrollTop = e.detail.scrollTop
+	}
+	const goTop = ()=> {
+		scrollTop.value = old.value.scrollTop
+		 nextTick(() => {
+		    scrollTop.value = 0
+		  })
+	}
 
 	//顶部tab点击
 	const onScrollTolower = () => {
 		emit('next')
 	}
+	defineExpose({ goTop });
 </script>
 
 

+ 5 - 2
pages/address/index.vue

@@ -1,7 +1,7 @@
 <template>
 	<view class="address-page">
 		<view class="address-section">
-			<pub-list-scroll @next="onScrollTolower" :loaded="loaded" :text="loadText" :status="status">
+			<pub-list-scroll ref="pubListScrollRef" @next="onScrollTolower" :loaded="loaded" :text="loadText" :status="status">
 				<view class="no-data" v-if="(!list || list.length == 0)&&!loaded">
 					<image mode="heightFix" src="/static/image/no-data.png" />
 					暂无数据
@@ -32,6 +32,7 @@
 			</pub-list-scroll>
 		</view>
 		<view class="pub-button is-bg large" @click="openDetails('add')">新增地址</view>
+
 		<!-- 选择弹窗 -->
 		<uni-popup ref="confirmPopup" type="dialog">
 			<uni-popup-dialog type="info" cancelText="取消" confirmText="确定" content="确定使用快递配送?" @confirm="onApply"
@@ -54,7 +55,8 @@
 	import * as link from '@/lib/link'
 	import { BasicInfoVO } from '../../lib/type';
 
-
+	const pubListScrollRef = ref(null)
+	const scrollTop = ref(0)
 	const loaded = ref(false)
 	const loadText = ref('数据加载中...')
 	const status = ref('loading')
@@ -163,6 +165,7 @@
 			}
 			// 重置滚动位置 
 			if (queryParams.value.pageNo === 1) { 
+				pubListScrollRef.value.goTop()
 			}
 		} catch (e) {
 			dlg.error(e)