index.vue 41 KB

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