index.vue 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  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. return '[自定义消息]';
  694. default:
  695. return '[未知消息]';
  696. }
  697. },
  698. /**
  699. * 获取消息类型
  700. */
  701. getMessageType(message) {
  702. if (!message) return 1;
  703. const typeMap = {
  704. 'TIMTextElem': 1, // 文本
  705. 'TIMImageElem': 2, // 图片
  706. 'TIMSoundElem': 3, // 语音
  707. 'TIMVideoFileElem': 4 // 视频
  708. };
  709. return typeMap[message.type] || 1;
  710. },
  711. /**
  712. * 下拉刷新
  713. */
  714. onRefresh() {
  715. this.refreshing = true;
  716. this.loadConversations();
  717. },
  718. /**
  719. * 加载更多(TIM一次性返回所有会话,不需要分页)
  720. */
  721. loadMore() {
  722. // TIM SDK 一次性返回所有会话,不需要分页加载
  723. },
  724. /**
  725. * 加载系统消息未读
  726. */
  727. async loadSystemUnread() {
  728. try {
  729. const userId = this.userId;
  730. const res = await this.$api?.message?.getSystemUnreadCount ? this.$api.message.getSystemUnreadCount(userId) : null;
  731. if (res && (res.code === 200 || res.code === 0)) {
  732. this.systemUnread = res.data || 0;
  733. } else {
  734. // 直接调用工具方法
  735. const api = require('@/utils/api.js').default;
  736. const r = await api.message.getSystemUnreadCount(userId);
  737. this.systemUnread = r.data || 0;
  738. }
  739. // 预览最新一条
  740. const api2 = require('@/utils/api.js').default;
  741. const listRes = await api2.message.getSystemList(userId, 1, 1);
  742. const list = listRes.data?.list || listRes.data || [];
  743. if (list.length > 0) {
  744. this.systemLatestTime = list[0].createdAt || list[0].created_at;
  745. this.systemLatestPreview = list[0].title || '系统通知';
  746. }
  747. // 更新总未读数
  748. const allUnreadCount = this.conversations.reduce((total, conv) => total + conv.unreadCount, 0);
  749. this.totalUnread = allUnreadCount + this.systemUnread;
  750. // 同步到Vuex
  751. this.$store.dispatch('updateTotalUnread', this.totalUnread);
  752. } catch (e) {
  753. console.log('加载系统未读失败', e);
  754. }
  755. },
  756. openSystemMessages() {
  757. uni.navigateTo({ url: '/pages/message/system' });
  758. },
  759. /**
  760. * 刷新会话列表
  761. */
  762. refreshConversations() {
  763. if (this.timInitialized) {
  764. // 先刷新系统消息未读
  765. this.loadSystemUnread();
  766. // 再刷新会话列表
  767. this.loadConversations();
  768. }
  769. },
  770. /**
  771. * 打开聊天页面
  772. */
  773. openChat(conversation) {
  774. uni.navigateTo({
  775. url: `/pages/message/chat?targetUserId=${conversation.targetUserId}&targetUserName=${conversation.targetUserName}&targetUserAvatar=${conversation.targetUserAvatar || ''}`
  776. });
  777. },
  778. /**
  779. * 显示操作菜单
  780. */
  781. showActionMenu(conversation) {
  782. this.selectedConversation = conversation;
  783. this.$refs.actionMenu.open();
  784. },
  785. /**
  786. * 关闭操作菜单
  787. */
  788. closeActionMenu() {
  789. this.$refs.actionMenu.close();
  790. this.selectedConversation = null;
  791. },
  792. /**
  793. * 标记为已读
  794. */
  795. async markAsRead() {
  796. if (!this.selectedConversation) {
  797. return;
  798. }
  799. try {
  800. // 调用 TIM SDK 标记已读
  801. await timManager.setMessageRead(this.selectedConversation.id);
  802. // 更新本地显示
  803. this.selectedConversation.unreadCount = 0;
  804. // 重新计算总未读数(包含所有会话+系统消息)
  805. const allUnreadCount = this.conversations.reduce((total, conv) => total + conv.unreadCount, 0);
  806. this.totalUnread = allUnreadCount + this.systemUnread;
  807. // 同步到Vuex
  808. this.$store.dispatch('updateTotalUnread', this.totalUnread);
  809. uni.showToast({
  810. title: '已标记为已读',
  811. icon: 'success'
  812. });
  813. } catch (e) {
  814. console.error('标记已读失败', e);
  815. }
  816. this.closeActionMenu();
  817. },
  818. /**
  819. * 删除会话
  820. */
  821. async deleteCurrentConversation() {
  822. if (!this.selectedConversation) {
  823. return;
  824. }
  825. uni.showModal({
  826. title: '确认删除',
  827. content: '确定要删除该会话吗?',
  828. success: async (res) => {
  829. if (res.confirm) {
  830. try {
  831. // 调用 TIM SDK 删除会话
  832. await timManager.tim.deleteConversation(this.selectedConversation.id);
  833. // 从列表中移除
  834. const index = this.conversations.findIndex(c => c.id === this.selectedConversation.id);
  835. if (index > -1) {
  836. this.conversations.splice(index, 1);
  837. }
  838. // 重新计算总未读数(包含所有会话+系统消息)
  839. const allUnreadCount = this.conversations.reduce((total, conv) => total + conv.unreadCount, 0);
  840. this.totalUnread = allUnreadCount + this.systemUnread;
  841. // 同步到Vuex
  842. this.$store.dispatch('updateTotalUnread', this.totalUnread);
  843. uni.showToast({
  844. title: '删除成功',
  845. icon: 'success'
  846. });
  847. } catch (e) {
  848. console.error('删除会话失败', e);
  849. uni.showToast({
  850. title: '删除失败',
  851. icon: 'none'
  852. });
  853. }
  854. }
  855. }
  856. });
  857. this.closeActionMenu();
  858. },
  859. /**
  860. * 搜索(实时过滤在computed中实现)
  861. */
  862. onSearch() {
  863. console.log('搜索:', this.searchKeyword);
  864. // filteredConversations computed属性会自动过滤
  865. },
  866. /**
  867. * 取消搜索
  868. */
  869. cancelSearch() {
  870. this.showSearchPanel = false;
  871. this.searchKeyword = '';
  872. },
  873. /**
  874. * 处理滑动
  875. */
  876. handleSwipe(e, conv) {
  877. if (e.detail.x < -50) {
  878. this.swipingConvId = conv.id;
  879. } else if (e.detail.x > -10) {
  880. this.swipingConvId = null;
  881. }
  882. },
  883. /**
  884. * 滑动结束
  885. */
  886. handleSwipeEnd(conv) {
  887. // 如果滑动距离不够,自动回弹
  888. setTimeout(() => {
  889. if (this.swipingConvId === conv.id) {
  890. // 保持显示操作按钮
  891. }
  892. }, 100);
  893. },
  894. /**
  895. * 切换置顶状态
  896. */
  897. togglePin(conv) {
  898. conv.isPinned = conv.isPinned ? 0 : 1;
  899. // 保存到本地存储
  900. this.savePinnedConversations();
  901. // 重置滑动状态
  902. this.swipingConvId = null;
  903. uni.showToast({
  904. title: conv.isPinned ? '已置顶' : '已取消置顶',
  905. icon: 'success'
  906. });
  907. },
  908. /**
  909. * 加载置顶会话列表
  910. */
  911. loadPinnedConversations() {
  912. try {
  913. const pinned = uni.getStorageSync('pinnedConversations_' + this.userId);
  914. if (pinned) {
  915. this.pinnedConversations = JSON.parse(pinned);
  916. }
  917. } catch (e) {
  918. console.error('加载置顶列表失败:', e);
  919. }
  920. },
  921. /**
  922. * 保存置顶会话列表
  923. */
  924. savePinnedConversations() {
  925. try {
  926. const pinnedIds = this.conversations
  927. .filter(conv => conv.isPinned)
  928. .map(conv => conv.id);
  929. uni.setStorageSync('pinnedConversations_' + this.userId, JSON.stringify(pinnedIds));
  930. } catch (e) {
  931. console.error('保存置顶列表失败:', e);
  932. }
  933. },
  934. /**
  935. * 确认删除会话
  936. */
  937. confirmDeleteConversation(conv) {
  938. uni.showModal({
  939. title: '确认删除',
  940. content: '确定要删除该会话吗?',
  941. success: (res) => {
  942. if (res.confirm) {
  943. this.deleteConversationItem(conv);
  944. }
  945. }
  946. });
  947. // 重置滑动状态
  948. this.swipingConvId = null;
  949. },
  950. /**
  951. * 删除会话
  952. */
  953. async deleteConversationItem(conv) {
  954. try {
  955. // 调用 TIM SDK 删除会话
  956. await timManager.tim.deleteConversation(conv.id);
  957. // 从列表中移除
  958. const index = this.conversations.findIndex(c => c.id === conv.id);
  959. if (index > -1) {
  960. this.conversations.splice(index, 1);
  961. }
  962. // 重新计算总未读数(包含所有会话+系统消息)
  963. const allUnreadCount = this.conversations.reduce((total, c) => total + c.unreadCount, 0);
  964. this.totalUnread = allUnreadCount + this.systemUnread;
  965. // 同步到Vuex
  966. this.$store.dispatch('updateTotalUnread', this.totalUnread);
  967. uni.showToast({
  968. title: '删除成功',
  969. icon: 'success'
  970. });
  971. } catch (e) {
  972. console.error('删除会话失败', e);
  973. uni.showToast({
  974. title: '删除失败',
  975. icon: 'none'
  976. });
  977. }
  978. },
  979. /**
  980. * 格式化最后一条消息
  981. */
  982. formatLastMessage(conv) {
  983. if (!conv.lastMessage) {
  984. return '暂无消息';
  985. }
  986. // 限制长度
  987. const maxLen = 30;
  988. if (conv.lastMessage.length > maxLen) {
  989. return conv.lastMessage.substring(0, maxLen) + '...';
  990. }
  991. return conv.lastMessage;
  992. },
  993. /**
  994. * 格式化时间
  995. */
  996. formatTime(time) {
  997. if (!time) return '';
  998. const date = new Date(time);
  999. const now = new Date();
  1000. const diff = now - date;
  1001. // 今天
  1002. if (date.toDateString() === now.toDateString()) {
  1003. return date.toLocaleTimeString('zh-CN', {
  1004. hour: '2-digit',
  1005. minute: '2-digit'
  1006. });
  1007. }
  1008. // 昨天
  1009. const yesterday = new Date(now);
  1010. yesterday.setDate(yesterday.getDate() - 1);
  1011. if (date.toDateString() === yesterday.toDateString()) {
  1012. return '昨天';
  1013. }
  1014. // 本周
  1015. if (diff < 7 * 24 * 60 * 60 * 1000) {
  1016. const days = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
  1017. return days[date.getDay()];
  1018. }
  1019. // 更早
  1020. return date.toLocaleDateString('zh-CN', {
  1021. month: '2-digit',
  1022. day: '2-digit'
  1023. });
  1024. },
  1025. /**
  1026. * 切换标签页
  1027. */
  1028. switchTab(tab) {
  1029. if (tab === 'message') return;
  1030. const tabPages = {
  1031. index: '/pages/index/index',
  1032. plaza: '/pages/plaza/index',
  1033. recommend: '/pages/recommend/index',
  1034. mine: '/pages/mine/index'
  1035. };
  1036. if (tabPages[tab]) {
  1037. uni.redirectTo({
  1038. url: tabPages[tab]
  1039. });
  1040. }
  1041. }
  1042. }
  1043. };
  1044. </script>
  1045. <style lang="scss" scoped>
  1046. .message-page {
  1047. min-height: 100vh;
  1048. background-color: #F5F5F5;
  1049. padding-bottom: 120rpx;
  1050. }
  1051. /* 顶部标题栏 */
  1052. .header {
  1053. display: flex;
  1054. align-items: center;
  1055. justify-content: space-between;
  1056. padding: 30rpx;
  1057. background-color: #FFFFFF;
  1058. border-bottom: 1rpx solid #F0F0F0;
  1059. .header-title {
  1060. font-size: 40rpx;
  1061. font-weight: bold;
  1062. color: #E91E63;
  1063. }
  1064. .header-actions {
  1065. display: flex;
  1066. gap: 30rpx;
  1067. .action-icon {
  1068. font-size: 40rpx;
  1069. cursor: pointer;
  1070. }
  1071. }
  1072. }
  1073. /* 搜索面板 */
  1074. .search-panel {
  1075. background-color: #FFFFFF;
  1076. padding: 20rpx 30rpx;
  1077. border-bottom: 1rpx solid #F0F0F0;
  1078. .search-bar {
  1079. display: flex;
  1080. align-items: center;
  1081. gap: 20rpx;
  1082. .search-input {
  1083. flex: 1;
  1084. height: 70rpx;
  1085. padding: 0 20rpx;
  1086. background-color: #F5F5F5;
  1087. border-radius: 35rpx;
  1088. font-size: 28rpx;
  1089. }
  1090. .search-cancel {
  1091. font-size: 28rpx;
  1092. color: #E91E63;
  1093. }
  1094. }
  1095. }
  1096. /* 会话列表 */
  1097. .conversation-list {
  1098. height: calc(100vh - 200rpx);
  1099. background-color: #FFFFFF;
  1100. }
  1101. /* 骨架屏 */
  1102. .skeleton-container {
  1103. padding: 20rpx 0;
  1104. }
  1105. .skeleton-item {
  1106. display: flex;
  1107. align-items: center;
  1108. padding: 25rpx 30rpx;
  1109. background-color: #FFFFFF;
  1110. border-bottom: 1rpx solid #F5F5F5;
  1111. .skeleton-avatar {
  1112. width: 100rpx;
  1113. height: 100rpx;
  1114. border-radius: 12rpx;
  1115. background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  1116. background-size: 200% 100%;
  1117. animation: skeleton-loading 1.5s ease-in-out infinite;
  1118. margin-right: 25rpx;
  1119. }
  1120. .skeleton-content {
  1121. flex: 1;
  1122. .skeleton-line {
  1123. height: 30rpx;
  1124. border-radius: 6rpx;
  1125. background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  1126. background-size: 200% 100%;
  1127. animation: skeleton-loading 1.5s ease-in-out infinite;
  1128. &.skeleton-line-title {
  1129. width: 40%;
  1130. margin-bottom: 20rpx;
  1131. }
  1132. &.skeleton-line-text {
  1133. width: 60%;
  1134. }
  1135. }
  1136. }
  1137. }
  1138. @keyframes skeleton-loading {
  1139. 0% {
  1140. background-position: 200% 0;
  1141. }
  1142. 100% {
  1143. background-position: -200% 0;
  1144. }
  1145. }
  1146. /* 空状态 */
  1147. .empty-container {
  1148. display: flex;
  1149. flex-direction: column;
  1150. align-items: center;
  1151. justify-content: center;
  1152. padding: 150rpx 60rpx;
  1153. .empty-icon-wrapper {
  1154. width: 200rpx;
  1155. height: 200rpx;
  1156. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  1157. border-radius: 50%;
  1158. display: flex;
  1159. align-items: center;
  1160. justify-content: center;
  1161. margin-bottom: 40rpx;
  1162. box-shadow: 0 20rpx 60rpx rgba(102, 126, 234, 0.3);
  1163. animation: float 3s ease-in-out infinite;
  1164. }
  1165. .empty-icon {
  1166. font-size: 100rpx;
  1167. filter: brightness(1.2);
  1168. }
  1169. .empty-text {
  1170. font-size: 36rpx;
  1171. font-weight: 600;
  1172. color: #333333;
  1173. margin-bottom: 15rpx;
  1174. }
  1175. .empty-hint {
  1176. font-size: 28rpx;
  1177. color: #999999;
  1178. margin-bottom: 40rpx;
  1179. }
  1180. .empty-action {
  1181. margin-top: 20rpx;
  1182. .empty-btn {
  1183. padding: 20rpx 60rpx;
  1184. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  1185. color: #FFFFFF;
  1186. border-radius: 50rpx;
  1187. font-size: 28rpx;
  1188. border: none;
  1189. box-shadow: 0 10rpx 30rpx rgba(102, 126, 234, 0.3);
  1190. &::after {
  1191. border: none;
  1192. }
  1193. }
  1194. }
  1195. }
  1196. @keyframes float {
  1197. 0%, 100% {
  1198. transform: translateY(0);
  1199. }
  1200. 50% {
  1201. transform: translateY(-20rpx);
  1202. }
  1203. }
  1204. /* 会话列表项包装器 */
  1205. .conversation-item-wrapper {
  1206. position: relative;
  1207. background-color: #FFFFFF;
  1208. border-bottom: 1rpx solid #F5F5F5;
  1209. overflow: hidden;
  1210. }
  1211. /* 系统消息高亮样式 */
  1212. .system-highlight { background: #fff7f7; }
  1213. .system-icon { font-size: 44rpx; color: #E91E63; }
  1214. .system-title { color: #E91E63; font-weight: 600; }
  1215. .system-preview { color: #d25d6b; }
  1216. .system-tag { font-size: 22rpx; color: #fff; background-color: #E91E63; padding: 4rpx 10rpx; border-radius: 8rpx; }
  1217. /* 滑动区域 */
  1218. .movable-area {
  1219. width: 100%;
  1220. height: 160rpx;
  1221. position: relative;
  1222. }
  1223. .movable-view {
  1224. width: 100%;
  1225. height: 100%;
  1226. background-color: #FFFFFF;
  1227. }
  1228. /* 会话列表项 */
  1229. .conversation-item {
  1230. display: flex;
  1231. align-items: center;
  1232. padding: 25rpx 30rpx;
  1233. background-color: #FFFFFF;
  1234. position: relative;
  1235. width: 100%;
  1236. height: 100%;
  1237. &:active {
  1238. background-color: #F8F8F8;
  1239. }
  1240. /* 置顶标记 */
  1241. .pinned-badge {
  1242. position: absolute;
  1243. top: 10rpx;
  1244. left: 10rpx;
  1245. font-size: 28rpx;
  1246. opacity: 0.7;
  1247. }
  1248. .avatar-wrapper {
  1249. position: relative;
  1250. margin-right: 25rpx;
  1251. .avatar {
  1252. width: 100rpx;
  1253. height: 100rpx;
  1254. border-radius: 12rpx;
  1255. }
  1256. .online-badge {
  1257. position: absolute;
  1258. bottom: 0;
  1259. right: 0;
  1260. width: 24rpx;
  1261. height: 24rpx;
  1262. background-color: #07C160;
  1263. border: 3rpx solid #FFFFFF;
  1264. border-radius: 50%;
  1265. }
  1266. .unread-badge {
  1267. position: absolute;
  1268. top: -10rpx;
  1269. right: -10rpx;
  1270. min-width: 36rpx;
  1271. height: 36rpx;
  1272. line-height: 36rpx;
  1273. padding: 0 8rpx;
  1274. background-color: #FA5151;
  1275. border-radius: 18rpx;
  1276. font-size: 20rpx;
  1277. color: #FFFFFF;
  1278. text-align: center;
  1279. }
  1280. }
  1281. .conversation-content {
  1282. flex: 1;
  1283. .content-top {
  1284. display: flex;
  1285. align-items: center;
  1286. justify-content: space-between;
  1287. margin-bottom: 12rpx;
  1288. .user-name {
  1289. font-size: 32rpx;
  1290. font-weight: 500;
  1291. color: #333333;
  1292. }
  1293. .last-time {
  1294. font-size: 24rpx;
  1295. color: #999999;
  1296. }
  1297. }
  1298. .content-bottom {
  1299. display: flex;
  1300. align-items: center;
  1301. gap: 10rpx;
  1302. .last-message {
  1303. flex: 1;
  1304. font-size: 28rpx;
  1305. color: #999999;
  1306. overflow: hidden;
  1307. text-overflow: ellipsis;
  1308. white-space: nowrap;
  1309. &.unread {
  1310. color: #666666;
  1311. font-weight: 500;
  1312. }
  1313. }
  1314. .message-type-icon {
  1315. font-size: 28rpx;
  1316. }
  1317. }
  1318. }
  1319. /* 右滑操作按钮 */
  1320. .conversation-actions {
  1321. position: absolute;
  1322. right: 0;
  1323. top: 0;
  1324. height: 100%;
  1325. display: flex;
  1326. z-index: 1;
  1327. .action-btn {
  1328. width: 150rpx;
  1329. height: 100%;
  1330. display: flex;
  1331. align-items: center;
  1332. justify-content: center;
  1333. color: #FFFFFF;
  1334. font-size: 28rpx;
  1335. }
  1336. .pin-btn {
  1337. background-color: #576B95;
  1338. }
  1339. .delete-btn {
  1340. background-color: #FA5151;
  1341. }
  1342. }
  1343. }
  1344. .load-more {
  1345. padding: 30rpx;
  1346. text-align: center;
  1347. .load-more-text {
  1348. font-size: 26rpx;
  1349. color: #999999;
  1350. }
  1351. }
  1352. /* 底部导航栏 */
  1353. .tabbar {
  1354. position: fixed;
  1355. bottom: 0;
  1356. left: 0;
  1357. right: 0;
  1358. display: flex;
  1359. background-color: #FFFFFF;
  1360. border-top: 1rpx solid #F0F0F0;
  1361. padding-bottom: constant(safe-area-inset-bottom);
  1362. padding-bottom: env(safe-area-inset-bottom);
  1363. z-index: 999;
  1364. .tabbar-item {
  1365. flex: 1;
  1366. display: flex;
  1367. flex-direction: column;
  1368. align-items: center;
  1369. justify-content: center;
  1370. padding: 15rpx 0;
  1371. position: relative;
  1372. .tabbar-icon {
  1373. font-size: 44rpx;
  1374. margin-bottom: 5rpx;
  1375. }
  1376. .tabbar-text {
  1377. font-size: 22rpx;
  1378. color: #666666;
  1379. }
  1380. .tab-badge {
  1381. position: absolute;
  1382. top: 8rpx;
  1383. right: 50%;
  1384. margin-right: -40rpx;
  1385. min-width: 32rpx;
  1386. height: 32rpx;
  1387. line-height: 32rpx;
  1388. padding: 0 6rpx;
  1389. background-color: #FA5151;
  1390. border-radius: 16rpx;
  1391. font-size: 20rpx;
  1392. color: #FFFFFF;
  1393. text-align: center;
  1394. }
  1395. &.active {
  1396. .tabbar-text {
  1397. color: #E91E63;
  1398. font-weight: bold;
  1399. }
  1400. }
  1401. }
  1402. }
  1403. /* 操作菜单 */
  1404. .action-menu {
  1405. background-color: #FFFFFF;
  1406. border-radius: 20rpx 20rpx 0 0;
  1407. .menu-item {
  1408. padding: 30rpx;
  1409. text-align: center;
  1410. font-size: 32rpx;
  1411. color: #333333;
  1412. border-bottom: 1rpx solid #F0F0F0;
  1413. &:active {
  1414. background-color: #F8F8F8;
  1415. }
  1416. &.cancel {
  1417. color: #999999;
  1418. border: none;
  1419. margin-top: 20rpx;
  1420. }
  1421. }
  1422. }
  1423. </style>