index.vue 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  1. <template>
  2. <view class="message-page">
  3. <!-- 顶部标题栏 -->
  4. <view class="header">
  5. <text class="header-title">💬 消息</text>
  6. <view class="header-actions">
  7. <text class="action-icon" @click="showSearchPanel = true">🔍</text>
  8. </view>
  9. </view>
  10. <!-- 搜索面板 -->
  11. <view v-if="showSearchPanel" class="search-panel">
  12. <view class="search-bar">
  13. <input
  14. class="search-input"
  15. v-model="searchKeyword"
  16. placeholder="搜索好友或消息内容"
  17. @input="onSearch" />
  18. <text class="search-cancel" @click="cancelSearch">取消</text>
  19. </view>
  20. </view>
  21. <!-- 会话列表 -->
  22. <scroll-view
  23. class="conversation-list"
  24. scroll-y
  25. refresher-enabled
  26. :refresher-triggered="refreshing"
  27. @refresherrefresh="onRefresh"
  28. @scrolltolower="loadMore">
  29. <!-- 骨架屏加载状态 -->
  30. <view v-if="loading && conversations.length === 0" class="skeleton-container">
  31. <view v-for="i in 6" :key="i" class="skeleton-item">
  32. <view class="skeleton-avatar"></view>
  33. <view class="skeleton-content">
  34. <view class="skeleton-line skeleton-line-title"></view>
  35. <view class="skeleton-line skeleton-line-text"></view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 空状态(初次/无搜索) -->
  40. <view v-if="conversations.length === 0 && !loading && !searchKeyword" class="empty-container">
  41. <view class="empty-icon-wrapper">
  42. <text class="empty-icon">💬</text>
  43. </view>
  44. <text class="empty-text">暂无消息</text>
  45. <text class="empty-hint">开始和心仪的TA聊天吧~</text>
  46. <view class="empty-action">
  47. <button class="empty-btn" @click="switchTab('recommend')">去推荐页面</button>
  48. </view>
  49. </view>
  50. <!-- 系统消息作为第一条会话项展示(整合到同列表,突出样式) -->
  51. <view v-else-if="!searchKeyword" class="conversation-item-wrapper system-highlight" @click="openSystemMessages">
  52. <view class="conversation-item">
  53. <view class="avatar-wrapper">
  54. <text class="system-icon">📢</text>
  55. <view v-if="systemUnread > 0" class="unread-badge">{{ systemUnread > 99 ? '99+' : systemUnread }}</view>
  56. </view>
  57. <view class="conversation-content">
  58. <view class="content-top">
  59. <text class="user-name system-title">系统通知</text>
  60. <text class="last-time">{{ systemLatestTime ? formatTime(systemLatestTime) : '' }}</text>
  61. </view>
  62. <view class="content-bottom">
  63. <text class="last-message system-preview">{{ systemLatestPreview || '平台公告及处理通知' }}</text>
  64. <text class="system-tag"></text>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 搜索无结果 -->
  70. <view v-else-if="searchKeyword && filteredConversations.length === 0" class="empty-container">
  71. <view class="empty-icon-wrapper">
  72. <text class="empty-icon">🔍</text>
  73. </view>
  74. <text class="empty-text">没有找到相关内容</text>
  75. <text class="empty-hint">试试搜索其他关键词</text>
  76. </view>
  77. <!-- 会话列表项(带滑动) -->
  78. <view
  79. v-for="conv in filteredConversations"
  80. :key="conv.id"
  81. class="conversation-item-wrapper">
  82. <movable-area class="movable-area">
  83. <movable-view
  84. class="movable-view"
  85. direction="horizontal"
  86. :x="conv.id === swipingConvId ? -150 : 0"
  87. @change="handleSwipe($event, conv)"
  88. @touchend="handleSwipeEnd(conv)">
  89. <view class="conversation-item" @click="openChat(conv)" @longpress="showActionMenu(conv)">
  90. <!-- 置顶标记 -->
  91. <view v-if="conv.isPinned" class="pinned-badge">📌</view>
  92. <!-- 头像 -->
  93. <view class="avatar-wrapper">
  94. <image
  95. class="avatar"
  96. :src="conv.targetUserAvatar || '/static/default-avatar.svg'"
  97. mode="aspectFill"
  98. lazy-load />
  99. <view v-if="conv.isOnline" class="online-badge"></view>
  100. <view v-if="conv.unreadCount > 0" class="unread-badge">
  101. {{ conv.unreadCount > 99 ? '99+' : conv.unreadCount }}
  102. </view>
  103. </view>
  104. <!-- 会话内容 -->
  105. <view class="conversation-content">
  106. <view class="content-top">
  107. <text class="user-name">{{ conv.targetUserName }}</text>
  108. <text class="last-time">{{formatTime(conv.lastMessageTime) }}</text>
  109. </view>
  110. <view class="content-bottom">
  111. <text class="last-message" :class="{ unread: conv.unreadCount > 0 }">
  112. {{ formatLastMessage(conv) }}
  113. </text>
  114. <text v-if="conv.lastMessageType === 1" class="message-type-icon">📝</text>
  115. <text v-else-if="conv.lastMessageType === 2" class="message-type-icon">🖼️</text>
  116. <text v-else-if="conv.lastMessageType === 3" class="message-type-icon">🎤</text>
  117. <text v-else-if="conv.lastMessageType === 4" class="message-type-icon">📹</text>
  118. </view>
  119. </view>
  120. </view>
  121. </movable-view>
  122. <!-- 右滑操作按钮 -->
  123. <view class="conversation-actions">
  124. <view class="action-btn pin-btn" @click.stop="togglePin(conv)">
  125. {{ conv.isPinned ? '取消' : '置顶' }}
  126. </view>
  127. <view class="action-btn delete-btn" @click.stop="confirmDeleteConversation(conv)">
  128. 删除
  129. </view>
  130. </view>
  131. </movable-area>
  132. </view>
  133. <!-- 加载更多 -->
  134. <view v-if="hasMore && conversations.length > 0" class="load-more">
  135. <text class="load-more-text">{{ loading ? '加载中...' : '上拉加载更多' }}</text>
  136. </view>
  137. <view v-else-if="!hasMore && conversations.length > 0" class="load-more">
  138. <text class="load-more-text">没有更多了</text>
  139. </view>
  140. </scroll-view>
  141. <!-- 底部导航栏 -->
  142. <view class="tabbar">
  143. <view class="tabbar-item" @click="switchTab('index')">
  144. <text class="tabbar-icon">🏠</text>
  145. <text class="tabbar-text">首页</text>
  146. </view>
  147. <view class="tabbar-item" @click="switchTab('plaza')">
  148. <text class="tabbar-icon">💕</text>
  149. <text class="tabbar-text">广场</text>
  150. </view>
  151. <view class="tabbar-item" @click="switchTab('recommend')">
  152. <text class="tabbar-icon">👍</text>
  153. <text class="tabbar-text">推荐</text>
  154. </view>
  155. <view class="tabbar-item active">
  156. <text class="tabbar-icon">💬</text>
  157. <text class="tabbar-text">消息</text>
  158. <view v-if="totalUnread > 0" class="tab-badge">
  159. {{ totalUnread > 99 ? '99+' : totalUnread }}
  160. </view>
  161. </view>
  162. <view class="tabbar-item" @click="switchTab('mine')">
  163. <text class="tabbar-icon">👤</text>
  164. <text class="tabbar-text">我的</text>
  165. </view>
  166. </view>
  167. <!-- 操作菜单 -->
  168. <uni-popup ref="actionMenu" type="bottom">
  169. <view class="action-menu">
  170. <view class="menu-item" @click="markAsRead">标为已读</view>
  171. <view class="menu-item" @click="deleteCurrentConversation">删除会话</view>
  172. <view class="menu-item cancel" @click="closeActionMenu">取消</view>
  173. </view>
  174. </uni-popup>
  175. </view>
  176. </template>
  177. <script>
  178. import { getConversations, getUnreadCount, deleteConversation, checkOnlineStatus } from '@/utils/chat-api.js';
  179. import wsManager from '@/utils/websocket.js';
  180. import timManager from '@/utils/tim-manager.js';
  181. import TIM from 'tim-wx-sdk';
  182. export default {
  183. data() {
  184. return {
  185. blacklistUsers: [], // 拉黑用户ID列表
  186. blacklistLoaded: false, // 拉黑列表是否加载完成
  187. userId: null,
  188. conversations: [],
  189. loading: false,
  190. refreshing: false,
  191. hasMore: false, // TIM 一次性返回所有会话,不分页
  192. currentPage: 1,
  193. pageSize: 20,
  194. totalUnread: 0,
  195. showSearchPanel: false,
  196. searchKeyword: '',
  197. selectedConversation: null,
  198. onlineCheckTimer: null,
  199. timInitialized: false,
  200. // 滑动相关
  201. swipingConvId: null,
  202. // 置顶会话列表(本地存储)
  203. pinnedConversations: []
  204. , systemUnread: 0
  205. , systemLatestTime: null
  206. , systemLatestPreview: ''
  207. };
  208. },
  209. computed: {
  210. // 过滤和排序会话列表
  211. filteredConversations() {
  212. let list = [...this.conversations];
  213. // 搜索过滤
  214. if (this.searchKeyword) {
  215. list = list.filter(conv => {
  216. return conv.targetUserName.includes(this.searchKeyword) ||
  217. conv.lastMessage.includes(this.searchKeyword);
  218. });
  219. }
  220. // 按置顶和时间排序
  221. list.sort((a, b) => {
  222. // 置顶优先
  223. if (a.isPinned && !b.isPinned) return -1;
  224. if (!a.isPinned && b.isPinned) return 1;
  225. // 时间倒序
  226. return new Date(b.lastMessageTime) - new Date(a.lastMessageTime);
  227. });
  228. return list;
  229. }
  230. },
  231. onLoad() {
  232. // 获取登录凭证
  233. const token = uni.getStorageSync('token');
  234. const userInfo = uni.getStorageSync('userInfo');
  235. const storedUserId = uni.getStorageSync('userId');
  236. console.log('=== 消息页面登录状态检查 ===');
  237. console.log('token:', token ? '存在' : '不存在');
  238. console.log('userInfo:', userInfo);
  239. console.log('storedUserId:', storedUserId);
  240. // 严格验证登录状态
  241. if (!token || !userInfo) {
  242. console.error('❌ 未登录或登录信息不完整');
  243. uni.showModal({
  244. title: '需要登录',
  245. content: '请先登录后再查看消息',
  246. showCancel: false,
  247. success: () => {
  248. uni.reLaunch({
  249. url: '/pages/page3/page3'
  250. });
  251. }
  252. });
  253. return;
  254. }
  255. // 优先使用 storage 中的 userId,确保一致性
  256. this.userId = storedUserId || userInfo.userId || userInfo.id || userInfo.user_id;
  257. // 转换为数字类型(如果是字符串)
  258. if (typeof this.userId === 'string') {
  259. this.userId = parseInt(this.userId);
  260. }
  261. // 最终验证 userId
  262. if (!this.userId || isNaN(this.userId)) {
  263. console.error('❌ 无法获取有效的用户ID');
  264. console.error('userInfo:', JSON.stringify(userInfo));
  265. console.error('storedUserId:', storedUserId);
  266. uni.showModal({
  267. title: '用户信息错误',
  268. content: '无法获取用户ID,请重新登录',
  269. showCancel: false,
  270. success: () => {
  271. // 清除错误的登录信息
  272. uni.removeStorageSync('token');
  273. uni.removeStorageSync('userInfo');
  274. uni.removeStorageSync('userId');
  275. uni.reLaunch({
  276. url: '/pages/page3/page3'
  277. });
  278. }
  279. });
  280. return;
  281. }
  282. console.log('✅ 当前登录用户ID:', this.userId, '(类型:', typeof this.userId, ')');
  283. // 确保 userId 同步到 storage(以防不一致)
  284. if (storedUserId !== this.userId) {
  285. console.log('⚠️ 同步 userId 到 storage');
  286. uni.setStorageSync('userId', this.userId);
  287. }
  288. // 加载置顶会话列表(基于当前用户ID)
  289. this.loadPinnedConversations();
  290. // 初始化腾讯云IM(确保使用正确的用户ID登录)
  291. this.initTIM();
  292. // 拉取系统消息未读
  293. this.loadSystemUnread();
  294. // 监听刷新事件(从聊天页面返回时触发)
  295. uni.$on('refreshConversations', this.refreshConversations);
  296. uni.$on('blacklistUpdated', this.handleBlacklistUpdate);
  297. },
  298. onShow() {
  299. console.log('=== 消息页面显示 ===');
  300. // 重新验证登录状态
  301. const token = uni.getStorageSync('token');
  302. const storedUserId = uni.getStorageSync('userId');
  303. console.log('onShow - 检查登录状态:');
  304. console.log(' - token:', token ? '存在' : '不存在');
  305. console.log(' - storedUserId:', storedUserId);
  306. console.log(' - this.userId:', this.userId);
  307. // 如果未登录,跳转登录页
  308. if (!token || !storedUserId) {
  309. console.warn('⚠️ 未登录,跳转登录页');
  310. uni.reLaunch({
  311. url: '/pages/page3/page3'
  312. });
  313. return;
  314. }
  315. // 如果用户ID改变,更新页面userId并重新初始化TIM
  316. if (storedUserId !== this.userId) {
  317. console.warn('⚠️ 用户ID改变,从', this.userId, '到', storedUserId);
  318. console.log('🔄 更新页面userId并重新初始化TIM...');
  319. this.userId = storedUserId;
  320. this.timInitialized = false;
  321. // 重新初始化TIM
  322. this.initTIM().catch(error => {
  323. console.error('❌ 重新初始化TIM失败:', error);
  324. uni.showToast({
  325. title: '初始化失败',
  326. icon: 'none'
  327. });
  328. });
  329. return;
  330. }
  331. console.log('✅ 登录状态正常,用户ID:', this.userId);
  332. // 页面显示时刷新会话列表
  333. this.refreshConversations();
  334. this.loadSystemUnread();
  335. },
  336. onUnload() {
  337. // 清除定时器
  338. if (this.onlineCheckTimer) {
  339. clearInterval(this.onlineCheckTimer);
  340. }
  341. // 移除事件监听
  342. uni.$off('refreshConversations', this.refreshConversations);
  343. // 移除拉黑状态变更监听
  344. uni.$off('blacklistUpdated', this.handleBlacklistUpdate);
  345. },
  346. methods: {
  347. /**
  348. * 处理拉黑列表更新事件
  349. */
  350. async handleBlacklistUpdate() {
  351. console.log('🔄 检测到拉黑列表更新,开始刷新会话列表');
  352. // 重置拉黑列表加载状态
  353. this.blacklistLoaded = false;
  354. // 重新加载拉黑列表
  355. await this.loadBlacklist();
  356. // 重新加载系统消息未读
  357. await this.loadSystemUnread();
  358. // 重新加载会话列表(会自动过滤拉黑用户)
  359. this.loadConversations();
  360. // 显示提示
  361. uni.showToast({
  362. title: '已更新会话列表',
  363. icon: 'success',
  364. duration: 1500
  365. });
  366. },
  367. /**
  368. * 初始化腾讯云IM
  369. */
  370. async initTIM() {
  371. try {
  372. console.log('📱 初始化腾讯云IM...');
  373. console.log('📱 当前用户ID:', this.userId);
  374. // 如果未初始化,先初始化
  375. if (!timManager.tim) {
  376. timManager.init(1600109674); // SDKAppID
  377. console.log('✅ TIM SDK 实例已创建');
  378. }
  379. // 检查是否已登录,以及登录的用户是否匹配
  380. if (timManager.isLogin && timManager.userId) {
  381. // 如果已登录但用户ID不匹配,先登出
  382. if (String(timManager.userId) !== String(this.userId)) {
  383. console.warn('⚠️ 检测到用户切换,从', timManager.userId, '到', this.userId);
  384. console.log('⚠️ 执行登出操作...');
  385. await timManager.logout();
  386. } else {
  387. console.log('✅ TIM 已登录,用户ID匹配:', this.userId);
  388. this.timInitialized = true;
  389. // 直接加载会话列表
  390. this.loadConversations();
  391. return;
  392. }
  393. }
  394. // 执行登录流程
  395. console.log('🔐 开始登录流程,用户ID:', this.userId);
  396. // 先导入用户到腾讯云IM
  397. await this.importUser();
  398. // 获取 UserSig 并登录
  399. const userSig = await this.getUserSig();
  400. console.log('🔑 获取到 UserSig');
  401. // 登录到 TIM
  402. await timManager.login(this.userId, userSig);
  403. console.log('✅ TIM 登录成功,用户ID:', this.userId);
  404. // 监听会话列表更新
  405. timManager.tim.on(TIM.EVENT.CONVERSATION_LIST_UPDATED, (event) => {
  406. console.log('📋 会话列表更新事件触发');
  407. console.log('📋 当前登录用户:', this.userId);
  408. this.loadConversations();
  409. });
  410. this.timInitialized = true;
  411. console.log('✅ TIM 初始化完成');
  412. // 加载会话列表
  413. this.loadConversations();
  414. } catch (error) {
  415. console.error('❌ TIM 初始化失败:', error);
  416. console.error('❌ 错误详情:', error.message || error);
  417. uni.showToast({
  418. title: '初始化失败: ' + (error.message || '请重试'),
  419. icon: 'none',
  420. duration: 3000
  421. });
  422. }
  423. },
  424. /**
  425. * 导入用户到腾讯云IM
  426. */
  427. async importUser() {
  428. try {
  429. await uni.request({
  430. url: 'http://localhost:1004/api/im/importUser',
  431. method: 'POST',
  432. data: {
  433. userId: String(this.userId)
  434. }
  435. });
  436. console.log('✅ 用户导入成功');
  437. } catch (error) {
  438. console.log('⚠️ 用户导入失败(可能已存在):', error);
  439. // 导入失败不影响登录
  440. }
  441. },
  442. /**
  443. * 获取 UserSig
  444. */
  445. async getUserSig() {
  446. try {
  447. const res = await uni.request({
  448. url: `http://localhost:1004/api/im/getUserSig?userId=${this.userId}`,
  449. method: 'GET'
  450. });
  451. if (res[1].data.code === 200) {
  452. return res[1].data.data.userSig;
  453. } else {
  454. throw new Error(res[1].data.message);
  455. }
  456. } catch (error) {
  457. console.error('❌ 获取 UserSig 失败:', error);
  458. throw error;
  459. }
  460. },
  461. /**
  462. * 加载会话列表(从腾讯云IM)
  463. */
  464. async loadConversations() {
  465. if (this.loading || !this.timInitialized) {
  466. console.log('⏸️ 跳过加载会话列表:', this.loading ? '正在加载中' : 'TIM未初始化');
  467. return;
  468. }
  469. // 确保先加载拉黑列表
  470. if (!this.blacklistLoaded) {
  471. await this.loadBlacklist();
  472. }
  473. // 验证登录状态
  474. if (!timManager.isLogin || !timManager.userId) {
  475. console.error('❌ TIM 未登录或用户ID为空');
  476. return;
  477. }
  478. // 验证用户ID是否匹配
  479. if (String(timManager.userId) !== String(this.userId)) {
  480. console.error('❌ 用户ID不匹配!TIM:', timManager.userId, '页面:', this.userId);
  481. console.log('🔄 自动切换用户,重新登录TIM...');
  482. // 自动重新初始化TIM(会自动登出旧用户并登录新用户)
  483. this.timInitialized = false;
  484. try {
  485. await this.initTIM();
  486. // 初始化完成后会自动调用loadConversations
  487. } catch (error) {
  488. console.error('❌ 重新初始化TIM失败:', error);
  489. uni.showModal({
  490. title: '切换用户失败',
  491. content: '请重新登录',
  492. showCancel: false,
  493. success: () => {
  494. uni.reLaunch({
  495. url: '/pages/page3/page3'
  496. });
  497. }
  498. });
  499. }
  500. return;
  501. }
  502. this.loading = true;
  503. console.log('🔄 开始加载会话列表,用户ID:', this.userId);
  504. try {
  505. // 从腾讯云IM获取会话列表(仅当前登录用户的会话)
  506. const conversationList = await timManager.getConversationList();
  507. console.log('📋 从TIM获取到会话数:', conversationList.length);
  508. // 转换为UI需要的格式
  509. let formattedConversations = conversationList.map(conv => {
  510. const formatted = this.formatConversation(conv);
  511. // 验证会话是否属于当前用户
  512. if (formatted.userId !== this.userId) {
  513. console.warn('⚠️ 发现不属于当前用户的会话:', formatted);
  514. }
  515. return formatted;
  516. });
  517. // 过滤掉不属于当前用户的会话(双重保险)
  518. formattedConversations = formattedConversations.filter(conv => conv.userId === this.userId);
  519. // 先计算所有会话的未读数(包括拉黑用户)
  520. const allUnreadCount = formattedConversations.reduce((total, conv) => total + conv.unreadCount, 0);
  521. // 过滤掉拉黑用户的会话 🌟
  522. formattedConversations = formattedConversations.filter(conv => {
  523. return !this.blacklistUsers.includes(conv.targetUserId.toString());
  524. });
  525. this.conversations = formattedConversations;
  526. // 批量获取用户头像信息
  527. await this.loadUserAvatars();
  528. // 计算总未读数(包括所有会话的未读 + 系统消息未读)
  529. this.totalUnread = allUnreadCount + this.systemUnread;
  530. // 同步到Vuex
  531. this.$store.dispatch('updateTotalUnread', this.totalUnread);
  532. console.log('✅ 会话列表加载成功');
  533. console.log(' - 当前用户ID:', this.userId);
  534. console.log(' - 会话数量:', this.conversations.length);
  535. console.log(' - 拉黑用户数:', this.blacklistUsers.length);
  536. console.log(' - 会话未读数:', allUnreadCount);
  537. console.log(' - 系统消息未读数:', this.systemUnread);
  538. console.log(' - 总未读数:', this.totalUnread);
  539. // 输出前3个会话的详细信息(调试用)
  540. if (this.conversations.length > 0) {
  541. console.log('📋 会话预览(前3个):');
  542. this.conversations.slice(0, 3).forEach((conv, idx) => {
  543. console.log(` ${idx + 1}. ${conv.targetUserName} (ID:${conv.targetUserId}) 头像: ${conv.targetUserAvatar}, 未读: ${conv.unreadCount}`);
  544. });
  545. }
  546. if (this.blacklistUsers.length > 0) {
  547. console.log('🚫 已过滤拉黑用户:', this.blacklistUsers);
  548. }
  549. } catch (e) {
  550. console.error('❌ 加载会话列表失败:', e);
  551. console.error('❌ 错误详情:', e.message || e);
  552. uni.showToast({
  553. title: '加载失败: ' + (e.message || '请重试'),
  554. icon: 'none',
  555. duration: 2000
  556. });
  557. } finally {
  558. this.loading = false;
  559. this.refreshing = false;
  560. }
  561. },
  562. /**
  563. * 获取拉黑用户列表
  564. */
  565. async loadBlacklist() {
  566. try {
  567. console.log('🔄 加载拉黑用户列表,用户ID:', this.userId);
  568. const res = await uni.request({
  569. url: 'http://localhost:8083/api/chatfriend/getBlacklist', // 替换为你的后端接口
  570. method: 'GET',
  571. data: {
  572. userId: this.userId
  573. }
  574. });
  575. if (res[1].statusCode === 200 && res[1].data.code === 200) {
  576. // 假设返回格式: {data: [{targetUserId: 'xxx'}, ...]}
  577. const blacklistData = res[1].data.data || [];
  578. this.blacklistUsers = blacklistData.map(item => {
  579. // 确保用户ID为字符串格式,避免类型不一致问题
  580. return String(item.targetUserId || item.userId || item.id);
  581. });
  582. console.log('✅ 拉黑列表加载成功,共', this.blacklistUsers.length, '个拉黑用户:', this.blacklistUsers);
  583. } else {
  584. console.warn('⚠️ 拉黑列表接口返回异常:', res[1].data);
  585. }
  586. } catch (error) {
  587. console.error('❌ 加载拉黑列表失败:', error);
  588. // 加载失败不影响会话列表显示,只记录错误
  589. } finally {
  590. this.blacklistLoaded = true; // 标记为已加载,避免重复请求
  591. }
  592. },
  593. /**
  594. * 批量获取用户头像信息
  595. */
  596. async loadUserAvatars() {
  597. try {
  598. if (this.conversations.length === 0) {
  599. return;
  600. }
  601. // 收集所有需要获取头像的用户ID
  602. const userIds = this.conversations
  603. .map(conv => conv.targetUserId)
  604. .filter(id => id) // 过滤掉空值
  605. .join(',');
  606. if (!userIds) {
  607. console.log('⚠️ 没有需要获取头像的用户');
  608. return;
  609. }
  610. console.log('🔄 开始批量获取用户头像,用户ID列表:', userIds);
  611. // 调用批量获取用户信息接口
  612. const res = await uni.request({
  613. url: 'http://localhost:8083/api/user/batch',
  614. method: 'GET',
  615. data: {
  616. userIds: userIds
  617. }
  618. });
  619. if (res[1].statusCode === 200 && res[1].data.code === 200) {
  620. const userList = res[1].data.data || [];
  621. console.log('✅ 批量获取用户信息成功,数量:', userList.length);
  622. // 创建用户ID到用户信息的映射
  623. const userMap = {};
  624. userList.forEach(user => {
  625. userMap[user.userId] = user;
  626. });
  627. // 更新会话列表中的头像和昵称
  628. this.conversations.forEach(conv => {
  629. const userInfo = userMap[conv.targetUserId];
  630. if (userInfo) {
  631. // 更新头像(如果数据库中有头像)
  632. if (userInfo.avatarUrl) {
  633. conv.targetUserAvatar = userInfo.avatarUrl;
  634. }
  635. // 更新昵称(如果数据库中的昵称更准确)
  636. if (userInfo.nickname && userInfo.nickname !== `用户${conv.targetUserId}`) {
  637. conv.targetUserName = userInfo.nickname;
  638. }
  639. console.log(`🖼️ 更新用户 ${conv.targetUserId} 的信息:`, {
  640. 昵称: conv.targetUserName,
  641. 头像: conv.targetUserAvatar
  642. });
  643. }
  644. });
  645. } else {
  646. console.error('❌ 批量获取用户信息失败:', res[1].data);
  647. }
  648. } catch (error) {
  649. console.error('❌ 批量获取用户头像失败:', error);
  650. // 头像获取失败不影响会话列表显示,只记录错误
  651. }
  652. },
  653. /**
  654. * 格式化会话数据
  655. * 将TIM的会话格式转换为UI需要的格式
  656. */
  657. formatConversation(timConv) {
  658. // conversationID 格式: C2C{userId}
  659. const targetUserId = timConv.conversationID.replace('C2C', '');
  660. // 检查是否在本地置顶列表中
  661. const isPinned = this.pinnedConversations.includes(timConv.conversationID) ? 1 : 0;
  662. return {
  663. id: timConv.conversationID,
  664. userId: this.userId,
  665. targetUserId: targetUserId,
  666. targetUserName: timConv.userProfile?.nick || `用户${targetUserId}`,
  667. targetUserAvatar: timConv.userProfile?.avatar || '',
  668. lastMessage: this.getLastMessageText(timConv.lastMessage),
  669. lastMessageType: this.getMessageType(timConv.lastMessage),
  670. lastMessageTime: timConv.lastMessage?.lastTime ? timConv.lastMessage.lastTime * 1000 : Date.now(),
  671. unreadCount: timConv.unreadCount || 0,
  672. isOnline: false,
  673. isPinned: isPinned
  674. };
  675. },
  676. /**
  677. * 获取最后一条消息的文本
  678. */
  679. getLastMessageText(message) {
  680. if (!message) return '暂无消息';
  681. switch (message.type) {
  682. case 'TIMTextElem':
  683. return message.payload?.text || '';
  684. case 'TIMImageElem':
  685. return '[图片]';
  686. case 'TIMSoundElem':
  687. return '[语音]';
  688. case 'TIMVideoFileElem':
  689. return '[视频]';
  690. case 'TIMFileElem':
  691. return '[文件]';
  692. case 'TIMCustomElem':
  693. // 处理自定义消息(我们的语音消息)
  694. try {
  695. const customData = JSON.parse(message.payload.data);
  696. if (customData.type === 'voice') {
  697. return '[语音]';
  698. }
  699. } catch (e) {
  700. console.error('解析自定义消息失败:', e);
  701. }
  702. return '[自定义消息]';
  703. default:
  704. return '[未知消息]';
  705. }
  706. },
  707. /**
  708. * 获取消息类型
  709. */
  710. getMessageType(message) {
  711. if (!message) return 1;
  712. const typeMap = {
  713. 'TIMTextElem': 1, // 文本
  714. 'TIMImageElem': 2, // 图片
  715. 'TIMSoundElem': 3, // 语音
  716. 'TIMVideoFileElem': 4 // 视频
  717. };
  718. return typeMap[message.type] || 1;
  719. },
  720. /**
  721. * 下拉刷新
  722. */
  723. onRefresh() {
  724. this.refreshing = true;
  725. this.loadConversations();
  726. },
  727. /**
  728. * 加载更多(TIM一次性返回所有会话,不需要分页)
  729. */
  730. loadMore() {
  731. // TIM SDK 一次性返回所有会话,不需要分页加载
  732. },
  733. /**
  734. * 加载系统消息未读
  735. */
  736. async loadSystemUnread() {
  737. try {
  738. const userId = this.userId;
  739. const res = await this.$api?.message?.getSystemUnreadCount ? this.$api.message.getSystemUnreadCount(userId) : null;
  740. if (res && (res.code === 200 || res.code === 0)) {
  741. this.systemUnread = res.data || 0;
  742. } else {
  743. // 直接调用工具方法
  744. const api = require('@/utils/api.js').default;
  745. const r = await api.message.getSystemUnreadCount(userId);
  746. this.systemUnread = r.data || 0;
  747. }
  748. // 预览最新一条
  749. const api2 = require('@/utils/api.js').default;
  750. const listRes = await api2.message.getSystemList(userId, 1, 1);
  751. const list = listRes.data?.list || listRes.data || [];
  752. if (list.length > 0) {
  753. this.systemLatestTime = list[0].createdAt || list[0].created_at;
  754. this.systemLatestPreview = list[0].title || '系统通知';
  755. }
  756. // 更新总未读数
  757. const allUnreadCount = this.conversations.reduce((total, conv) => total + conv.unreadCount, 0);
  758. this.totalUnread = allUnreadCount + this.systemUnread;
  759. // 同步到Vuex
  760. this.$store.dispatch('updateTotalUnread', this.totalUnread);
  761. } catch (e) {
  762. console.log('加载系统未读失败', e);
  763. }
  764. },
  765. openSystemMessages() {
  766. uni.navigateTo({ url: '/pages/message/system' });
  767. },
  768. /**
  769. * 刷新会话列表
  770. */
  771. refreshConversations() {
  772. if (this.timInitialized) {
  773. // 先刷新系统消息未读
  774. this.loadSystemUnread();
  775. // 再刷新会话列表
  776. this.loadConversations();
  777. }
  778. },
  779. /**
  780. * 打开聊天页面
  781. */
  782. openChat(conversation) {
  783. uni.navigateTo({
  784. url: `/pages/message/chat?targetUserId=${conversation.targetUserId}&targetUserName=${conversation.targetUserName}&targetUserAvatar=${conversation.targetUserAvatar || ''}`
  785. });
  786. },
  787. /**
  788. * 显示操作菜单
  789. */
  790. showActionMenu(conversation) {
  791. this.selectedConversation = conversation;
  792. this.$refs.actionMenu.open();
  793. },
  794. /**
  795. * 关闭操作菜单
  796. */
  797. closeActionMenu() {
  798. this.$refs.actionMenu.close();
  799. this.selectedConversation = null;
  800. },
  801. /**
  802. * 标记为已读
  803. */
  804. async markAsRead() {
  805. if (!this.selectedConversation) {
  806. return;
  807. }
  808. try {
  809. // 调用 TIM SDK 标记已读
  810. await timManager.setMessageRead(this.selectedConversation.id);
  811. // 更新本地显示
  812. this.selectedConversation.unreadCount = 0;
  813. // 重新计算总未读数(包含所有会话+系统消息)
  814. const allUnreadCount = this.conversations.reduce((total, conv) => total + conv.unreadCount, 0);
  815. this.totalUnread = allUnreadCount + this.systemUnread;
  816. // 同步到Vuex
  817. this.$store.dispatch('updateTotalUnread', this.totalUnread);
  818. uni.showToast({
  819. title: '已标记为已读',
  820. icon: 'success'
  821. });
  822. } catch (e) {
  823. console.error('标记已读失败', e);
  824. }
  825. this.closeActionMenu();
  826. },
  827. /**
  828. * 删除会话
  829. */
  830. async deleteCurrentConversation() {
  831. if (!this.selectedConversation) {
  832. return;
  833. }
  834. uni.showModal({
  835. title: '确认删除',
  836. content: '确定要删除该会话吗?',
  837. success: async (res) => {
  838. if (res.confirm) {
  839. try {
  840. // 调用 TIM SDK 删除会话
  841. await timManager.tim.deleteConversation(this.selectedConversation.id);
  842. // 从列表中移除
  843. const index = this.conversations.findIndex(c => c.id === this.selectedConversation.id);
  844. if (index > -1) {
  845. this.conversations.splice(index, 1);
  846. }
  847. // 重新计算总未读数(包含所有会话+系统消息)
  848. const allUnreadCount = this.conversations.reduce((total, conv) => total + conv.unreadCount, 0);
  849. this.totalUnread = allUnreadCount + this.systemUnread;
  850. // 同步到Vuex
  851. this.$store.dispatch('updateTotalUnread', this.totalUnread);
  852. uni.showToast({
  853. title: '删除成功',
  854. icon: 'success'
  855. });
  856. } catch (e) {
  857. console.error('删除会话失败', e);
  858. uni.showToast({
  859. title: '删除失败',
  860. icon: 'none'
  861. });
  862. }
  863. }
  864. }
  865. });
  866. this.closeActionMenu();
  867. },
  868. /**
  869. * 搜索(实时过滤在computed中实现)
  870. */
  871. onSearch() {
  872. console.log('搜索:', this.searchKeyword);
  873. // filteredConversations computed属性会自动过滤
  874. },
  875. /**
  876. * 取消搜索
  877. */
  878. cancelSearch() {
  879. this.showSearchPanel = false;
  880. this.searchKeyword = '';
  881. },
  882. /**
  883. * 处理滑动
  884. */
  885. handleSwipe(e, conv) {
  886. if (e.detail.x < -50) {
  887. this.swipingConvId = conv.id;
  888. } else if (e.detail.x > -10) {
  889. this.swipingConvId = null;
  890. }
  891. },
  892. /**
  893. * 滑动结束
  894. */
  895. handleSwipeEnd(conv) {
  896. // 如果滑动距离不够,自动回弹
  897. setTimeout(() => {
  898. if (this.swipingConvId === conv.id) {
  899. // 保持显示操作按钮
  900. }
  901. }, 100);
  902. },
  903. /**
  904. * 切换置顶状态
  905. */
  906. togglePin(conv) {
  907. conv.isPinned = conv.isPinned ? 0 : 1;
  908. // 保存到本地存储
  909. this.savePinnedConversations();
  910. // 重置滑动状态
  911. this.swipingConvId = null;
  912. uni.showToast({
  913. title: conv.isPinned ? '已置顶' : '已取消置顶',
  914. icon: 'success'
  915. });
  916. },
  917. /**
  918. * 加载置顶会话列表
  919. */
  920. loadPinnedConversations() {
  921. try {
  922. const pinned = uni.getStorageSync('pinnedConversations_' + this.userId);
  923. if (pinned) {
  924. this.pinnedConversations = JSON.parse(pinned);
  925. }
  926. } catch (e) {
  927. console.error('加载置顶列表失败:', e);
  928. }
  929. },
  930. /**
  931. * 保存置顶会话列表
  932. */
  933. savePinnedConversations() {
  934. try {
  935. const pinnedIds = this.conversations
  936. .filter(conv => conv.isPinned)
  937. .map(conv => conv.id);
  938. uni.setStorageSync('pinnedConversations_' + this.userId, JSON.stringify(pinnedIds));
  939. } catch (e) {
  940. console.error('保存置顶列表失败:', e);
  941. }
  942. },
  943. /**
  944. * 确认删除会话
  945. */
  946. confirmDeleteConversation(conv) {
  947. uni.showModal({
  948. title: '确认删除',
  949. content: '确定要删除该会话吗?',
  950. success: (res) => {
  951. if (res.confirm) {
  952. this.deleteConversationItem(conv);
  953. }
  954. }
  955. });
  956. // 重置滑动状态
  957. this.swipingConvId = null;
  958. },
  959. /**
  960. * 删除会话
  961. */
  962. async deleteConversationItem(conv) {
  963. try {
  964. // 调用 TIM SDK 删除会话
  965. await timManager.tim.deleteConversation(conv.id);
  966. // 从列表中移除
  967. const index = this.conversations.findIndex(c => c.id === conv.id);
  968. if (index > -1) {
  969. this.conversations.splice(index, 1);
  970. }
  971. // 重新计算总未读数(包含所有会话+系统消息)
  972. const allUnreadCount = this.conversations.reduce((total, c) => total + c.unreadCount, 0);
  973. this.totalUnread = allUnreadCount + this.systemUnread;
  974. // 同步到Vuex
  975. this.$store.dispatch('updateTotalUnread', this.totalUnread);
  976. uni.showToast({
  977. title: '删除成功',
  978. icon: 'success'
  979. });
  980. } catch (e) {
  981. console.error('删除会话失败', e);
  982. uni.showToast({
  983. title: '删除失败',
  984. icon: 'none'
  985. });
  986. }
  987. },
  988. /**
  989. * 格式化最后一条消息
  990. */
  991. formatLastMessage(conv) {
  992. if (!conv.lastMessage) {
  993. return '暂无消息';
  994. }
  995. // 限制长度
  996. const maxLen = 30;
  997. if (conv.lastMessage.length > maxLen) {
  998. return conv.lastMessage.substring(0, maxLen) + '...';
  999. }
  1000. return conv.lastMessage;
  1001. },
  1002. /**
  1003. * 格式化时间
  1004. */
  1005. formatTime(time) {
  1006. if (!time) return '';
  1007. const date = new Date(time);
  1008. const now = new Date();
  1009. const diff = now - date;
  1010. // 今天
  1011. if (date.toDateString() === now.toDateString()) {
  1012. return date.toLocaleTimeString('zh-CN', {
  1013. hour: '2-digit',
  1014. minute: '2-digit'
  1015. });
  1016. }
  1017. // 昨天
  1018. const yesterday = new Date(now);
  1019. yesterday.setDate(yesterday.getDate() - 1);
  1020. if (date.toDateString() === yesterday.toDateString()) {
  1021. return '昨天';
  1022. }
  1023. // 本周
  1024. if (diff < 7 * 24 * 60 * 60 * 1000) {
  1025. const days = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
  1026. return days[date.getDay()];
  1027. }
  1028. // 更早
  1029. return date.toLocaleDateString('zh-CN', {
  1030. month: '2-digit',
  1031. day: '2-digit'
  1032. });
  1033. },
  1034. /**
  1035. * 切换标签页
  1036. */
  1037. switchTab(tab) {
  1038. if (tab === 'message') return;
  1039. const tabPages = {
  1040. index: '/pages/index/index',
  1041. plaza: '/pages/plaza/index',
  1042. recommend: '/pages/recommend/index',
  1043. mine: '/pages/mine/index'
  1044. };
  1045. if (tabPages[tab]) {
  1046. uni.redirectTo({
  1047. url: tabPages[tab]
  1048. });
  1049. }
  1050. }
  1051. }
  1052. };
  1053. </script>
  1054. <style lang="scss" scoped>
  1055. .message-page {
  1056. min-height: 100vh;
  1057. background-color: #F5F5F5;
  1058. padding-bottom: 120rpx;
  1059. }
  1060. /* 顶部标题栏 */
  1061. .header {
  1062. display: flex;
  1063. align-items: center;
  1064. justify-content: space-between;
  1065. padding: 30rpx;
  1066. background-color: #FFFFFF;
  1067. border-bottom: 1rpx solid #F0F0F0;
  1068. .header-title {
  1069. font-size: 40rpx;
  1070. font-weight: bold;
  1071. color: #E91E63;
  1072. }
  1073. .header-actions {
  1074. display: flex;
  1075. gap: 30rpx;
  1076. .action-icon {
  1077. font-size: 40rpx;
  1078. cursor: pointer;
  1079. }
  1080. }
  1081. }
  1082. /* 搜索面板 */
  1083. .search-panel {
  1084. background-color: #FFFFFF;
  1085. padding: 20rpx 30rpx;
  1086. border-bottom: 1rpx solid #F0F0F0;
  1087. .search-bar {
  1088. display: flex;
  1089. align-items: center;
  1090. gap: 20rpx;
  1091. .search-input {
  1092. flex: 1;
  1093. height: 70rpx;
  1094. padding: 0 20rpx;
  1095. background-color: #F5F5F5;
  1096. border-radius: 35rpx;
  1097. font-size: 28rpx;
  1098. }
  1099. .search-cancel {
  1100. font-size: 28rpx;
  1101. color: #E91E63;
  1102. }
  1103. }
  1104. }
  1105. /* 会话列表 */
  1106. .conversation-list {
  1107. height: calc(100vh - 200rpx);
  1108. background-color: #FFFFFF;
  1109. }
  1110. /* 骨架屏 */
  1111. .skeleton-container {
  1112. padding: 20rpx 0;
  1113. }
  1114. .skeleton-item {
  1115. display: flex;
  1116. align-items: center;
  1117. padding: 25rpx 30rpx;
  1118. background-color: #FFFFFF;
  1119. border-bottom: 1rpx solid #F5F5F5;
  1120. .skeleton-avatar {
  1121. width: 100rpx;
  1122. height: 100rpx;
  1123. border-radius: 12rpx;
  1124. background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  1125. background-size: 200% 100%;
  1126. animation: skeleton-loading 1.5s ease-in-out infinite;
  1127. margin-right: 25rpx;
  1128. }
  1129. .skeleton-content {
  1130. flex: 1;
  1131. .skeleton-line {
  1132. height: 30rpx;
  1133. border-radius: 6rpx;
  1134. background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  1135. background-size: 200% 100%;
  1136. animation: skeleton-loading 1.5s ease-in-out infinite;
  1137. &.skeleton-line-title {
  1138. width: 40%;
  1139. margin-bottom: 20rpx;
  1140. }
  1141. &.skeleton-line-text {
  1142. width: 60%;
  1143. }
  1144. }
  1145. }
  1146. }
  1147. @keyframes skeleton-loading {
  1148. 0% {
  1149. background-position: 200% 0;
  1150. }
  1151. 100% {
  1152. background-position: -200% 0;
  1153. }
  1154. }
  1155. /* 空状态 */
  1156. .empty-container {
  1157. display: flex;
  1158. flex-direction: column;
  1159. align-items: center;
  1160. justify-content: center;
  1161. padding: 150rpx 60rpx;
  1162. .empty-icon-wrapper {
  1163. width: 200rpx;
  1164. height: 200rpx;
  1165. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  1166. border-radius: 50%;
  1167. display: flex;
  1168. align-items: center;
  1169. justify-content: center;
  1170. margin-bottom: 40rpx;
  1171. box-shadow: 0 20rpx 60rpx rgba(102, 126, 234, 0.3);
  1172. animation: float 3s ease-in-out infinite;
  1173. }
  1174. .empty-icon {
  1175. font-size: 100rpx;
  1176. filter: brightness(1.2);
  1177. }
  1178. .empty-text {
  1179. font-size: 36rpx;
  1180. font-weight: 600;
  1181. color: #333333;
  1182. margin-bottom: 15rpx;
  1183. }
  1184. .empty-hint {
  1185. font-size: 28rpx;
  1186. color: #999999;
  1187. margin-bottom: 40rpx;
  1188. }
  1189. .empty-action {
  1190. margin-top: 20rpx;
  1191. .empty-btn {
  1192. padding: 20rpx 60rpx;
  1193. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  1194. color: #FFFFFF;
  1195. border-radius: 50rpx;
  1196. font-size: 28rpx;
  1197. border: none;
  1198. box-shadow: 0 10rpx 30rpx rgba(102, 126, 234, 0.3);
  1199. &::after {
  1200. border: none;
  1201. }
  1202. }
  1203. }
  1204. }
  1205. @keyframes float {
  1206. 0%, 100% {
  1207. transform: translateY(0);
  1208. }
  1209. 50% {
  1210. transform: translateY(-20rpx);
  1211. }
  1212. }
  1213. /* 会话列表项包装器 */
  1214. .conversation-item-wrapper {
  1215. position: relative;
  1216. background-color: #FFFFFF;
  1217. border-bottom: 1rpx solid #F5F5F5;
  1218. overflow: hidden;
  1219. }
  1220. /* 系统消息高亮样式 */
  1221. .system-highlight { background: #fff7f7; }
  1222. .system-icon { font-size: 44rpx; color: #E91E63; }
  1223. .system-title { color: #E91E63; font-weight: 600; }
  1224. .system-preview { color: #d25d6b; }
  1225. .system-tag { font-size: 22rpx; color: #fff; background-color: #E91E63; padding: 4rpx 10rpx; border-radius: 8rpx; }
  1226. /* 滑动区域 */
  1227. .movable-area {
  1228. width: 100%;
  1229. height: 160rpx;
  1230. position: relative;
  1231. }
  1232. .movable-view {
  1233. width: 100%;
  1234. height: 100%;
  1235. background-color: #FFFFFF;
  1236. }
  1237. /* 会话列表项 */
  1238. .conversation-item {
  1239. display: flex;
  1240. align-items: center;
  1241. padding: 25rpx 30rpx;
  1242. background-color: #FFFFFF;
  1243. position: relative;
  1244. width: 94%;
  1245. height: 100%;
  1246. &:active {
  1247. background-color: #F8F8F8;
  1248. }
  1249. /* 置顶标记 */
  1250. .pinned-badge {
  1251. position: absolute;
  1252. top: 10rpx;
  1253. left: 10rpx;
  1254. font-size: 28rpx;
  1255. opacity: 0.7;
  1256. }
  1257. .avatar-wrapper {
  1258. position: relative;
  1259. margin-right: 25rpx;
  1260. .avatar {
  1261. width: 100rpx;
  1262. height: 100rpx;
  1263. border-radius: 12rpx;
  1264. }
  1265. .online-badge {
  1266. position: absolute;
  1267. bottom: 0;
  1268. right: 0;
  1269. width: 24rpx;
  1270. height: 24rpx;
  1271. background-color: #07C160;
  1272. border: 3rpx solid #FFFFFF;
  1273. border-radius: 50%;
  1274. }
  1275. .unread-badge {
  1276. position: absolute;
  1277. top: -10rpx;
  1278. right: -10rpx;
  1279. min-width: 36rpx;
  1280. height: 36rpx;
  1281. line-height: 36rpx;
  1282. padding: 0 8rpx;
  1283. background-color: #FA5151;
  1284. border-radius: 18rpx;
  1285. font-size: 20rpx;
  1286. color: #FFFFFF;
  1287. text-align: center;
  1288. }
  1289. }
  1290. .conversation-content {
  1291. flex: 1;
  1292. .content-top {
  1293. display: flex;
  1294. align-items: center;
  1295. justify-content: space-between;
  1296. margin-bottom: 12rpx;
  1297. .user-name {
  1298. font-size: 32rpx;
  1299. font-weight: 500;
  1300. color: #333333;
  1301. }
  1302. .last-time {
  1303. font-size: 24rpx;
  1304. color: #999999;
  1305. }
  1306. }
  1307. .content-bottom {
  1308. display: flex;
  1309. align-items: center;
  1310. gap: 10rpx;
  1311. .last-message {
  1312. flex: 1;
  1313. font-size: 28rpx;
  1314. color: #999999;
  1315. overflow: hidden;
  1316. text-overflow: ellipsis;
  1317. white-space: nowrap;
  1318. &.unread {
  1319. color: #666666;
  1320. font-weight: 500;
  1321. }
  1322. }
  1323. .message-type-icon {
  1324. font-size: 28rpx;
  1325. }
  1326. }
  1327. }
  1328. /* 右滑操作按钮 */
  1329. .conversation-actions {
  1330. position: absolute;
  1331. right: 0;
  1332. top: 0;
  1333. height: 100%;
  1334. display: flex;
  1335. z-index: 1;
  1336. .action-btn {
  1337. width: 150rpx;
  1338. height: 100%;
  1339. display: flex;
  1340. align-items: center;
  1341. justify-content: center;
  1342. color: #FFFFFF;
  1343. font-size: 28rpx;
  1344. }
  1345. .pin-btn {
  1346. background-color: #576B95;
  1347. }
  1348. .delete-btn {
  1349. background-color: #FA5151;
  1350. }
  1351. }
  1352. }
  1353. .load-more {
  1354. padding: 30rpx;
  1355. text-align: center;
  1356. .load-more-text {
  1357. font-size: 26rpx;
  1358. color: #999999;
  1359. }
  1360. }
  1361. /* 底部导航栏 */
  1362. .tabbar {
  1363. position: fixed;
  1364. bottom: 0;
  1365. left: 0;
  1366. right: 0;
  1367. display: flex;
  1368. background-color: #FFFFFF;
  1369. border-top: 1rpx solid #F0F0F0;
  1370. padding-bottom: constant(safe-area-inset-bottom);
  1371. padding-bottom: env(safe-area-inset-bottom);
  1372. z-index: 999;
  1373. .tabbar-item {
  1374. flex: 1;
  1375. display: flex;
  1376. flex-direction: column;
  1377. align-items: center;
  1378. justify-content: center;
  1379. padding: 15rpx 0;
  1380. position: relative;
  1381. .tabbar-icon {
  1382. font-size: 44rpx;
  1383. margin-bottom: 5rpx;
  1384. }
  1385. .tabbar-text {
  1386. font-size: 22rpx;
  1387. color: #666666;
  1388. }
  1389. .tab-badge {
  1390. position: absolute;
  1391. top: 8rpx;
  1392. right: 50%;
  1393. margin-right: -40rpx;
  1394. min-width: 32rpx;
  1395. height: 32rpx;
  1396. line-height: 32rpx;
  1397. padding: 0 6rpx;
  1398. background-color: #FA5151;
  1399. border-radius: 16rpx;
  1400. font-size: 20rpx;
  1401. color: #FFFFFF;
  1402. text-align: center;
  1403. }
  1404. &.active {
  1405. .tabbar-text {
  1406. color: #E91E63;
  1407. font-weight: bold;
  1408. }
  1409. }
  1410. }
  1411. }
  1412. /* 操作菜单 */
  1413. .action-menu {
  1414. background-color: #FFFFFF;
  1415. border-radius: 20rpx 20rpx 0 0;
  1416. .menu-item {
  1417. padding: 30rpx;
  1418. text-align: center;
  1419. font-size: 32rpx;
  1420. color: #333333;
  1421. border-bottom: 1rpx solid #F0F0F0;
  1422. &:active {
  1423. background-color: #F8F8F8;
  1424. }
  1425. &.cancel {
  1426. color: #999999;
  1427. border: none;
  1428. margin-top: 20rpx;
  1429. }
  1430. }
  1431. }
  1432. </style>