chore: establish V1.1 recovery baseline
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 消息列表页 U23(重构:用 messageStore + conversation-item)
|
||||
*
|
||||
* 不变量(AGENTS.md):
|
||||
* - 第 3 条:Mutual Match 后才能聊天——列表只展示 mutualMatch 状态的会话;
|
||||
* 若 conversation.canSendMessage=false(已 Block/Unmatch),仍展示但置灰,点击进入后禁止输入。
|
||||
* - 第 4 条:Block/Unmatch 后会话立即停用,UI 不删除而是显示"已停用"提示。
|
||||
* - 第 6 条:单向活动意向不泄露——此页只展示已建立的 Mutual 会话,不会泄露对方是否单独选过我。
|
||||
* - 第 9 条:DB 是 Source of Truth——本地不缓存完整会话历史,每次进入页面重新拉取最新列表。
|
||||
*/
|
||||
const { messageStore, appStore, authStore } = require('../../stores');
|
||||
const { ROUTE, to } = require('../../constants');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
conversations: [],
|
||||
loading: false,
|
||||
unreadTotal: 0,
|
||||
emptyActions: [
|
||||
{ text: '去今日推荐', event: 'home', variant: 'primary' },
|
||||
],
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 绑定 messageStore 字段到 page data
|
||||
this._unsubMsg = messageStore.bindToPage(this, {
|
||||
conversations: 'conversations',
|
||||
totalUnreadCount: 'unreadTotal',
|
||||
});
|
||||
this._unsubLoading = messageStore.subscribe((state) => {
|
||||
if (state.conversationsLoading !== this.data.loading) {
|
||||
this.setData({ loading: state.conversationsLoading });
|
||||
}
|
||||
});
|
||||
this.setData({ loading: messageStore.state.conversationsLoading });
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!authStore.state.isLoggedIn) return;
|
||||
// 每次显示重新拉取会话列表(最新的 lastMessage / 未读数会刷新)
|
||||
messageStore.fetchConversations().catch((err) => appStore.toastError(err));
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
this._unsubMsg && this._unsubMsg();
|
||||
this._unsubLoading && this._unsubLoading();
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
messageStore.fetchConversations().finally(() => wx.stopPullDownRefresh());
|
||||
},
|
||||
|
||||
onReachBottom() {
|
||||
if (messageStore.state.conversationsHasMore) {
|
||||
messageStore.loadMoreConversations().catch(() => {});
|
||||
}
|
||||
},
|
||||
|
||||
onGoChat(e) {
|
||||
const { conversationId } = e.detail;
|
||||
wx.navigateTo({ url: to.chat(conversationId) });
|
||||
},
|
||||
|
||||
onEmptyAction(e) {
|
||||
if (e.detail.event === 'home') {
|
||||
wx.switchTab({ url: ROUTE.TAB.HOME });
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"navigationBarTitleText": "消息",
|
||||
"enablePullDownRefresh": true,
|
||||
"backgroundColor": "#F7F8FA",
|
||||
"backgroundTextStyle": "dark",
|
||||
"usingComponents": {
|
||||
"ui-conversation-item": "/components/conversation-item/index",
|
||||
"ui-empty": "/components/empty/index",
|
||||
"ui-loading": "/components/loading/index",
|
||||
"ui-section-header": "/components/section-header/index"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<!-- 消息列表页 U23 -->
|
||||
<view class="page">
|
||||
<ui-section-header
|
||||
wx:if="{{conversations.length > 0}}"
|
||||
title="消息"
|
||||
subtitle="{{unreadTotal > 0 ? unreadTotal + ' 条未读' : '全部已读'}}"
|
||||
/>
|
||||
|
||||
<!-- 加载中(首次) -->
|
||||
<ui-loading
|
||||
wx:if="{{loading && conversations.length === 0}}"
|
||||
mode="skeleton"
|
||||
rows="4"
|
||||
/>
|
||||
|
||||
<!-- 会话列表 -->
|
||||
<block wx:elif="{{conversations.length > 0}}">
|
||||
<ui-conversation-item
|
||||
wx:for="{{conversations}}"
|
||||
wx:key="conversationId"
|
||||
conversation="{{item}}"
|
||||
bind:tap="onGoChat"
|
||||
/>
|
||||
<!-- 加载更多 -->
|
||||
<ui-loading
|
||||
wx:if="{{loading && conversations.length > 0}}"
|
||||
mode="spinner"
|
||||
text="加载更多会话…"
|
||||
inline
|
||||
/>
|
||||
</block>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<ui-empty
|
||||
wx:elif="{{!loading}}"
|
||||
illustration="message"
|
||||
title="还没有消息"
|
||||
description="互相喜欢后可以开始聊天。去看看今天为你推荐的人吧。"
|
||||
actions="{{emptyActions}}"
|
||||
bind:action="onEmptyAction"
|
||||
/>
|
||||
</view>
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* 消息列表页样式(重构后大幅简化,主体样式封装在 ui-conversation-item 内)
|
||||
*/
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: var(--color-bg-page);
|
||||
}
|
||||
Reference in New Issue
Block a user