Update: Merge remote changes and preserve local features

This commit is contained in:
zhiyun 2026-02-05 01:11:49 +08:00
parent d32801cb5b
commit 638f13df1f
3 changed files with 18 additions and 28 deletions

View File

@ -71,6 +71,7 @@ Page({
// 滚动控制
scrollIntoView: '',
scrollTop: 0, // 当前滚动位置
scrollAnimation: false, // 控制滚动动画
// 加载状态
loading: true,
@ -636,7 +637,8 @@ Page({
isFirstLoad: false,
hasMore: true // 假设还有更多,允许下拉
}, () => {
this.scrollToBottom()
// 首次加载(缓存)使用无动画滚动,避免视觉跳动
this.scrollToBottom(false)
})
}
@ -680,15 +682,16 @@ Page({
// 只有当消息列表真的发生变化时才更新,避免闪烁
if (finalMessages.length !== this.data.messages.length) {
this.setData({
messages: finalMessages,
hasMore: res.data.length >= pageSize,
page: 1,
isFirstLoad: false
}, () => {
this.scrollToBottom()
// 更新缓存
this.saveMessagesToCache(finalMessages)
})
messages: finalMessages,
hasMore: res.data.length >= pageSize,
page: 1,
isFirstLoad: false
}, () => {
// API更新时也使用无动画滚动确保位置稳定
this.scrollToBottom(false)
// 更新缓存
this.saveMessagesToCache(finalMessages)
})
} else {
console.log('[chat-detail] 消息列表无变化,跳过更新')
this.setData({ isFirstLoad: false })
@ -1260,13 +1263,15 @@ Page({
/**
* 滚动到底部仅在发送/接收新消息时调用
* 使用 scroll-into-view 属性自动滚动到最后一条消息
* @param {boolean} animated - 是否使用动画滚动默认true
*/
scrollToBottom() {
scrollToBottom(animated = true) {
const messages = this.data.messages
if (messages && messages.length > 0) {
// 使用 setTimeout 确保 DOM 已更新
setTimeout(() => {
this.setData({
scrollAnimation: animated,
scrollIntoView: `msg-${messages.length - 1}`
})
}, 100)

View File

@ -37,7 +37,7 @@
scroll-y
class="chat-scroll"
scroll-into-view="{{scrollIntoView}}"
scroll-with-animation="{{true}}"
scroll-with-animation="{{scrollAnimation}}"
enhanced="{{true}}"
show-scrollbar="{{false}}"
bindscroll="onScroll"

View File

@ -63,22 +63,7 @@
</view>
</view>
<!-- 如何加入说明 -->
<view class="how-to-join">
<view class="join-icon-wrapper">
<view class="join-icon">
<view class="dot dot-1"></view>
<view class="dot dot-2"></view>
<view class="dot dot-3"></view>
<view class="dot dot-4"></view>
<view class="line"></view>
</view>
</view>
<view class="join-content">
<view class="join-title">如何加入</view>
<view class="join-desc">点击上方感兴趣的分类,保存二维码图片或长按扫码识别,一键申请即可。</view>
</view>
</view>
<!-- 底部占位 -->
<view style="height: 60rpx;"></view>