hookehuyr

fix(滚动列表): 修复滚动列表重置时位置不正确的问题

修复切换标签或视图模式时滚动列表位置未正确重置的问题
添加没有更多数据的提示样式
优化滚动列表的重置逻辑,使用随机数触发重新渲染
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
40 </nut-sticky> 40 </nut-sticky>
41 41
42 <!-- 消息列表内容 --> 42 <!-- 消息列表内容 -->
43 - <scroll-view class="conversation-list" :style="scrollStyle" :scroll-y="true" @scrolltolower="loadMore" 43 + <scroll-view ref="scrollViewRef" class="conversation-list" :style="scrollStyle" :scroll-y="true" @scrolltolower="loadMore"
44 - @scroll="scroll" :lower-threshold="50" :enable-flex="false"> 44 + @scroll="scroll" :lower-threshold="100" :enable-flex="false" :scroll-top="scrollTop">
45 <view v-for="conversation in filteredConversations" :key="conversation.id" 45 <view v-for="conversation in filteredConversations" :key="conversation.id"
46 class="conversation-item mt-2 mb-4 border-b border-gray-100 pb-2" 46 class="conversation-item mt-2 mb-4 border-b border-gray-100 pb-2"
47 @click="onConversationClick(conversation)"> 47 @click="onConversationClick(conversation)">
...@@ -73,6 +73,11 @@ ...@@ -73,6 +73,11 @@
73 <view v-if="loading" class="loading-container"> 73 <view v-if="loading" class="loading-container">
74 <text class="loading-text">加载中...</text> 74 <text class="loading-text">加载中...</text>
75 </view> 75 </view>
76 +
77 + <!-- 没有更多数据 -->
78 + <view v-if="!hasMore && filteredConversations.length > 0" class="no-more">
79 + <text class="no-more-text">没有更多消息了</text>
80 + </view>
76 </scroll-view> 81 </scroll-view>
77 82
78 <!-- 自定义TabBar --> 83 <!-- 自定义TabBar -->
...@@ -126,6 +131,10 @@ const scrollStyle = ref({ ...@@ -126,6 +131,10 @@ const scrollStyle = ref({
126 height: 'calc(100vh - 500rpx)' 131 height: 'calc(100vh - 500rpx)'
127 }) 132 })
128 133
134 +// 滚动相关变量
135 +const scrollViewRef = ref(null)
136 +const scrollTop = ref(0)
137 +
129 // 搜索值 138 // 搜索值
130 const searchValue = ref('') 139 const searchValue = ref('')
131 const onBlurSearch = () => { 140 const onBlurSearch = () => {
...@@ -213,8 +222,19 @@ const setActiveTab = (tabKey) => { ...@@ -213,8 +222,19 @@ const setActiveTab = (tabKey) => {
213 222
214 setTimeout(() => { 223 setTimeout(() => {
215 activeTab.value = tabKey; 224 activeTab.value = tabKey;
225 + // 重置搜索条件
226 + searchValue.value = '';
227 + // 重置分页状态
216 page.value = 1; 228 page.value = 1;
217 hasMore.value = true; 229 hasMore.value = true;
230 + // 重置加载状态
231 + loading.value = false;
232 + // 重置滚动位置
233 + scrollTop.value = Math.random(); // 使用随机数触发scroll-view重新渲染
234 + setTimeout(() => {
235 + scrollTop.value = 0; // 重置到顶部
236 + }, 50);
237 + // 重新初始化数据
218 initData(); 238 initData();
219 239
220 // 添加淡入效果 240 // 添加淡入效果
...@@ -375,6 +395,19 @@ onMounted(() => { ...@@ -375,6 +395,19 @@ onMounted(() => {
375 color: #9ca3af; 395 color: #9ca3af;
376 } 396 }
377 397
398 + /* 没有更多数据 */
399 + .no-more {
400 + display: flex;
401 + align-items: center;
402 + justify-content: center;
403 + padding: 40rpx;
404 + }
405 +
406 + .no-more-text {
407 + font-size: 28rpx;
408 + color: #9ca3af;
409 + }
410 +
378 /* Tailwind CSS 类的补充样式 */ 411 /* Tailwind CSS 类的补充样式 */
379 .w-12 { 412 .w-12 {
380 width: 88rpx; 413 width: 88rpx;
......
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
41 <!-- 订单列表 --> 41 <!-- 订单列表 -->
42 <view class="order-list"> 42 <view class="order-list">
43 <!-- 滚动列表 --> 43 <!-- 滚动列表 -->
44 - <scroll-view class="order-scroll-view" :style="scrollStyle" :scroll-y="true" @scrolltolower="loadMore" 44 + <scroll-view ref="scrollViewRef" class="order-scroll-view" :style="scrollStyle" :scroll-y="true" @scrolltolower="loadMore"
45 - @scroll="scroll" :lower-threshold="50" :enable-flex="false"> 45 + @scroll="scroll" :lower-threshold="50" :enable-flex="false" :scroll-top="scrollTop">
46 <!-- 空状态 --> 46 <!-- 空状态 -->
47 <view v-if="filteredOrders.length === 0" class="empty-state"> 47 <view v-if="filteredOrders.length === 0" class="empty-state">
48 <text class="empty-text">暂无订单</text> 48 <text class="empty-text">暂无订单</text>
...@@ -300,6 +300,10 @@ const scrollStyle = ref({ ...@@ -300,6 +300,10 @@ const scrollStyle = ref({
300 height: '' 300 height: ''
301 }) 301 })
302 302
303 +// 滚动相关
304 +const scrollViewRef = ref(null)
305 +const scrollTop = ref(0)
306 +
303 // 页面状态 307 // 页面状态
304 const activeTab = ref('all') 308 const activeTab = ref('all')
305 const viewMode = ref('bought') 309 const viewMode = ref('bought')
...@@ -518,9 +522,8 @@ const setViewMode = (mode) => { ...@@ -518,9 +522,8 @@ const setViewMode = (mode) => {
518 viewMode.value = mode 522 viewMode.value = mode
519 // 重置状态筛选标签到全部 523 // 重置状态筛选标签到全部
520 activeTab.value = 'all' 524 activeTab.value = 'all'
521 - resetListState() 525 + // 重置列表状态和数据
522 - // 重置加载更多的状态 526 + resetListState(true)
523 - hasMore.value = true
524 } 527 }
525 528
526 /** 529 /**
...@@ -529,17 +532,34 @@ const setViewMode = (mode) => { ...@@ -529,17 +532,34 @@ const setViewMode = (mode) => {
529 const setActiveTab = (tab) => { 532 const setActiveTab = (tab) => {
530 activeTab.value = tab 533 activeTab.value = tab
531 // 重置列表加载状态 534 // 重置列表加载状态
532 - resetListState() 535 + resetListState(false)
533 } 536 }
534 537
535 /** 538 /**
536 * 重置列表状态 539 * 重置列表状态
540 + * @param {boolean} resetData - 是否重置已加载的数据
537 */ 541 */
538 -const resetListState = () => { 542 +const resetListState = (resetData = false) => {
539 loading.value = false 543 loading.value = false
540 hasMore.value = true 544 hasMore.value = true
541 - // 重置加载索引,但不重置已加载的数据 545 +
542 - // 这样切换标签时不会重复加载数据,但切换视图模式时会重置 546 + // 重置滚动位置到顶部
547 + scrollTop.value = Math.random() // 使用随机数触发scroll-view重新渲染
548 +
549 + if (resetData) {
550 + // 重置已加载的数据索引
551 + loadedBoughtIndex.value = 0
552 + loadedSoldIndex.value = 0
553 +
554 + // 重置订单数据到初始状态
555 + boughtOrders.value = boughtOrders.value.slice(0, 5) // 保留前5条初始数据
556 + soldOrders.value = soldOrders.value.slice(0, 5) // 保留前5条初始数据
557 + }
558 +
559 + // 延迟重置scrollTop为0,确保滚动位置正确
560 + setTimeout(() => {
561 + scrollTop.value = 0
562 + }, 50)
543 } 563 }
544 564
545 /** 565 /**
......