chat.vue 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  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. uni.$emit('blacklistUpdated');
  1040. // 拉黑成功后立即返回消息列表页面(优化体验)
  1041. setTimeout(() => {
  1042. uni.navigateBack({
  1043. delta: 1,
  1044. success: () => {
  1045. // 返回成功后再次触发一次刷新,确保万无一失
  1046. uni.$emit('blacklistUpdated');
  1047. }
  1048. });
  1049. }, 1500);
  1050. } else {
  1051. throw new Error(res.data?.message || '拉黑失败');
  1052. }
  1053. } catch (error) {
  1054. console.error('拉黑失败:', error);
  1055. uni.showToast({ title: error.message || '拉黑失败', icon: 'none' });
  1056. }
  1057. },
  1058. }
  1059. };
  1060. </script>
  1061. <style scoped>
  1062. /* 弹窗遮罩 */
  1063. .modal-mask {
  1064. position: fixed;
  1065. top: 0;
  1066. left: 0;
  1067. right: 0;
  1068. bottom: 0;
  1069. background-color: rgba(0, 0, 0, 0.5);
  1070. z-index: 10000;
  1071. display: flex;
  1072. align-items: center;
  1073. justify-content: center;
  1074. }
  1075. /* 更多选项弹窗内容 */
  1076. .modal-content {
  1077. width: 70%;
  1078. background-color: #fff;
  1079. border-radius: 20rpx;
  1080. overflow: hidden;
  1081. }
  1082. .modal-header {
  1083. padding: 30rpx;
  1084. text-align: center;
  1085. border-bottom: 1px solid #eee;
  1086. }
  1087. .modal-title {
  1088. font-size: 32rpx;
  1089. font-weight: bold;
  1090. display: block;
  1091. }
  1092. .modal-subtitle {
  1093. font-size: 24rpx;
  1094. color: #999;
  1095. display: block;
  1096. margin-top: 10rpx;
  1097. }
  1098. .modal-body {
  1099. padding: 20rpx 0;
  1100. }
  1101. .modal-item {
  1102. display: flex;
  1103. align-items: center;
  1104. padding: 25rpx 40rpx;
  1105. font-size: 30rpx;
  1106. }
  1107. .modal-item.danger {
  1108. color: #fa5151;
  1109. }
  1110. .item-icon {
  1111. font-size: 32rpx;
  1112. margin-right: 20rpx;
  1113. }
  1114. .modal-footer {
  1115. padding: 20rpx;
  1116. border-top: 1px solid #eee;
  1117. }
  1118. .modal-close-btn {
  1119. width: 100%;
  1120. background-color: #f5f5f5;
  1121. border: none;
  1122. border-radius: 10rpx;
  1123. padding: 20rpx;
  1124. font-size: 30rpx;
  1125. }
  1126. /* 确认弹窗样式 */
  1127. .confirm-modal {
  1128. width: 60%;
  1129. background-color: #fff;
  1130. border-radius: 20rpx;
  1131. padding: 40rpx;
  1132. text-align: center;
  1133. }
  1134. .confirm-title {
  1135. font-size: 32rpx;
  1136. font-weight: bold;
  1137. margin-bottom: 30rpx;
  1138. }
  1139. .confirm-content {
  1140. font-size: 28rpx;
  1141. color: #666;
  1142. margin-bottom: 40rpx;
  1143. line-height: 1.5;
  1144. }
  1145. .confirm-buttons {
  1146. display: flex;
  1147. justify-content: space-between;
  1148. }
  1149. .confirm-btn {
  1150. flex: 1;
  1151. margin: 0 10rpx;
  1152. padding: 20rpx;
  1153. border-radius: 10rpx;
  1154. border: none;
  1155. font-size: 28rpx;
  1156. }
  1157. .confirm-btn.cancel {
  1158. background-color: #f5f5f5;
  1159. }
  1160. .confirm-btn.confirm {
  1161. background-color: #fa5151;
  1162. color: #fff;
  1163. }
  1164. .chat-page {
  1165. display: flex;
  1166. flex-direction: column;
  1167. height: 100vh;
  1168. background-color: #f5f5f5;
  1169. }
  1170. /* 顶部导航 */
  1171. .chat-header {
  1172. display: flex;
  1173. align-items: center;
  1174. justify-content: space-between;
  1175. padding: 20rpx 30rpx;
  1176. background-color: #fff;
  1177. border-bottom: 1px solid #e5e5e5;
  1178. }
  1179. .header-left, .header-right {
  1180. width: 80rpx;
  1181. }
  1182. .icon-back, .icon-more {
  1183. font-size: 40rpx;
  1184. }
  1185. .header-center {
  1186. flex: 1;
  1187. text-align: center;
  1188. }
  1189. .chat-title {
  1190. display: block;
  1191. font-size: 36rpx;
  1192. font-weight: bold;
  1193. }
  1194. .online-status {
  1195. display: block;
  1196. font-size: 24rpx;
  1197. color: #999;
  1198. margin-top: 5rpx;
  1199. }
  1200. .online-status.online {
  1201. color: #07c160;
  1202. }
  1203. /* 消息列表 */
  1204. .message-list {
  1205. flex: 1;
  1206. padding: 20rpx;
  1207. overflow-y: scroll;
  1208. }
  1209. .loading-tip {
  1210. text-align: center;
  1211. padding: 20rpx;
  1212. color: #999;
  1213. font-size: 28rpx;
  1214. }
  1215. .message-item {
  1216. display: flex;
  1217. margin-bottom: 30rpx;
  1218. }
  1219. .message-item.message-self {
  1220. flex-direction: row-reverse;
  1221. }
  1222. .avatar {
  1223. width: 80rpx;
  1224. height: 80rpx;
  1225. border-radius: 8rpx;
  1226. margin: 0 20rpx;
  1227. }
  1228. .message-content-wrapper {
  1229. max-width: 70%;
  1230. }
  1231. .message-name {
  1232. display: block;
  1233. font-size: 24rpx;
  1234. color: #999;
  1235. margin-bottom: 10rpx;
  1236. }
  1237. .message-bubble {
  1238. padding: 20rpx;
  1239. border-radius: 8rpx;
  1240. background-color: #fff;
  1241. word-wrap: break-word;
  1242. }
  1243. .message-self .message-bubble {
  1244. background-color: #95ec69;
  1245. }
  1246. .message-bubble.bubble-self {
  1247. background-color: #95ec69;
  1248. }
  1249. .message-text {
  1250. font-size: 30rpx;
  1251. line-height: 1.5;
  1252. }
  1253. .message-image {
  1254. max-width: 400rpx;
  1255. border-radius: 8rpx;
  1256. }
  1257. .message-voice {
  1258. display: flex;
  1259. align-items: center;
  1260. gap: 10rpx;
  1261. }
  1262. .message-video {
  1263. width: 400rpx;
  1264. height: 300rpx;
  1265. }
  1266. .message-recalled {
  1267. color: #999;
  1268. font-size: 28rpx;
  1269. }
  1270. .message-status {
  1271. text-align: right;
  1272. font-size: 24rpx;
  1273. color: #999;
  1274. margin-top: 5rpx;
  1275. }
  1276. .message-status .read {
  1277. color: #07c160;
  1278. }
  1279. .message-status .failed {
  1280. color: #fa5151;
  1281. }
  1282. .message-time {
  1283. display: block;
  1284. text-align: right;
  1285. font-size: 22rpx;
  1286. color: #ccc;
  1287. margin-top: 5rpx;
  1288. }
  1289. /* 输入框 */
  1290. .input-bar {
  1291. display: flex;
  1292. align-items: center;
  1293. padding: 20rpx;
  1294. background-color: #fff;
  1295. border-top: 1px solid #e5e5e5;
  1296. }
  1297. .input-icon {
  1298. width: 80rpx;
  1299. height: 80rpx;
  1300. display: flex;
  1301. align-items: center;
  1302. justify-content: center;
  1303. font-size: 50rpx;
  1304. }
  1305. .input-field {
  1306. flex: 1;
  1307. height: 70rpx;
  1308. padding: 0 20rpx;
  1309. background-color: #f5f5f5;
  1310. border-radius: 8rpx;
  1311. font-size: 30rpx;
  1312. }
  1313. .voice-button {
  1314. flex: 1;
  1315. height: 70rpx;
  1316. line-height: 70rpx;
  1317. background-color: #f5f5f5;
  1318. border-radius: 8rpx;
  1319. text-align: center;
  1320. font-size: 30rpx;
  1321. border: none;
  1322. }
  1323. /* 表情面板 */
  1324. .emoji-panel {
  1325. display: flex;
  1326. flex-wrap: wrap;
  1327. padding: 20rpx;
  1328. background-color: #fff;
  1329. border-top: 1px solid #e5e5e5;
  1330. }
  1331. .emoji-item {
  1332. width: 80rpx;
  1333. height: 80rpx;
  1334. display: flex;
  1335. align-items: center;
  1336. justify-content: center;
  1337. font-size: 60rpx;
  1338. }
  1339. /* 更多功能面板 */
  1340. .more-panel {
  1341. display: flex;
  1342. padding: 40rpx;
  1343. background-color: #fff;
  1344. border-top: 1px solid #e5e5e5;
  1345. }
  1346. .more-item {
  1347. display: flex;
  1348. flex-direction: column;
  1349. align-items: center;
  1350. margin: 0 40rpx;
  1351. }
  1352. .more-icon {
  1353. width: 100rpx;
  1354. height: 100rpx;
  1355. display: flex;
  1356. align-items: center;
  1357. justify-content: center;
  1358. font-size: 60rpx;
  1359. background-color: #f5f5f5;
  1360. border-radius: 16rpx;
  1361. margin-bottom: 10rpx;
  1362. }
  1363. .more-text {
  1364. font-size: 24rpx;
  1365. color: #666;
  1366. }
  1367. /* 时间分隔线 */
  1368. .time-divider {
  1369. text-align: center;
  1370. padding: 20rpx 0;
  1371. }
  1372. .time-text {
  1373. display: inline-block;
  1374. padding: 8rpx 20rpx;
  1375. background-color: rgba(0, 0, 0, 0.1);
  1376. border-radius: 8rpx;
  1377. font-size: 22rpx;
  1378. color: #999;
  1379. }
  1380. /* 消息气泡失败状态 */
  1381. .bubble-failed {
  1382. opacity: 0.6;
  1383. border: 2rpx solid #fa5151;
  1384. }
  1385. /* 消息状态优化 */
  1386. .message-status .sending {
  1387. color: #576b95;
  1388. }
  1389. .message-status .failed-group {
  1390. display: flex;
  1391. align-items: center;
  1392. gap: 10rpx;
  1393. }
  1394. .message-status .retry-btn {
  1395. color: #576b95;
  1396. text-decoration: underline;
  1397. cursor: pointer;
  1398. }
  1399. /* 消息操作菜单遮罩 */
  1400. .message-action-mask {
  1401. position: fixed;
  1402. top: 0;
  1403. left: 0;
  1404. right: 0;
  1405. bottom: 0;
  1406. background-color: rgba(0, 0, 0, 0.4);
  1407. z-index: 9999;
  1408. display: flex;
  1409. align-items: center;
  1410. justify-content: center;
  1411. }
  1412. /* 消息操作菜单 */
  1413. .message-action-menu {
  1414. width: 600rpx;
  1415. background-color: #fff;
  1416. border-radius: 20rpx;
  1417. overflow: hidden;
  1418. }
  1419. .message-action-menu .menu-item {
  1420. display: flex;
  1421. align-items: center;
  1422. justify-content: center;
  1423. gap: 15rpx;
  1424. padding: 30rpx;
  1425. font-size: 32rpx;
  1426. color: #333;
  1427. border-bottom: 1rpx solid #f0f0f0;
  1428. transition: background-color 0.2s;
  1429. }
  1430. .message-action-menu .menu-item:active {
  1431. background-color: #f5f5f5;
  1432. }
  1433. .message-action-menu .menu-item.cancel {
  1434. color: #999;
  1435. border-bottom: none;
  1436. margin-top: 20rpx;
  1437. border-top: 10rpx solid #f5f5f5;
  1438. }
  1439. .message-action-menu .menu-icon {
  1440. font-size: 36rpx;
  1441. }
  1442. </style>