chat.vue 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646
  1. <template>
  2. <view class="chat-page">
  3. <!-- 更多选项弹窗 -->
  4. <view v-if="showMoreOptionsModal" class="modal-mask" @click="closeMoreOptions">
  5. <view class="modal-content" @click.stop>
  6. <view class="modal-header">
  7. <text class="modal-title">{{ targetUserName }}</text>
  8. <text class="modal-subtitle">好友操作</text>
  9. </view>
  10. <view class="modal-body">
  11. <!-- <view class="modal-item" @click="goToUserProfile">
  12. <text class="item-icon">👤</text>
  13. <text class="item-text">查看资料</text>
  14. </view> -->
  15. <view class="modal-item" @click="blockFriend" :class="{ danger: true }">
  16. <text class="item-icon">🚫</text>
  17. <text class="item-text">拉黑好友</text>
  18. </view>
  19. <!-- <view class="modal-item" @click="reportUser" :class="{ danger: true }">
  20. <text class="item-icon">🚨</text>
  21. <text class="item-text">举报用户</text>
  22. </view> -->
  23. </view>
  24. <view class="modal-footer">
  25. <button class="modal-close-btn" @click="closeMoreOptions">取消</button>
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 拉黑确认弹窗 -->
  30. <view v-if="showBlockConfirmModal" class="modal-mask" @click="closeBlockConfirm">
  31. <view class="confirm-modal" @click.stop>
  32. <view class="confirm-title">确认拉黑</view>
  33. <view class="confirm-content">
  34. <text>拉黑后将无法接收该用户的消息,是否确定?</text>
  35. </view>
  36. <view class="confirm-buttons">
  37. <button class="confirm-btn cancel" @click="closeBlockConfirm">取消</button>
  38. <button class="confirm-btn confirm" @click="confirmBlockFriend">确认</button>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 顶部导航 -->
  43. <view class="chat-header">
  44. <view class="header-left" @click="goBack">
  45. <text class="icon-back">←</text>
  46. </view>
  47. <view class="header-center">
  48. <text class="chat-title">{{ targetUserName }}</text>
  49. <text class="online-status" :class="{ online: isTargetOnline }">
  50. {{ isTargetOnline ? '在线' : '离线' }}
  51. </text>
  52. </view>
  53. <view class="header-right" @click="showMoreOptions">
  54. <text class="icon-more">⋯</text>
  55. </view>
  56. </view>
  57. <!-- 消息列表 -->
  58. <scroll-view
  59. class="message-list"
  60. scroll-y
  61. :scroll-into-view="scrollToView"
  62. @scrolltoupper="loadMoreMessages">
  63. <!-- 加载更多提示 -->
  64. <view v-if="loading" class="loading-tip">加载中...</view>
  65. <view v-else-if="noMore" class="loading-tip">没有更多消息了</view>
  66. <!-- 时间分组和消息项 -->
  67. <view v-for="(msg, index) in messages" :key="msg.messageId">
  68. <!-- 时间分隔线 (每5分钟显示一次) -->
  69. <view v-if="shouldShowTime(msg, index)" class="time-divider">
  70. <text class="time-text">{{ formatMessageTime(msg.sendTime) }}</text>
  71. </view>
  72. <!-- 消息项 -->
  73. <view
  74. :id="'msg-' + index"
  75. class="message-item"
  76. :class="{ 'message-self': msg.fromUserId === userId }"
  77. @longpress="showMessageMenu(msg, index)">
  78. <!-- 头像 -->
  79. <image
  80. class="avatar"
  81. :src="msg.fromUserId === userId ? userAvatar : targetUserAvatar"
  82. mode="aspectFill" />
  83. <!-- 消息内容 -->
  84. <view class="message-content-wrapper">
  85. <!-- 用户名(对方消息时显示) -->
  86. <text v-if="msg.fromUserId !== userId" class="message-name">
  87. {{ msg.fromUserName }}
  88. </text>
  89. <!-- 消息气泡 -->
  90. <view
  91. class="message-bubble"
  92. :class="{ 'bubble-self': msg.fromUserId === userId, 'bubble-failed': msg.sendStatus === 4 }"
  93. @click="handleMessageClick(msg)">
  94. <!-- 文本消息 -->
  95. <text v-if="msg.messageType === 1" class="message-text">
  96. {{ msg.content }}
  97. </text>
  98. <!-- 图片消息 -->
  99. <image
  100. v-else-if="msg.messageType === 2"
  101. class="message-image"
  102. :src="msg.mediaUrl"
  103. mode="widthFix"
  104. lazy-load
  105. @click.stop="previewImage(msg.mediaUrl)" />
  106. <!-- 语音消息 -->
  107. <view v-else-if="msg.messageType === 3" class="message-voice" @click.stop="playVoice(msg)">
  108. <text>🔊</text>
  109. <text>{{ msg.duration }}"</text>
  110. </view>
  111. <!-- 视频消息 -->
  112. <video
  113. v-else-if="msg.messageType === 4"
  114. class="message-video"
  115. :src="msg.mediaUrl"
  116. controls />
  117. <!-- 撤回消息 -->
  118. <text v-if="msg.isRecalled" class="message-recalled">
  119. 消息已撤回
  120. </text>
  121. </view>
  122. <!-- 消息状态(自己的消息) -->
  123. <view v-if="msg.fromUserId === userId" class="message-status">
  124. <text v-if="msg.sendStatus === 1" class="sending">发送中...</text>
  125. <text v-else-if="msg.sendStatus === 2">已送达</text>
  126. <text v-else-if="msg.sendStatus === 3" class="read">已读</text>
  127. <view v-else-if="msg.sendStatus === 4" class="failed-group">
  128. <text class="failed">发送失败</text>
  129. <text class="retry-btn" @click.stop="retryMessage(msg)">重试</text>
  130. </view>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. </scroll-view>
  136. <!-- 输入框 -->
  137. <view class="input-bar">
  138. <!-- 语音按钮 -->
  139. <view class="input-icon" @click="switchInputType">
  140. <text>{{ inputType === 'text' ? '🎤' : '⌨️' }}</text>
  141. </view>
  142. <!-- 文本输入 -->
  143. <input
  144. v-if="inputType === 'text'"
  145. class="input-field"
  146. v-model="inputText"
  147. placeholder="说点什么..."
  148. confirm-type="send"
  149. @confirm="sendTextMessage"
  150. @input="onInputChange" />
  151. <!-- 语音按钮 -->
  152. <button
  153. v-else
  154. class="voice-button"
  155. @touchstart="startVoiceRecord"
  156. @touchend="stopVoiceRecord">
  157. 按住说话
  158. </button>
  159. <!-- 表情按钮 -->
  160. <view class="input-icon" @click="showEmojiPanel = !showEmojiPanel">
  161. <text>😊</text>
  162. </view>
  163. <!-- 更多按钮 -->
  164. <view class="input-icon" @click="showMorePanel = !showMorePanel">
  165. <text>➕</text>
  166. </view>
  167. </view>
  168. <!-- 表情面板 -->
  169. <view v-if="showEmojiPanel" class="emoji-panel">
  170. <text
  171. v-for="emoji in emojis"
  172. :key="emoji"
  173. class="emoji-item"
  174. @click="insertEmoji(emoji)">
  175. {{ emoji }}
  176. </text>
  177. </view>
  178. <!-- 更多功能面板 -->
  179. <view v-if="showMorePanel" class="more-panel">
  180. <view class="more-item" @click="chooseImage">
  181. <view class="more-icon">🖼️</view>
  182. <text class="more-text">图片</text>
  183. </view>
  184. <view class="more-item" @click="chooseVideo">
  185. <view class="more-icon">📹</view>
  186. <text class="more-text">视频</text>
  187. </view>
  188. <view class="more-item" @click="chooseFile">
  189. <view class="more-icon">📁</view>
  190. <text class="more-text">文件</text>
  191. </view>
  192. </view>
  193. <!-- 消息操作菜单 -->
  194. <view v-if="showMessageAction" class="message-action-mask" @click="hideMessageMenu">
  195. <view class="message-action-menu" @click.stop>
  196. <view class="menu-item" @click="copyMessage" v-if="selectedMessage && selectedMessage.messageType === 1">
  197. <text class="menu-icon">📋</text>
  198. <text>复制</text>
  199. </view>
  200. <view class="menu-item" @click="recallMessage" v-if="selectedMessage && selectedMessage.fromUserId === userId && canRecall(selectedMessage)">
  201. <text class="menu-icon">↩️</text>
  202. <text>撤回</text>
  203. </view>
  204. <view class="menu-item" @click="deleteMessage">
  205. <text class="menu-icon">🗑️</text>
  206. <text>删除</text>
  207. </view>
  208. <view class="menu-item cancel" @click="hideMessageMenu">
  209. <text>取消</text>
  210. </view>
  211. </view>
  212. </view>
  213. </view>
  214. </template>
  215. <script>
  216. import timManager from '@/utils/tim-manager.js';
  217. import TIM from 'tim-wx-sdk';
  218. export default {
  219. data() {
  220. return {
  221. userId: null,
  222. userAvatar: '',
  223. targetUserId: null,
  224. targetUserName: '',
  225. targetUserAvatar: '',
  226. messages: [],
  227. inputText: '',
  228. inputType: 'text',
  229. conversationID: '',
  230. scrollToView: '',
  231. showEmojiPanel: false,
  232. showMorePanel: false,
  233. isLogin: false,
  234. // 消息操作菜单
  235. showMessageAction: false,
  236. selectedMessage: null,
  237. selectedMessageIndex: -1,
  238. menuTop: 0,
  239. // 加载更多
  240. loading: false,
  241. noMore: false,
  242. nextReqMessageID: '',
  243. isTargetOnline: false,
  244. emojis: ['😀', '😃', '😄', '😁', '😆', '😅', '😂', '🤣', '😊', '😇', '🙂', '🙃', '😉', '😌', '😍', '🥰', '😘', '😗', '😙', '😚', '😋', '😛', '😝', '😜', '🤪', '🤨', '🧐', '🤓', '😎', '🤩', '🥳'],
  245. showMoreOptionsModal: false, // 控制更多选项弹窗显示
  246. showBlockConfirmModal: false // 控制拉黑确认弹窗显示
  247. };
  248. },
  249. async onLoad(options) {
  250. console.log('=== 聊天页面加载 ===');
  251. // 严格验证登录状态
  252. const token = uni.getStorageSync('token');
  253. const userInfo = uni.getStorageSync('userInfo');
  254. const storedUserId = uni.getStorageSync('userId');
  255. console.log('登录状态检查:');
  256. console.log('- token:', token ? '存在' : '不存在');
  257. console.log('- userInfo:', userInfo);
  258. console.log('- storedUserId:', storedUserId);
  259. if (!token || !userInfo) {
  260. console.error('❌ 未登录或登录信息不完整');
  261. uni.showModal({
  262. title: '需要登录',
  263. content: '请先登录后再进行聊天',
  264. showCancel: false,
  265. success: () => {
  266. uni.reLaunch({
  267. url: '/pages/page3/page3'
  268. });
  269. }
  270. });
  271. return;
  272. }
  273. // 优先使用 storage 中的 userId,确保一致性
  274. let rawUserId = storedUserId || userInfo.userId || userInfo.id || userInfo.user_id;
  275. // 转换为数字类型(确保与消息列表页面一致)
  276. if (typeof rawUserId === 'string') {
  277. rawUserId = parseInt(rawUserId);
  278. }
  279. if (!rawUserId || isNaN(rawUserId)) {
  280. console.error('❌ 无法获取有效的用户ID');
  281. uni.showModal({
  282. title: '用户信息错误',
  283. content: '无法获取用户ID,请重新登录',
  284. showCancel: false,
  285. success: () => {
  286. uni.removeStorageSync('token');
  287. uni.removeStorageSync('userInfo');
  288. uni.removeStorageSync('userId');
  289. uni.reLaunch({
  290. url: '/pages/page3/page3'
  291. });
  292. }
  293. });
  294. return;
  295. }
  296. // 保存用户ID(TIM需要字符串格式)
  297. this.userId = String(rawUserId);
  298. this.userAvatar = userInfo.avatar || userInfo.avatarUrl || '/static/default-avatar.svg';
  299. // 获取对方用户信息(确保是字符串格式)
  300. this.targetUserId = String(options.targetUserId);
  301. this.targetUserName = decodeURIComponent(options.targetUserName || '用户');
  302. this.targetUserAvatar = decodeURIComponent(options.targetUserAvatar || '/static/default-avatar.svg');
  303. // 生成会话 ID
  304. this.conversationID = `C2C${this.targetUserId}`;
  305. console.log('✅ 聊天页面初始化成功:');
  306. console.log(' - 当前用户ID:', rawUserId, '(TIM格式:', this.userId, ')');
  307. console.log(' - 对方用户ID:', this.targetUserId);
  308. console.log(' - 会话ID:', this.conversationID);
  309. // 初始化 TIM
  310. await this.initTIM();
  311. // 等待 SDK Ready 后再加载消息
  312. await this.waitForSDKReady();
  313. // 加载历史消息
  314. await this.loadMessages();
  315. // 监听新消息
  316. this.listenMessages();
  317. },
  318. onUnload() {
  319. // 页面卸载时移除监听
  320. timManager.offMessage(this.handleNewMessage);
  321. },
  322. methods: {
  323. /**
  324. * 初始化 TIM
  325. */
  326. async initTIM() {
  327. try {
  328. // 如果未初始化,先初始化
  329. if (!timManager.tim) {
  330. timManager.init(1600109674); // ✅ 已更新为正确的 SDKAppID
  331. }
  332. // 如果未登录,获取 userSig 并登录
  333. if (!timManager.isLogin) {
  334. // 先导入当前用户和目标用户到腾讯云IM
  335. await this.importUsers();
  336. // 从后端获取 userSig
  337. const userSig = await this.getUserSig();
  338. await timManager.login(this.userId, userSig);
  339. }
  340. this.isLogin = true;
  341. console.log('✅ TIM 初始化完成');
  342. } catch (error) {
  343. console.error('❌ TIM 初始化失败:', error);
  344. uni.showToast({
  345. title: '连接失败,请重试',
  346. icon: 'none'
  347. });
  348. }
  349. },
  350. more(userid) {
  351. console.log('点击了更多按钮,开始跳转...', userid);
  352. // 如果目标页面是普通页面,用navigateTo(保留当前页面);如果是tabbar页面,用switchTab
  353. uni.navigateTo({
  354. url: `/pages/message/more?userid=${userid}`,
  355. success: () => {
  356. console.log('跳转成功');
  357. },
  358. fail: (err) => {
  359. console.error('跳转失败:', err);
  360. uni.showToast({
  361. title: '页面不存在或路径错误',
  362. icon: 'none'
  363. });
  364. }
  365. });
  366. },
  367. /**
  368. * 导入用户到腾讯云IM
  369. */
  370. async importUsers() {
  371. try {
  372. console.log('📥 开始导入用户到腾讯云IM...');
  373. console.log(' - 当前用户ID:', this.userId, '(类型:', typeof this.userId, ')');
  374. console.log(' - 目标用户ID:', this.targetUserId, '(类型:', typeof this.targetUserId, ')');
  375. // 验证用户ID
  376. if (!this.userId || this.userId === 'undefined' || this.userId === 'null') {
  377. throw new Error('当前用户ID无效: ' + this.userId);
  378. }
  379. if (!this.targetUserId || this.targetUserId === 'undefined' || this.targetUserId === 'null') {
  380. throw new Error('目标用户ID无效: ' + this.targetUserId);
  381. }
  382. // 导入当前用户(确保userId是字符串)
  383. const currentUserRes = await uni.request({
  384. url: 'http://localhost:1004/api/im/importUser',
  385. method: 'POST',
  386. data: {
  387. userId: String(this.userId),
  388. nickname: '用户' + this.userId
  389. },
  390. header: {
  391. 'Content-Type': 'application/json'
  392. }
  393. });
  394. console.log(' - 当前用户导入结果:', currentUserRes[1].data);
  395. // 导入目标用户(确保userId是字符串)
  396. const targetUserRes = await uni.request({
  397. url: 'http://localhost:1004/api/im/importUser',
  398. method: 'POST',
  399. data: {
  400. userId: String(this.targetUserId),
  401. nickname: this.targetUserName || '用户' + this.targetUserId
  402. },
  403. header: {
  404. 'Content-Type': 'application/json'
  405. }
  406. });
  407. console.log(' - 目标用户导入结果:', targetUserRes[1].data);
  408. console.log('✅ 用户导入成功');
  409. } catch (error) {
  410. console.log('⚠️ 用户导入失败(可能已存在):', error);
  411. // 导入失败不影响登录,因为用户可能已经存在
  412. }
  413. },
  414. /**
  415. * 获取 UserSig
  416. */
  417. async getUserSig() {
  418. try {
  419. const [err, res] = await uni.request({
  420. url: 'http://localhost:1004/api/im/getUserSig',
  421. method: 'GET',
  422. data: {
  423. userId: this.userId
  424. }
  425. });
  426. if (err) {
  427. throw new Error('请求失败');
  428. }
  429. if (res.data && res.data.code === 200) {
  430. return res.data.data.userSig;
  431. } else {
  432. throw new Error('获取 UserSig 失败');
  433. }
  434. } catch (error) {
  435. console.error('❌ 获取 UserSig 失败:', error);
  436. throw error;
  437. }
  438. },
  439. /**
  440. * 等待 SDK Ready
  441. */
  442. async waitForSDKReady() {
  443. return new Promise((resolve) => {
  444. // 如果已经 ready,立即返回
  445. if (timManager.isLogin) {
  446. console.log('✅ SDK 已就绪');
  447. resolve();
  448. return;
  449. }
  450. // 否则等待 SDK ready 事件
  451. console.log('⏳ 等待 SDK 就绪...');
  452. const checkReady = setInterval(() => {
  453. if (timManager.isLogin) {
  454. console.log('✅ SDK 已就绪');
  455. clearInterval(checkReady);
  456. resolve();
  457. }
  458. }, 100); // 每 100ms 检查一次
  459. // 超时保护(10秒后强制继续)
  460. setTimeout(() => {
  461. console.log('⚠️ 等待 SDK 就绪超时,继续执行');
  462. clearInterval(checkReady);
  463. resolve();
  464. }, 10000);
  465. });
  466. },
  467. /**
  468. * 加载历史消息
  469. */
  470. async loadMessages() {
  471. try {
  472. const res = await timManager.tim.getMessageList({
  473. conversationID: this.conversationID,
  474. count: 20
  475. });
  476. const messageList = res.data.messageList;
  477. this.nextReqMessageID = res.data.nextReqMessageID;
  478. this.noMore = !res.data.isCompleted;
  479. // 转换为我们的消息格式
  480. this.messages = messageList.map(msg => this.convertMessage(msg));
  481. // 滚动到底部
  482. this.$nextTick(() => {
  483. this.scrollToBottom();
  484. });
  485. // 标记已读
  486. await timManager.setMessageRead(this.conversationID);
  487. } catch (error) {
  488. console.error('❌ 加载消息失败:', error);
  489. }
  490. },
  491. /**
  492. * 加载更多消息(上拉)
  493. */
  494. async loadMoreMessages() {
  495. if (this.loading || !this.nextReqMessageID) {
  496. return;
  497. }
  498. this.loading = true;
  499. try {
  500. const res = await timManager.tim.getMessageList({
  501. conversationID: this.conversationID,
  502. nextReqMessageID: this.nextReqMessageID,
  503. count: 20
  504. });
  505. const messageList = res.data.messageList;
  506. this.nextReqMessageID = res.data.nextReqMessageID;
  507. this.noMore = !res.data.isCompleted;
  508. // 转换并添加到消息列表前面
  509. const newMessages = messageList.map(msg => this.convertMessage(msg));
  510. this.messages = [...newMessages, ...this.messages];
  511. } catch (error) {
  512. console.error('❌ 加载更多消息失败:', error);
  513. } finally {
  514. this.loading = false;
  515. }
  516. },
  517. /**
  518. * 监听新消息
  519. */
  520. listenMessages() {
  521. const handleNewMessage = (messageList) => {
  522. messageList.forEach(msg => {
  523. // 只处理当前会话的消息
  524. if (msg.conversationID === this.conversationID) {
  525. this.messages.push(this.convertMessage(msg));
  526. this.$nextTick(() => {
  527. this.scrollToBottom();
  528. });
  529. // 标记已读
  530. timManager.setMessageRead(this.conversationID);
  531. }
  532. });
  533. };
  534. this.handleNewMessage = handleNewMessage;
  535. timManager.onMessage(handleNewMessage);
  536. },
  537. /**
  538. * 转换消息格式
  539. */
  540. convertMessage(timMsg) {
  541. return {
  542. messageId: timMsg.ID,
  543. fromUserId: timMsg.from,
  544. toUserId: timMsg.to,
  545. messageType: timMsg.type === TIM.TYPES.MSG_TEXT ? 1 : 2,
  546. content: timMsg.type === TIM.TYPES.MSG_TEXT ? timMsg.payload.text : '[图片]',
  547. mediaUrl: timMsg.type === TIM.TYPES.MSG_IMAGE ? timMsg.payload.imageInfoArray[0].url : '',
  548. sendStatus: timMsg.status === 'success' ? 2 : 1,
  549. sendTime: new Date(timMsg.time * 1000),
  550. isRecalled: timMsg.isRevoked,
  551. fromUserName: timMsg.from === this.userId ? '我' : this.targetUserName
  552. };
  553. },
  554. /**
  555. * 发送文本消息
  556. */
  557. async sendTextMessage() {
  558. if (!this.inputText.trim()) {
  559. return;
  560. }
  561. const content = this.inputText;
  562. this.inputText = '';
  563. try {
  564. const message = await timManager.sendTextMessage(this.targetUserId, content);
  565. // 添加到消息列表
  566. this.messages.push(this.convertMessage(message));
  567. this.scrollToBottom();
  568. console.log('✅ 消息发送成功');
  569. // 同步消息到MySQL数据库(双重保障)
  570. this.syncMessageToMySQL(message);
  571. } catch (error) {
  572. console.error('❌ 消息发送失败:', error);
  573. uni.showToast({
  574. title: '发送失败',
  575. icon: 'none'
  576. });
  577. // 失败时恢复输入框内容
  578. this.inputText = content;
  579. }
  580. },
  581. /**
  582. * 选择图片
  583. */
  584. chooseImage() {
  585. uni.chooseImage({
  586. count: 1,
  587. sizeType: ['compressed'],
  588. sourceType: ['album', 'camera'],
  589. success: async (res) => {
  590. const tempFilePath = res.tempFilePaths[0];
  591. try {
  592. uni.showLoading({ title: '发送中...' });
  593. const message = await timManager.sendImageMessage(this.targetUserId, tempFilePath);
  594. this.messages.push(this.convertMessage(message));
  595. this.scrollToBottom();
  596. uni.hideLoading();
  597. console.log('✅ 图片发送成功');
  598. } catch (error) {
  599. uni.hideLoading();
  600. console.error('❌ 图片发送失败:', error);
  601. uni.showToast({
  602. title: '发送失败',
  603. icon: 'none'
  604. });
  605. }
  606. }
  607. });
  608. this.showMorePanel = false;
  609. },
  610. /**
  611. * 输入框内容变化
  612. */
  613. onInputChange() {
  614. // 腾讯云 IM 可以实现正在输入状态,这里暂时省略
  615. console.log('输入中...');
  616. },
  617. /**
  618. * 同步消息到MySQL数据库(双重存储保障)
  619. */
  620. async syncMessageToMySQL(timMessage) {
  621. try {
  622. console.log('🔄 同步消息到MySQL...', timMessage.ID);
  623. // 构建同步参数
  624. const syncData = {
  625. messageId: timMessage.ID,
  626. fromUserId: timMessage.from,
  627. toUserId: timMessage.to,
  628. messageType: this.getMessageType(timMessage),
  629. content: this.getMessageContent(timMessage),
  630. sendTime: timMessage.time // TIM返回的是秒级时间戳
  631. };
  632. // 如果是图片消息,添加媒体信息
  633. if (timMessage.type === 'TIMImageElem' && timMessage.payload.imageInfoArray) {
  634. const imageInfo = timMessage.payload.imageInfoArray[0];
  635. syncData.mediaUrl = imageInfo.imageUrl;
  636. syncData.thumbnailUrl = imageInfo.imageUrl;
  637. }
  638. // 调用后端同步接口
  639. const res = await uni.request({
  640. url: 'http://localhost:1004/api/chat/syncTIMMessage',
  641. method: 'POST',
  642. data: syncData,
  643. header: {
  644. 'Content-Type': 'application/json'
  645. }
  646. });
  647. if (res[1].data.code === 200) {
  648. console.log('✅ 消息已同步到MySQL:', timMessage.ID);
  649. } else {
  650. console.warn('⚠️ 消息同步失败:', res[1].data.message);
  651. }
  652. } catch (error) {
  653. console.error('❌ 同步消息到MySQL失败:', error);
  654. // 同步失败不影响聊天功能,只记录日志
  655. }
  656. },
  657. /**
  658. * 获取消息类型
  659. */
  660. getMessageType(timMessage) {
  661. const typeMap = {
  662. 'TIMTextElem': 1, // 文本
  663. 'TIMImageElem': 2, // 图片
  664. 'TIMSoundElem': 3, // 语音
  665. 'TIMVideoFileElem': 4, // 视频
  666. 'TIMFileElem': 5 // 文件
  667. };
  668. return typeMap[timMessage.type] || 1;
  669. },
  670. /**
  671. * 获取消息内容
  672. */
  673. getMessageContent(timMessage) {
  674. switch (timMessage.type) {
  675. case 'TIMTextElem':
  676. return timMessage.payload.text || '';
  677. case 'TIMImageElem':
  678. return '[图片]';
  679. case 'TIMSoundElem':
  680. return '[语音]';
  681. case 'TIMVideoFileElem':
  682. return '[视频]';
  683. case 'TIMFileElem':
  684. return '[文件]';
  685. default:
  686. return '[未知消息]';
  687. }
  688. },
  689. /**
  690. * 滚动到底部
  691. */
  692. scrollToBottom() {
  693. this.$nextTick(() => {
  694. const lastIndex = this.messages.length - 1;
  695. this.scrollToView = 'msg-' + lastIndex;
  696. });
  697. },
  698. /**
  699. * 判断是否显示时间分隔线
  700. */
  701. shouldShowTime(msg, index) {
  702. if (index === 0) return true;
  703. const prevMsg = this.messages[index - 1];
  704. const timeDiff = new Date(msg.sendTime) - new Date(prevMsg.sendTime);
  705. // 超过5分钟显示时间
  706. return timeDiff > 5 * 60 * 1000;
  707. },
  708. /**
  709. * 格式化消息时间(用于时间分隔线)
  710. */
  711. formatMessageTime(time) {
  712. const date = new Date(time);
  713. const now = new Date();
  714. const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  715. const yesterday = new Date(today - 86400000);
  716. // 今天
  717. if (date >= today) {
  718. return date.toLocaleTimeString('zh-CN', {
  719. hour: '2-digit',
  720. minute: '2-digit'
  721. });
  722. }
  723. // 昨天
  724. if (date >= yesterday) {
  725. return '昨天 ' + date.toLocaleTimeString('zh-CN', {
  726. hour: '2-digit',
  727. minute: '2-digit'
  728. });
  729. }
  730. // 本周
  731. if (date > new Date(now - 7 * 86400000)) {
  732. const days = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
  733. return days[date.getDay()] + ' ' + date.toLocaleTimeString('zh-CN', {
  734. hour: '2-digit',
  735. minute: '2-digit'
  736. });
  737. }
  738. // 更早
  739. return date.toLocaleString('zh-CN', {
  740. month: '2-digit',
  741. day: '2-digit',
  742. hour: '2-digit',
  743. minute: '2-digit'
  744. });
  745. },
  746. /**
  747. * 格式化时间(消息状态用)
  748. */
  749. formatTime(time) {
  750. const date = new Date(time);
  751. const now = new Date();
  752. const diff = now - date;
  753. if (diff < 60000) {
  754. return '刚刚';
  755. } else if (diff < 3600000) {
  756. return Math.floor(diff / 60000) + '分钟前';
  757. } else if (diff < 86400000) {
  758. return Math.floor(diff / 3600000) + '小时前';
  759. } else {
  760. return date.toLocaleString('zh-CN', {
  761. month: '2-digit',
  762. day: '2-digit',
  763. hour: '2-digit',
  764. minute: '2-digit'
  765. });
  766. }
  767. },
  768. /**
  769. * 预览图片
  770. */
  771. previewImage(url) {
  772. uni.previewImage({
  773. urls: [url],
  774. current: url
  775. });
  776. },
  777. /**
  778. * 返回
  779. */
  780. goBack() {
  781. uni.navigateBack({
  782. success: () => {
  783. // 通知消息列表页面刷新
  784. uni.$emit('refreshConversations');
  785. }
  786. });
  787. },
  788. /**
  789. * 显示消息操作菜单
  790. */
  791. showMessageMenu(msg, index) {
  792. this.selectedMessage = msg;
  793. this.selectedMessageIndex = index;
  794. this.showMessageAction = true;
  795. // 计算菜单位置
  796. uni.createSelectorQuery().select('.message-item').boundingClientRect(rect => {
  797. if (rect) {
  798. this.menuTop = rect.top + rect.height;
  799. }
  800. }).exec();
  801. },
  802. /**
  803. * 隐藏消息操作菜单
  804. */
  805. hideMessageMenu() {
  806. this.showMessageAction = false;
  807. this.selectedMessage = null;
  808. this.selectedMessageIndex = -1;
  809. },
  810. /**
  811. * 复制消息
  812. */
  813. copyMessage() {
  814. if (!this.selectedMessage || this.selectedMessage.messageType !== 1) {
  815. return;
  816. }
  817. uni.setClipboardData({
  818. data: this.selectedMessage.content,
  819. success: () => {
  820. uni.showToast({
  821. title: '已复制',
  822. icon: 'success'
  823. });
  824. }
  825. });
  826. this.hideMessageMenu();
  827. },
  828. /**
  829. * 判断是否可以撤回
  830. */
  831. canRecall(msg) {
  832. const diff = Date.now() - new Date(msg.sendTime).getTime();
  833. return diff < 2 * 60 * 1000; // 2分钟内可撤回
  834. },
  835. /**
  836. * 撤回消息
  837. */
  838. async recallMessage() {
  839. if (!this.selectedMessage) {
  840. return;
  841. }
  842. try {
  843. // 查找TIM消息对象
  844. const timMessage = await timManager.tim.findMessage(this.selectedMessage.messageId);
  845. if (timMessage) {
  846. await timManager.revokeMessage(timMessage);
  847. // 更新本地消息状态
  848. this.selectedMessage.isRecalled = true;
  849. this.selectedMessage.content = '你撤回了一条消息';
  850. uni.showToast({
  851. title: '已撤回',
  852. icon: 'success'
  853. });
  854. }
  855. } catch (error) {
  856. console.error('撤回失败:', error);
  857. uni.showToast({
  858. title: '撤回失败',
  859. icon: 'none'
  860. });
  861. }
  862. this.hideMessageMenu();
  863. },
  864. /**
  865. * 删除消息
  866. */
  867. deleteMessage() {
  868. if (!this.selectedMessage) {
  869. return;
  870. }
  871. uni.showModal({
  872. title: '确认删除',
  873. content: '确定要删除这条消息吗?',
  874. success: (res) => {
  875. if (res.confirm) {
  876. // 从列表中删除
  877. this.messages.splice(this.selectedMessageIndex, 1);
  878. uni.showToast({
  879. title: '已删除',
  880. icon: 'success'
  881. });
  882. }
  883. }
  884. });
  885. this.hideMessageMenu();
  886. },
  887. /**
  888. * 处理消息点击
  889. */
  890. handleMessageClick(msg) {
  891. // 如果是发送失败的消息,提示重试
  892. if (msg.sendStatus === 4) {
  893. uni.showModal({
  894. title: '发送失败',
  895. content: '消息发送失败,是否重试?',
  896. success: (res) => {
  897. if (res.confirm) {
  898. this.retryMessage(msg);
  899. }
  900. }
  901. });
  902. }
  903. },
  904. /**
  905. * 重试发送消息
  906. */
  907. async retryMessage(msg) {
  908. if (msg.messageType !== 1) {
  909. uni.showToast({
  910. title: '暂不支持重发该类型消息',
  911. icon: 'none'
  912. });
  913. return;
  914. }
  915. try {
  916. // 更新状态为发送中
  917. msg.sendStatus = 1;
  918. // 重新发送
  919. const message = await timManager.sendTextMessage(this.targetUserId, msg.content);
  920. // 更新消息
  921. const index = this.messages.findIndex(m => m.messageId === msg.messageId);
  922. if (index > -1) {
  923. this.messages[index] = this.convertMessage(message);
  924. }
  925. console.log('✅ 消息重发成功');
  926. } catch (error) {
  927. console.error('❌ 消息重发失败:', error);
  928. msg.sendStatus = 4;
  929. uni.showToast({
  930. title: '发送失败',
  931. icon: 'none'
  932. });
  933. }
  934. },
  935. // 其他功能方法
  936. switchInputType() {
  937. this.inputType = this.inputType === 'text' ? 'voice' : 'text';
  938. },
  939. startVoiceRecord() {
  940. uni.showToast({
  941. title: '按住说话',
  942. icon: 'none'
  943. });
  944. },
  945. stopVoiceRecord() {
  946. uni.showToast({
  947. title: '语音功能开发中',
  948. icon: 'none'
  949. });
  950. },
  951. insertEmoji(emoji) {
  952. this.inputText += emoji;
  953. this.showEmojiPanel = false;
  954. },
  955. chooseVideo() {
  956. uni.showToast({
  957. title: '视频功能开发中',
  958. icon: 'none'
  959. });
  960. this.showMorePanel = false;
  961. },
  962. chooseFile() {
  963. uni.showToast({
  964. title: '文件功能开发中',
  965. icon: 'none'
  966. });
  967. this.showMorePanel = false;
  968. },
  969. playVoice() {
  970. uni.showToast({
  971. title: '语音播放功能开发中',
  972. icon: 'none'
  973. });
  974. },
  975. showMoreOptions() {
  976. this.showMoreOptionsModal = true;
  977. },
  978. closeMoreOptions() {
  979. this.showMoreOptionsModal = false;
  980. },
  981. /**
  982. * 查看用户资料(跳转到原有more页面)
  983. */
  984. goToUserProfile() {
  985. this.closeMoreOptions();
  986. uni.navigateTo({
  987. url: `/pages/message/more?userid=${this.targetUserId}`,
  988. fail: (err) => {
  989. console.error('跳转失败:', err);
  990. uni.showToast({
  991. title: '页面不存在',
  992. icon: 'none'
  993. });
  994. }
  995. });
  996. },
  997. /**
  998. * 显示拉黑确认弹窗
  999. */
  1000. blockFriend() {
  1001. this.closeMoreOptions();
  1002. this.showBlockConfirmModal = true;
  1003. },
  1004. /**
  1005. * 关闭拉黑确认弹窗
  1006. */
  1007. closeBlockConfirm() {
  1008. this.showBlockConfirmModal = false;
  1009. },
  1010. /**
  1011. * 确认拉黑好友
  1012. */
  1013. async confirmBlockFriend() {
  1014. try {
  1015. uni.showLoading({
  1016. title: '处理中...'
  1017. });
  1018. // 调用后端拉黑接口(根据实际接口调整)
  1019. const [err, res] = await uni.request({
  1020. url: 'http://localhost:8083/api/chatfriend/block',
  1021. method: 'POST',
  1022. data: {
  1023. userId: this.userId,
  1024. targetUserId: this.targetUserId,
  1025. targetUserName: this.targetUserName,
  1026. targetUserAvatar: this.targetUserAvatar
  1027. },
  1028. header: {
  1029. 'Content-Type': 'application/json',
  1030. // 'Authorization': 'Bearer ' + uni.getStorageSync('token')
  1031. }
  1032. });
  1033. uni.hideLoading();
  1034. if (err) throw new Error('网络请求失败');
  1035. if (res.data && res.data.code === 200) {
  1036. uni.showToast({ title: '拉黑成功', icon: 'success' });
  1037. this.closeBlockConfirm();
  1038. // 拉黑成功后返回上一页
  1039. setTimeout(() => this.goBack(), 1500);
  1040. } else {
  1041. throw new Error(res.data?.message || '拉黑失败');
  1042. }
  1043. } catch (error) {
  1044. console.error('拉黑失败:', error);
  1045. uni.showToast({ title: error.message || '拉黑失败', icon: 'none' });
  1046. }
  1047. },
  1048. }
  1049. };
  1050. </script>
  1051. <style scoped>
  1052. /* 弹窗遮罩 */
  1053. .modal-mask {
  1054. position: fixed;
  1055. top: 0;
  1056. left: 0;
  1057. right: 0;
  1058. bottom: 0;
  1059. background-color: rgba(0, 0, 0, 0.5);
  1060. z-index: 10000;
  1061. display: flex;
  1062. align-items: center;
  1063. justify-content: center;
  1064. }
  1065. /* 更多选项弹窗内容 */
  1066. .modal-content {
  1067. width: 70%;
  1068. background-color: #fff;
  1069. border-radius: 20rpx;
  1070. overflow: hidden;
  1071. }
  1072. .modal-header {
  1073. padding: 30rpx;
  1074. text-align: center;
  1075. border-bottom: 1px solid #eee;
  1076. }
  1077. .modal-title {
  1078. font-size: 32rpx;
  1079. font-weight: bold;
  1080. display: block;
  1081. }
  1082. .modal-subtitle {
  1083. font-size: 24rpx;
  1084. color: #999;
  1085. display: block;
  1086. margin-top: 10rpx;
  1087. }
  1088. .modal-body {
  1089. padding: 20rpx 0;
  1090. }
  1091. .modal-item {
  1092. display: flex;
  1093. align-items: center;
  1094. padding: 25rpx 40rpx;
  1095. font-size: 30rpx;
  1096. }
  1097. .modal-item.danger {
  1098. color: #fa5151;
  1099. }
  1100. .item-icon {
  1101. font-size: 32rpx;
  1102. margin-right: 20rpx;
  1103. }
  1104. .modal-footer {
  1105. padding: 20rpx;
  1106. border-top: 1px solid #eee;
  1107. }
  1108. .modal-close-btn {
  1109. width: 100%;
  1110. background-color: #f5f5f5;
  1111. border: none;
  1112. border-radius: 10rpx;
  1113. padding: 20rpx;
  1114. font-size: 30rpx;
  1115. }
  1116. /* 确认弹窗样式 */
  1117. .confirm-modal {
  1118. width: 60%;
  1119. background-color: #fff;
  1120. border-radius: 20rpx;
  1121. padding: 40rpx;
  1122. text-align: center;
  1123. }
  1124. .confirm-title {
  1125. font-size: 32rpx;
  1126. font-weight: bold;
  1127. margin-bottom: 30rpx;
  1128. }
  1129. .confirm-content {
  1130. font-size: 28rpx;
  1131. color: #666;
  1132. margin-bottom: 40rpx;
  1133. line-height: 1.5;
  1134. }
  1135. .confirm-buttons {
  1136. display: flex;
  1137. justify-content: space-between;
  1138. }
  1139. .confirm-btn {
  1140. flex: 1;
  1141. margin: 0 10rpx;
  1142. padding: 20rpx;
  1143. border-radius: 10rpx;
  1144. border: none;
  1145. font-size: 28rpx;
  1146. }
  1147. .confirm-btn.cancel {
  1148. background-color: #f5f5f5;
  1149. }
  1150. .confirm-btn.confirm {
  1151. background-color: #fa5151;
  1152. color: #fff;
  1153. }
  1154. .chat-page {
  1155. display: flex;
  1156. flex-direction: column;
  1157. height: 100vh;
  1158. background-color: #f5f5f5;
  1159. }
  1160. /* 顶部导航 */
  1161. .chat-header {
  1162. display: flex;
  1163. align-items: center;
  1164. justify-content: space-between;
  1165. padding: 20rpx 30rpx;
  1166. background-color: #fff;
  1167. border-bottom: 1px solid #e5e5e5;
  1168. }
  1169. .header-left, .header-right {
  1170. width: 80rpx;
  1171. }
  1172. .icon-back, .icon-more {
  1173. font-size: 40rpx;
  1174. }
  1175. .header-center {
  1176. flex: 1;
  1177. text-align: center;
  1178. }
  1179. .chat-title {
  1180. display: block;
  1181. font-size: 36rpx;
  1182. font-weight: bold;
  1183. }
  1184. .online-status {
  1185. display: block;
  1186. font-size: 24rpx;
  1187. color: #999;
  1188. margin-top: 5rpx;
  1189. }
  1190. .online-status.online {
  1191. color: #07c160;
  1192. }
  1193. /* 消息列表 */
  1194. .message-list {
  1195. flex: 1;
  1196. padding: 20rpx;
  1197. overflow-y: scroll;
  1198. }
  1199. .loading-tip {
  1200. text-align: center;
  1201. padding: 20rpx;
  1202. color: #999;
  1203. font-size: 28rpx;
  1204. }
  1205. .message-item {
  1206. display: flex;
  1207. margin-bottom: 30rpx;
  1208. }
  1209. .message-item.message-self {
  1210. flex-direction: row-reverse;
  1211. }
  1212. .avatar {
  1213. width: 80rpx;
  1214. height: 80rpx;
  1215. border-radius: 8rpx;
  1216. margin: 0 20rpx;
  1217. }
  1218. .message-content-wrapper {
  1219. max-width: 70%;
  1220. }
  1221. .message-name {
  1222. display: block;
  1223. font-size: 24rpx;
  1224. color: #999;
  1225. margin-bottom: 10rpx;
  1226. }
  1227. .message-bubble {
  1228. padding: 20rpx;
  1229. border-radius: 8rpx;
  1230. background-color: #fff;
  1231. word-wrap: break-word;
  1232. }
  1233. .message-self .message-bubble {
  1234. background-color: #95ec69;
  1235. }
  1236. .message-bubble.bubble-self {
  1237. background-color: #95ec69;
  1238. }
  1239. .message-text {
  1240. font-size: 30rpx;
  1241. line-height: 1.5;
  1242. }
  1243. .message-image {
  1244. max-width: 400rpx;
  1245. border-radius: 8rpx;
  1246. }
  1247. .message-voice {
  1248. display: flex;
  1249. align-items: center;
  1250. gap: 10rpx;
  1251. }
  1252. .message-video {
  1253. width: 400rpx;
  1254. height: 300rpx;
  1255. }
  1256. .message-recalled {
  1257. color: #999;
  1258. font-size: 28rpx;
  1259. }
  1260. .message-status {
  1261. text-align: right;
  1262. font-size: 24rpx;
  1263. color: #999;
  1264. margin-top: 5rpx;
  1265. }
  1266. .message-status .read {
  1267. color: #07c160;
  1268. }
  1269. .message-status .failed {
  1270. color: #fa5151;
  1271. }
  1272. .message-time {
  1273. display: block;
  1274. text-align: right;
  1275. font-size: 22rpx;
  1276. color: #ccc;
  1277. margin-top: 5rpx;
  1278. }
  1279. /* 输入框 */
  1280. .input-bar {
  1281. display: flex;
  1282. align-items: center;
  1283. padding: 20rpx;
  1284. background-color: #fff;
  1285. border-top: 1px solid #e5e5e5;
  1286. }
  1287. .input-icon {
  1288. width: 80rpx;
  1289. height: 80rpx;
  1290. display: flex;
  1291. align-items: center;
  1292. justify-content: center;
  1293. font-size: 50rpx;
  1294. }
  1295. .input-field {
  1296. flex: 1;
  1297. height: 70rpx;
  1298. padding: 0 20rpx;
  1299. background-color: #f5f5f5;
  1300. border-radius: 8rpx;
  1301. font-size: 30rpx;
  1302. }
  1303. .voice-button {
  1304. flex: 1;
  1305. height: 70rpx;
  1306. line-height: 70rpx;
  1307. background-color: #f5f5f5;
  1308. border-radius: 8rpx;
  1309. text-align: center;
  1310. font-size: 30rpx;
  1311. border: none;
  1312. }
  1313. /* 表情面板 */
  1314. .emoji-panel {
  1315. display: flex;
  1316. flex-wrap: wrap;
  1317. padding: 20rpx;
  1318. background-color: #fff;
  1319. border-top: 1px solid #e5e5e5;
  1320. }
  1321. .emoji-item {
  1322. width: 80rpx;
  1323. height: 80rpx;
  1324. display: flex;
  1325. align-items: center;
  1326. justify-content: center;
  1327. font-size: 60rpx;
  1328. }
  1329. /* 更多功能面板 */
  1330. .more-panel {
  1331. display: flex;
  1332. padding: 40rpx;
  1333. background-color: #fff;
  1334. border-top: 1px solid #e5e5e5;
  1335. }
  1336. .more-item {
  1337. display: flex;
  1338. flex-direction: column;
  1339. align-items: center;
  1340. margin: 0 40rpx;
  1341. }
  1342. .more-icon {
  1343. width: 100rpx;
  1344. height: 100rpx;
  1345. display: flex;
  1346. align-items: center;
  1347. justify-content: center;
  1348. font-size: 60rpx;
  1349. background-color: #f5f5f5;
  1350. border-radius: 16rpx;
  1351. margin-bottom: 10rpx;
  1352. }
  1353. .more-text {
  1354. font-size: 24rpx;
  1355. color: #666;
  1356. }
  1357. /* 时间分隔线 */
  1358. .time-divider {
  1359. text-align: center;
  1360. padding: 20rpx 0;
  1361. }
  1362. .time-text {
  1363. display: inline-block;
  1364. padding: 8rpx 20rpx;
  1365. background-color: rgba(0, 0, 0, 0.1);
  1366. border-radius: 8rpx;
  1367. font-size: 22rpx;
  1368. color: #999;
  1369. }
  1370. /* 消息气泡失败状态 */
  1371. .bubble-failed {
  1372. opacity: 0.6;
  1373. border: 2rpx solid #fa5151;
  1374. }
  1375. /* 消息状态优化 */
  1376. .message-status .sending {
  1377. color: #576b95;
  1378. }
  1379. .message-status .failed-group {
  1380. display: flex;
  1381. align-items: center;
  1382. gap: 10rpx;
  1383. }
  1384. .message-status .retry-btn {
  1385. color: #576b95;
  1386. text-decoration: underline;
  1387. cursor: pointer;
  1388. }
  1389. /* 消息操作菜单遮罩 */
  1390. .message-action-mask {
  1391. position: fixed;
  1392. top: 0;
  1393. left: 0;
  1394. right: 0;
  1395. bottom: 0;
  1396. background-color: rgba(0, 0, 0, 0.4);
  1397. z-index: 9999;
  1398. display: flex;
  1399. align-items: center;
  1400. justify-content: center;
  1401. }
  1402. /* 消息操作菜单 */
  1403. .message-action-menu {
  1404. width: 600rpx;
  1405. background-color: #fff;
  1406. border-radius: 20rpx;
  1407. overflow: hidden;
  1408. }
  1409. .message-action-menu .menu-item {
  1410. display: flex;
  1411. align-items: center;
  1412. justify-content: center;
  1413. gap: 15rpx;
  1414. padding: 30rpx;
  1415. font-size: 32rpx;
  1416. color: #333;
  1417. border-bottom: 1rpx solid #f0f0f0;
  1418. transition: background-color 0.2s;
  1419. }
  1420. .message-action-menu .menu-item:active {
  1421. background-color: #f5f5f5;
  1422. }
  1423. .message-action-menu .menu-item.cancel {
  1424. color: #999;
  1425. border-bottom: none;
  1426. margin-top: 20rpx;
  1427. border-top: 10rpx solid #f5f5f5;
  1428. }
  1429. .message-action-menu .menu-icon {
  1430. font-size: 36rpx;
  1431. }
  1432. </style>