Update: Merge remote changes and preserve local features
This commit is contained in:
parent
d32801cb5b
commit
638f13df1f
|
|
@ -71,6 +71,7 @@ Page({
|
||||||
// 滚动控制
|
// 滚动控制
|
||||||
scrollIntoView: '',
|
scrollIntoView: '',
|
||||||
scrollTop: 0, // 当前滚动位置
|
scrollTop: 0, // 当前滚动位置
|
||||||
|
scrollAnimation: false, // 控制滚动动画
|
||||||
|
|
||||||
// 加载状态
|
// 加载状态
|
||||||
loading: true,
|
loading: true,
|
||||||
|
|
@ -636,7 +637,8 @@ Page({
|
||||||
isFirstLoad: false,
|
isFirstLoad: false,
|
||||||
hasMore: true // 假设还有更多,允许下拉
|
hasMore: true // 假设还有更多,允许下拉
|
||||||
}, () => {
|
}, () => {
|
||||||
this.scrollToBottom()
|
// 首次加载(缓存)使用无动画滚动,避免视觉跳动
|
||||||
|
this.scrollToBottom(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -680,15 +682,16 @@ Page({
|
||||||
// 只有当消息列表真的发生变化时才更新,避免闪烁
|
// 只有当消息列表真的发生变化时才更新,避免闪烁
|
||||||
if (finalMessages.length !== this.data.messages.length) {
|
if (finalMessages.length !== this.data.messages.length) {
|
||||||
this.setData({
|
this.setData({
|
||||||
messages: finalMessages,
|
messages: finalMessages,
|
||||||
hasMore: res.data.length >= pageSize,
|
hasMore: res.data.length >= pageSize,
|
||||||
page: 1,
|
page: 1,
|
||||||
isFirstLoad: false
|
isFirstLoad: false
|
||||||
}, () => {
|
}, () => {
|
||||||
this.scrollToBottom()
|
// API更新时也使用无动画滚动,确保位置稳定
|
||||||
// 更新缓存
|
this.scrollToBottom(false)
|
||||||
this.saveMessagesToCache(finalMessages)
|
// 更新缓存
|
||||||
})
|
this.saveMessagesToCache(finalMessages)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log('[chat-detail] 消息列表无变化,跳过更新')
|
console.log('[chat-detail] 消息列表无变化,跳过更新')
|
||||||
this.setData({ isFirstLoad: false })
|
this.setData({ isFirstLoad: false })
|
||||||
|
|
@ -1260,13 +1263,15 @@ Page({
|
||||||
/**
|
/**
|
||||||
* 滚动到底部(仅在发送/接收新消息时调用)
|
* 滚动到底部(仅在发送/接收新消息时调用)
|
||||||
* 使用 scroll-into-view 属性,自动滚动到最后一条消息
|
* 使用 scroll-into-view 属性,自动滚动到最后一条消息
|
||||||
|
* @param {boolean} animated - 是否使用动画滚动,默认true
|
||||||
*/
|
*/
|
||||||
scrollToBottom() {
|
scrollToBottom(animated = true) {
|
||||||
const messages = this.data.messages
|
const messages = this.data.messages
|
||||||
if (messages && messages.length > 0) {
|
if (messages && messages.length > 0) {
|
||||||
// 使用 setTimeout 确保 DOM 已更新
|
// 使用 setTimeout 确保 DOM 已更新
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.setData({
|
this.setData({
|
||||||
|
scrollAnimation: animated,
|
||||||
scrollIntoView: `msg-${messages.length - 1}`
|
scrollIntoView: `msg-${messages.length - 1}`
|
||||||
})
|
})
|
||||||
}, 100)
|
}, 100)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
scroll-y
|
scroll-y
|
||||||
class="chat-scroll"
|
class="chat-scroll"
|
||||||
scroll-into-view="{{scrollIntoView}}"
|
scroll-into-view="{{scrollIntoView}}"
|
||||||
scroll-with-animation="{{true}}"
|
scroll-with-animation="{{scrollAnimation}}"
|
||||||
enhanced="{{true}}"
|
enhanced="{{true}}"
|
||||||
show-scrollbar="{{false}}"
|
show-scrollbar="{{false}}"
|
||||||
bindscroll="onScroll"
|
bindscroll="onScroll"
|
||||||
|
|
|
||||||
|
|
@ -63,22 +63,7 @@
|
||||||
</view>
|
</view>
|
||||||
</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>
|
<view style="height: 60rpx;"></view>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user