2026-09-14 14:59:28 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 消息列表页 U23
|
|
|
|
|
|
*
|
|
|
|
|
|
* 不变量(AGENTS.md):
|
|
|
|
|
|
* - 第 3 条:Mutual Match 后才能聊天
|
|
|
|
|
|
* - 第 4 条:Block/Unmatch 后会话立即停用
|
|
|
|
|
|
* - 第 6 条:单向活动意向不泄露
|
|
|
|
|
|
* - 第 9 条:DB 是 Source of Truth
|
|
|
|
|
|
*/
|
|
|
|
|
|
import { messageStore, appStore, authStore } from '../../stores';
|
|
|
|
|
|
import { ROUTE, to } from '../../constants';
|
2026-09-23 09:55:40 +08:00
|
|
|
|
// 顶部安全区:实测右上角胶囊按钮矩形,避免快捷入口与搜索图标被胶囊压住(见 utils/nav-metrics.js)
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
|
|
const { navSafeData } = require('../../utils/nav-metrics');
|
2026-09-14 14:59:28 +08:00
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
|
data: {
|
2026-09-23 09:55:40 +08:00
|
|
|
|
navVars: '',
|
2026-09-14 14:59:28 +08:00
|
|
|
|
conversations: [] as any[],
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
unreadTotal: 0,
|
|
|
|
|
|
emptyActions: [{ text: '去今日推荐', event: 'home', variant: 'primary' }],
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onLoad() {
|
2026-09-23 09:55:40 +08:00
|
|
|
|
// 顶部安全区先算:onLoad 早于首次渲染,避免出现「先压住胶囊再跳开」的闪动
|
|
|
|
|
|
this.setData(navSafeData());
|
2026-09-14 14:59:28 +08:00
|
|
|
|
(this as any)._unsubMsg = messageStore.bindToPage(this, {
|
|
|
|
|
|
conversations: 'conversations',
|
|
|
|
|
|
totalUnreadCount: 'unreadTotal',
|
|
|
|
|
|
});
|
|
|
|
|
|
(this as any)._unsubLoading = messageStore.subscribe((state: any) => {
|
|
|
|
|
|
if (state.conversationsLoading !== this.data.loading) {
|
|
|
|
|
|
this.setData({ loading: state.conversationsLoading });
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
this.setData({ loading: messageStore.state.conversationsLoading });
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
|
|
if (!authStore.state.isLoggedIn) return;
|
|
|
|
|
|
messageStore.fetchConversations().catch((err: any) => appStore.toastError(err));
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onUnload() {
|
|
|
|
|
|
if ((this as any)._unsubMsg) (this as any)._unsubMsg();
|
|
|
|
|
|
if ((this as any)._unsubLoading) (this as any)._unsubLoading();
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
messageStore.fetchConversations().finally(() => wx.stopPullDownRefresh());
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
if (messageStore.state.conversationsHasMore) {
|
|
|
|
|
|
messageStore.loadMoreConversations().catch(() => {});
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onGoChat(e: any) {
|
|
|
|
|
|
const { conversationId, canSendMessage } = e.detail;
|
|
|
|
|
|
if (!canSendMessage) {
|
|
|
|
|
|
appStore.toastError('当前会话已停用,无法继续聊天');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
wx.navigateTo({ url: to.chat(conversationId) });
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onShortcutTap(e: any) {
|
|
|
|
|
|
const key = e.currentTarget.dataset.key;
|
|
|
|
|
|
if (key === 'new-friends') { wx.switchTab({ url: ROUTE.TAB.DISCOVER }); return; }
|
|
|
|
|
|
if (key === 'system') { wx.navigateTo({ url: ROUTE.SETTINGS.NOTIFICATIONS }); return; }
|
|
|
|
|
|
wx.navigateTo({ url: ROUTE.MAIN.FATE_CENTER });
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onEmptyAction(e: any) {
|
|
|
|
|
|
if (e.detail.event === 'home') wx.switchTab({ url: ROUTE.TAB.HOME });
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|