message.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. <template>
  2. <view class="matchmaker-message">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="goBack"></view>
  6. <text class="header-title">消息</text>
  7. <view class="placeholder"></view>
  8. </view>
  9. <scroll-view scroll-y class="content">
  10. <!-- 加载中 -->
  11. <view v-if="loading" class="loading-container">
  12. <text>加载中...</text>
  13. </view>
  14. <!-- 消息内容 -->
  15. <view v-else-if="conversationList.length > 0">
  16. <!-- 系统通知卡片 -->
  17. <view class="message-item system-notification" v-if="systemNotification" @click="openSystemMessages">
  18. <text class="message-type">{{ systemNotification.title }}</text>
  19. <text class="message-time">{{ systemNotification.timeText }}</text>
  20. <text class="message-content">{{ systemNotification.content }}</text>
  21. <text class="message-footer">{{ systemNotification.footer }}</text>
  22. </view>
  23. <!-- 撮合成功通知卡片 -->
  24. <view class="message-item match-success" v-if="matchSuccessNotification" @click="openAuditRecords">
  25. <view class="message-icon heart"></view>
  26. <view class="message-body">
  27. <text class="message-type">{{ matchSuccessNotification.title }}</text>
  28. <text class="message-content">{{ matchSuccessNotification.content }}</text>
  29. </view>
  30. <view class="message-right-area">
  31. <text class="message-time">{{ matchSuccessNotification.timeText }}</text>
  32. <view v-if="matchSuccessUnread > 0" class="match-unread-badge">
  33. {{ matchSuccessUnread > 99 ? '99+' : matchSuccessUnread }}
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 今天 -->
  38. <view v-if="todayConversations.length > 0">
  39. <view class="time-group">
  40. <text class="time-label">今天</text>
  41. </view>
  42. <view
  43. v-for="conversation in todayConversations"
  44. :key="conversation.conversationID"
  45. class="message-item user-message"
  46. @click="openChat(conversation)"
  47. >
  48. <image
  49. v-if="conversation.userProfile.avatar"
  50. :src="conversation.userProfile.avatar"
  51. class="message-avatar-img"
  52. />
  53. <view v-else class="message-avatar">
  54. {{ conversation.userProfile.nick || conversation.userProfile.userID.charAt(0) }}
  55. </view>
  56. <view class="message-body">
  57. <text class="message-type">{{ conversation.userProfile.nick || conversation.userProfile.userID }}</text>
  58. <text class="message-content">{{ getLastMessageText(conversation.lastMessage) }}</text>
  59. </view>
  60. <view class="message-right">
  61. <text class="message-time">{{ formatTime(conversation.lastMessage.lastTime) }}</text>
  62. <view v-if="conversation.unreadCount > 0" class="unread-badge">
  63. {{ conversation.unreadCount > 99 ? '99+' : conversation.unreadCount }}
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 昨日 -->
  69. <view v-if="yesterdayConversations.length > 0">
  70. <view class="time-group">
  71. <text class="time-label">昨日</text>
  72. </view>
  73. <view
  74. v-for="conversation in yesterdayConversations"
  75. :key="conversation.conversationID"
  76. class="message-item user-message"
  77. @click="openChat(conversation)"
  78. >
  79. <image
  80. v-if="conversation.userProfile.avatar"
  81. :src="conversation.userProfile.avatar"
  82. class="message-avatar-img"
  83. />
  84. <view v-else class="message-avatar">
  85. {{ conversation.userProfile.nick || conversation.userProfile.userID.charAt(0) }}
  86. </view>
  87. <view class="message-body">
  88. <text class="message-type">{{ conversation.userProfile.nick || conversation.userProfile.userID }}</text>
  89. <text class="message-content">{{ getLastMessageText(conversation.lastMessage) }}</text>
  90. </view>
  91. <view class="message-right">
  92. <text class="message-time">{{ formatTime(conversation.lastMessage.lastTime) }}</text>
  93. <view v-if="conversation.unreadCount > 0" class="unread-badge">
  94. {{ conversation.unreadCount > 99 ? '99+' : conversation.unreadCount }}
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. <!-- 更早 -->
  100. <view v-if="earlierConversations.length > 0">
  101. <view class="time-group">
  102. <text class="time-label">更早</text>
  103. </view>
  104. <view
  105. v-for="conversation in earlierConversations"
  106. :key="conversation.conversationID"
  107. class="message-item user-message"
  108. @click="openChat(conversation)"
  109. >
  110. <image
  111. v-if="conversation.userProfile.avatar"
  112. :src="conversation.userProfile.avatar"
  113. class="message-avatar-img"
  114. />
  115. <view v-else class="message-avatar">
  116. {{ conversation.userProfile.nick || conversation.userProfile.userID.charAt(0) }}
  117. </view>
  118. <view class="message-body">
  119. <text class="message-type">{{ conversation.userProfile.nick || conversation.userProfile.userID }}</text>
  120. <text class="message-content">{{ getLastMessageText(conversation.lastMessage) }}</text>
  121. </view>
  122. <view class="message-right">
  123. <text class="message-time">{{ formatTime(conversation.lastMessage.lastTime) }}</text>
  124. <view v-if="conversation.unreadCount > 0" class="unread-badge">
  125. {{ conversation.unreadCount > 99 ? '99+' : conversation.unreadCount }}
  126. </view>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. <!-- 空状态 -->
  132. <view v-else class="empty-container">
  133. <text>暂无消息</text>
  134. </view>
  135. </scroll-view>
  136. <!-- 底部导航 -->
  137. <view class="tabbar">
  138. <view class="tabbar-item home" @click="navigateToWorkbench">
  139. <view class="tabbar-icon"></view>
  140. <text class="tabbar-text">工作台</text>
  141. </view>
  142. <view class="tabbar-item resources" @click="navigateToMyResources">
  143. <view class="tabbar-icon"></view>
  144. <text class="tabbar-text">我的资源</text>
  145. </view>
  146. <view class="tabbar-item trophy" @click="navigateToRanking">
  147. <view class="tabbar-icon"></view>
  148. <text class="tabbar-text">排行榜</text>
  149. </view>
  150. <!-- <view class="tabbar-item message active" @click="navigateToMessage">
  151. <view class="tabbar-icon">
  152. <view v-if="totalUnreadCount > 0" class="badge">
  153. {{ totalUnreadCount > 99 ? '99+' : totalUnreadCount }}
  154. </view>
  155. </view>
  156. <text class="tabbar-text">消息</text>
  157. </view> -->
  158. <view class="tabbar-item mine" @click="navigateToMine">
  159. <view class="tabbar-icon"></view>
  160. <text class="tabbar-text">我的</text>
  161. </view>
  162. </view>
  163. </view>
  164. </template>
  165. <script>
  166. import timManager from '@/utils/tim-manager.js'
  167. import TIM from 'tim-wx-sdk'
  168. import api from '@/utils/api.js'
  169. export default {
  170. data() {
  171. return {
  172. loading: true,
  173. conversationList: [],
  174. matchmakerInfo: null,
  175. imUserId: '',
  176. totalUnreadCount: 0,
  177. // 系统消息未读数
  178. systemUnread: 0,
  179. // 撮合成功通知未读数
  180. matchSuccessUnread: 0,
  181. // 红娘ID
  182. matchmakerId: null,
  183. // 顶部系统通知占位(后续可从后端加载)
  184. systemNotification: {
  185. title: '系统通知',
  186. content: '您的线索审核已通过,获得20积分奖励,当期积分可兑换【资源查看权限】x1',
  187. footer: '完成线索录采集,积分+20(距离黄金级还差72分)',
  188. timeText: '刚刚'
  189. },
  190. // 撮合成功通知占位
  191. matchSuccessNotification: {
  192. title: '撮合成功通知',
  193. content: '您推荐的李先生和王女士已成功匹配,获得50积分+100元现金奖励',
  194. timeText: '10分钟前'
  195. }
  196. }
  197. },
  198. computed: {
  199. // 今天的会话
  200. todayConversations() {
  201. const today = new Date()
  202. return this.conversationList.filter(conv => this.isSameDay(conv.lastMessage, today))
  203. },
  204. // 昨日会话
  205. yesterdayConversations() {
  206. const yesterday = new Date()
  207. yesterday.setDate(yesterday.getDate() - 1)
  208. return this.conversationList.filter(conv => this.isSameDay(conv.lastMessage, yesterday))
  209. },
  210. // 更早会话
  211. earlierConversations() {
  212. const today = new Date()
  213. const yesterday = new Date()
  214. yesterday.setDate(yesterday.getDate() - 1)
  215. return this.conversationList.filter(conv => {
  216. const msg = conv.lastMessage
  217. if (!msg || !msg.lastTime) return false
  218. const isToday = this.isSameDay(msg, today)
  219. const isYesterday = this.isSameDay(msg, yesterday)
  220. return !isToday && !isYesterday
  221. })
  222. }
  223. },
  224. onLoad() {
  225. this.initIM()
  226. },
  227. onShow() {
  228. // 页面显示时刷新会话列表
  229. if (this.imUserId) {
  230. this.loadConversationList()
  231. }
  232. // 同步系统消息未读
  233. this.loadSystemUnread()
  234. // 同步撮合成功通知未读
  235. this.loadMatchSuccessUnread()
  236. },
  237. onUnload() {
  238. // 页面卸载时移除监听
  239. this.removeListeners()
  240. },
  241. methods: {
  242. // 判断消息是否与给定日期同一天
  243. isSameDay(lastMessage, baseDate) {
  244. if (!lastMessage || !lastMessage.lastTime) return false
  245. const msgDate = new Date(lastMessage.lastTime * 1000)
  246. const d = baseDate instanceof Date ? baseDate : new Date(baseDate)
  247. return (
  248. msgDate.getFullYear() === d.getFullYear() &&
  249. msgDate.getMonth() === d.getMonth() &&
  250. msgDate.getDate() === d.getDate()
  251. )
  252. },
  253. // 加载系统消息未读数,并同步最新一条系统通知到顶部卡片
  254. async loadSystemUnread() {
  255. try {
  256. const userId = uni.getStorageSync('userId')
  257. if (!userId) return
  258. const count = await api.message.getSystemUnreadCount(userId)
  259. // getSystemUnreadCount 可能返回 {code,data} 或直接 number,这里统一兼容
  260. if (typeof count === 'number') {
  261. this.systemUnread = count
  262. } else if (count && typeof count.data === 'number') {
  263. this.systemUnread = count.data
  264. }
  265. // 同时拉取最新一条系统通知,用于顶部卡片展示
  266. const res = await api.message.getSystemList(userId, 1, 1)
  267. const list = (res && (res.list || res.data?.list)) || []
  268. if (list.length > 0) {
  269. const item = list[0]
  270. // 计算时间文案
  271. let timeText = ''
  272. const t = item.createdAt || item.created_at
  273. if (t) {
  274. const d2 = new Date(t)
  275. const now = new Date()
  276. const diff = now - d2
  277. if (diff < 60000) {
  278. timeText = '刚刚'
  279. } else if (diff < 3600000) {
  280. timeText = Math.floor(diff / 60000) + '分钟前'
  281. } else {
  282. const mm = String(d2.getMonth() + 1).padStart(2, '0')
  283. const dd = String(d2.getDate()).padStart(2, '0')
  284. const hh = String(d2.getHours()).padStart(2, '0')
  285. const mi = String(d2.getMinutes()).padStart(2, '0')
  286. timeText = `${mm}-${dd} ${hh}:${mi}`
  287. }
  288. }
  289. // 用最新系统通知更新卡片文案(小字显示最新内容)
  290. this.systemNotification = {
  291. ...this.systemNotification,
  292. title: '系统通知',
  293. content: item.title || this.systemNotification.content,
  294. footer: item.content || this.systemNotification.footer,
  295. timeText: timeText || this.systemNotification.timeText
  296. }
  297. }
  298. } catch (e) {
  299. }
  300. },
  301. // 跳转系统通知列表
  302. openSystemMessages() {
  303. uni.navigateTo({
  304. url: '/pages/matchmaker-workbench/system-messages'
  305. })
  306. },
  307. // 跳转审核记录列表
  308. openAuditRecords() {
  309. uni.navigateTo({
  310. url: '/pages/matchmaker-workbench/audit-records'
  311. })
  312. },
  313. // 加载撮合成功通知未读数
  314. async loadMatchSuccessUnread() {
  315. try {
  316. if (!this.matchmakerId) return
  317. const res = await api.successCaseUpload.getUnreadCount(this.matchmakerId)
  318. if (res && res.code === 200) {
  319. this.matchSuccessUnread = res.data || 0
  320. }
  321. } catch (e) {
  322. }
  323. },
  324. // 初始化 IM
  325. async initIM() {
  326. try {
  327. this.loading = true
  328. // 1. 获取当前登录用户ID
  329. const userId = uni.getStorageSync('userId')
  330. if (!userId) {
  331. uni.showToast({ title: '请先登录', icon: 'none' })
  332. return
  333. }
  334. // 2. 获取红娘信息
  335. const res = await uni.request({
  336. url: 'https://api.zhongruanke.cn:8081/api/matchmaker/current',
  337. method: 'GET',
  338. data: { userId }
  339. })
  340. if (res[1].data.code !== 200) {
  341. uni.showToast({ title: '获取红娘信息失败', icon: 'none' })
  342. return
  343. }
  344. this.matchmakerInfo = res[1].data.data
  345. this.imUserId = this.matchmakerInfo.imUserId // m_1
  346. this.matchmakerId = this.matchmakerInfo.matchmakerId || this.matchmakerInfo.matchmaker_id
  347. // 加载撮合成功通知未读数
  348. this.loadMatchSuccessUnread()
  349. // 3. 获取 UserSig
  350. const sigRes = await uni.request({
  351. url: `https://api.zhongruanke.cn/api/im/getUserSig?userId=${this.imUserId}`,
  352. method: 'GET'
  353. })
  354. if (sigRes[1].data.code !== 200) {
  355. uni.showToast({ title: '获取UserSig失败', icon: 'none' })
  356. return
  357. }
  358. const userSig = sigRes[1].data.data.userSig
  359. // 4. 先登出当前账号(如果已登录)
  360. try {
  361. await timManager.logout()
  362. } catch (e) {
  363. }
  364. // 5. 以红娘身份登录 IM
  365. await timManager.login(this.imUserId, userSig)
  366. // 6. 监听事件
  367. this.addListeners()
  368. // 7. 加载会话列表
  369. await this.loadConversationList()
  370. } catch (error) {
  371. uni.showToast({ title: '初始化失败', icon: 'none' })
  372. } finally {
  373. this.loading = false
  374. }
  375. },
  376. // 加载会话列表
  377. async loadConversationList() {
  378. try {
  379. // SDK 未登录 / 未 ready 时不调用会话列表接口,避免报“接口调用时机不合理”
  380. if (!timManager.isLogin || !timManager.tim) {
  381. return
  382. }
  383. const tim = timManager.getTim()
  384. const { data } = await tim.getConversationList()
  385. this.conversationList = data.conversationList || []
  386. // 补全用户头像和昵称
  387. await this.loadUserAvatars()
  388. // 计算总未读数
  389. this.totalUnreadCount = this.conversationList.reduce((total, conv) => {
  390. return total + (conv.unreadCount || 0)
  391. }, 0)
  392. } catch (error) {
  393. }
  394. },
  395. // 添加事件监听
  396. addListeners() {
  397. const tim = timManager.getTim()
  398. // 监听新消息
  399. tim.on(TIM.EVENT.MESSAGE_RECEIVED, this.onMessageReceived)
  400. // 监听会话列表更新
  401. tim.on(TIM.EVENT.CONVERSATION_LIST_UPDATED, this.onConversationListUpdated)
  402. },
  403. // 移除事件监听
  404. removeListeners() {
  405. const tim = timManager.getTim()
  406. tim.off(TIM.EVENT.MESSAGE_RECEIVED, this.onMessageReceived)
  407. tim.off(TIM.EVENT.CONVERSATION_LIST_UPDATED, this.onConversationListUpdated)
  408. },
  409. // 收到新消息
  410. onMessageReceived(event) {
  411. this.loadConversationList()
  412. },
  413. // 会话列表更新
  414. onConversationListUpdated(event) {
  415. this.conversationList = event.data || []
  416. // 补全头像昵称后再计算未读
  417. this.loadUserAvatars().then(() => {
  418. this.totalUnreadCount = this.conversationList.reduce((total, conv) => {
  419. return total + (conv.unreadCount || 0)
  420. }, 0)
  421. })
  422. },
  423. // 批量补全用户头像和昵称
  424. async loadUserAvatars() {
  425. try {
  426. if (!this.conversationList || this.conversationList.length === 0) {
  427. return
  428. }
  429. // 收集对端用户ID(排除红娘 m_ 开头的ID)
  430. const userIds = []
  431. this.conversationList.forEach(conv => {
  432. let targetUserId = ''
  433. if (conv.userProfile && conv.userProfile.userID) {
  434. targetUserId = String(conv.userProfile.userID)
  435. } else if (conv.conversationID && conv.conversationID.indexOf('C2C') === 0) {
  436. targetUserId = conv.conversationID.replace('C2C', '')
  437. }
  438. if (!targetUserId) return
  439. if (targetUserId.startsWith('m_')) return
  440. userIds.push(targetUserId)
  441. })
  442. const uniqueIds = Array.from(new Set(userIds))
  443. if (uniqueIds.length === 0) return
  444. const res = await uni.request({
  445. url: 'https://api.zhongruanke.cn/api/user/batch',
  446. method: 'GET',
  447. data: {
  448. userIds: uniqueIds.join(',')
  449. }
  450. })
  451. if (!res[1] || res[1].statusCode !== 200 || res[1].data.code !== 200) {
  452. return
  453. }
  454. const list = res[1].data.data || []
  455. const userMap = {}
  456. list.forEach(user => {
  457. if (!user || user.userId == null) return
  458. userMap[String(user.userId)] = {
  459. nickname: user.nickname,
  460. avatarUrl: user.avatarUrl
  461. }
  462. })
  463. // 回填到会话列表的 userProfile 中
  464. this.conversationList = this.conversationList.map(conv => {
  465. let targetUserId = ''
  466. if (conv.userProfile && conv.userProfile.userID) {
  467. targetUserId = String(conv.userProfile.userID)
  468. } else if (conv.conversationID && conv.conversationID.indexOf('C2C') === 0) {
  469. targetUserId = conv.conversationID.replace('C2C', '')
  470. }
  471. const info = targetUserId ? userMap[targetUserId] : null
  472. if (info) {
  473. conv.userProfile = conv.userProfile || {}
  474. conv.userProfile.nick = info.nickname || conv.userProfile.nick || `用户${targetUserId}`
  475. conv.userProfile.avatar = info.avatarUrl || conv.userProfile.avatar || ''
  476. }
  477. return conv
  478. })
  479. } catch (error) {
  480. }
  481. },
  482. // 打开聊天页面
  483. openChat(conversation) {
  484. const targetUserId = conversation.userProfile.userID
  485. const targetUserName = encodeURIComponent(conversation.userProfile.nick || `用户${targetUserId}`)
  486. const targetUserAvatar = encodeURIComponent(conversation.userProfile.avatar || '')
  487. uni.navigateTo({
  488. url: `/pages/message/chat?targetUserId=${targetUserId}&targetUserName=${targetUserName}&targetUserAvatar=${targetUserAvatar}&fromMatchmaker=true`
  489. })
  490. },
  491. // 获取最后一条消息的文本
  492. getLastMessageText(lastMessage) {
  493. if (!lastMessage) return ''
  494. switch (lastMessage.type) {
  495. case TIM.TYPES.MSG_TEXT:
  496. return lastMessage.payload.text
  497. case TIM.TYPES.MSG_IMAGE:
  498. return '[图片]'
  499. case TIM.TYPES.MSG_AUDIO:
  500. return '[语音]'
  501. case TIM.TYPES.MSG_VIDEO:
  502. return '[视频]'
  503. case TIM.TYPES.MSG_FILE:
  504. return '[文件]'
  505. default:
  506. return '[消息]'
  507. }
  508. },
  509. // 格式化时间
  510. formatTime(timestamp) {
  511. if (!timestamp) return ''
  512. const now = new Date()
  513. const msgTime = new Date(timestamp * 1000)
  514. const diff = now - msgTime
  515. // 一分钟内
  516. if (diff < 60000) {
  517. return '刚刚'
  518. }
  519. // 一小时内
  520. if (diff < 3600000) {
  521. return Math.floor(diff / 60000) + '分钟前'
  522. }
  523. // 今天
  524. if (msgTime.toDateString() === now.toDateString()) {
  525. return msgTime.getHours() + ':' + String(msgTime.getMinutes()).padStart(2, '0')
  526. }
  527. // 昨天
  528. const yesterday = new Date(now)
  529. yesterday.setDate(yesterday.getDate() - 1)
  530. if (msgTime.toDateString() === yesterday.toDateString()) {
  531. return '昨天'
  532. }
  533. // 更早
  534. return (msgTime.getMonth() + 1) + '-' + msgTime.getDate()
  535. },
  536. // 返回上一页
  537. goBack() {
  538. uni.navigateBack()
  539. },
  540. // 导航到工作台
  541. navigateToWorkbench() {
  542. uni.redirectTo({
  543. url: '/pages/matchmaker-workbench/index'
  544. })
  545. },
  546. // 导航到我的资源
  547. navigateToMyResources() {
  548. uni.redirectTo({
  549. url: '/pages/matchmaker-workbench/my-resources'
  550. })
  551. },
  552. // 导航到排行榜
  553. navigateToRanking() {
  554. uni.redirectTo({
  555. url: '/pages/matchmaker-workbench/ranking'
  556. })
  557. },
  558. // 导航到消息
  559. navigateToMessage() {
  560. // 已在消息页面,无需跳转
  561. },
  562. // 导航到我的
  563. navigateToMine() {
  564. uni.redirectTo({
  565. url: '/pages/matchmaker-workbench/mine'
  566. })
  567. }
  568. }
  569. }
  570. </script>
  571. <style lang="scss" scoped>
  572. .matchmaker-message {
  573. min-height: 100vh;
  574. /* 顶部淡粉,中部淡紫,越到底部越接近白色 */
  575. background: linear-gradient(180deg, #fff1f7 0%, #f6ebff 45%, #fbf7ff 75%, #ffffff 100%);
  576. display: flex;
  577. flex-direction: column;
  578. }
  579. /* 顶部导航栏 */
  580. .header {
  581. display: flex;
  582. align-items: center;
  583. justify-content: space-between;
  584. padding: 25rpx 30rpx;
  585. padding-top: calc(25rpx + env(safe-area-inset-top));
  586. background: transparent;
  587. border-bottom-width: 0;
  588. .back-btn {
  589. width: 70rpx;
  590. height: 70rpx;
  591. display: flex;
  592. align-items: center;
  593. justify-content: center;
  594. background: rgba(240, 240, 240, 0.5);
  595. border-radius: 50%;
  596. background-size: 40rpx 40rpx;
  597. background-repeat: no-repeat;
  598. background-position: center;
  599. }
  600. .header-title {
  601. font-size: 38rpx;
  602. font-weight: bold;
  603. color: #333;
  604. }
  605. .placeholder {
  606. width: 70rpx;
  607. }
  608. }
  609. .content {
  610. flex: 1;
  611. padding: 20rpx 24rpx 140rpx;
  612. box-sizing: border-box;
  613. }
  614. /* 消息项 */
  615. .message-item {
  616. background: #ffffff;
  617. border-radius: 24rpx;
  618. padding: 28rpx;
  619. margin-bottom: 20rpx;
  620. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.05);
  621. position: relative;
  622. &.system-notification {
  623. background: #ffffff;
  624. border-radius: 28rpx;
  625. border: 2rpx solid rgba(255, 128, 171, 0.85);
  626. box-shadow: 0 10rpx 26rpx rgba(255, 128, 171, 0.28);
  627. padding: 26rpx 30rpx;
  628. .message-type {
  629. display: block;
  630. font-size: 32rpx;
  631. font-weight: 600;
  632. color: #333;
  633. margin-bottom: 12rpx;
  634. }
  635. .message-time {
  636. position: absolute;
  637. top: 26rpx;
  638. right: 30rpx;
  639. font-size: 24rpx;
  640. color: #b88bb0;
  641. }
  642. .message-content {
  643. display: block;
  644. font-size: 26rpx;
  645. color: #555;
  646. line-height: 1.6;
  647. margin-bottom: 12rpx;
  648. }
  649. .message-footer {
  650. display: block;
  651. font-size: 24rpx;
  652. color: #b27aa0;
  653. line-height: 1.4;
  654. }
  655. }
  656. &.match-success {
  657. display: flex;
  658. background: linear-gradient(135deg, #f8f3ff 0%, #f4e6ff 45%, #ffeaf7 100%);
  659. border: 0;
  660. box-shadow: 0 8rpx 20rpx rgba(186, 104, 200, 0.25);
  661. .message-icon {
  662. width: 60rpx;
  663. height: 60rpx;
  664. border-radius: 50%;
  665. margin-right: 20rpx;
  666. background-size: 40rpx 40rpx;
  667. background-repeat: no-repeat;
  668. background-position: center;
  669. }
  670. .message-icon.heart {
  671. background-color: #f8d9ef;
  672. background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23e573ab"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg>');
  673. }
  674. .message-body {
  675. flex: 1;
  676. }
  677. .message-type {
  678. display: block;
  679. font-size: 30rpx;
  680. font-weight: 600;
  681. color: #333;
  682. margin-bottom: 10rpx;
  683. }
  684. .message-content {
  685. display: block;
  686. font-size: 26rpx;
  687. color: #666;
  688. line-height: 1.4;
  689. }
  690. .message-right-area {
  691. display: flex;
  692. flex-direction: column;
  693. align-items: flex-end;
  694. margin-left: 20rpx;
  695. }
  696. .message-time {
  697. font-size: 24rpx;
  698. color: #a691c0;
  699. margin-bottom: 10rpx;
  700. }
  701. .match-unread-badge {
  702. background: #ff5c9a;
  703. color: #FFFFFF;
  704. font-size: 20rpx;
  705. padding: 4rpx 12rpx;
  706. border-radius: 20rpx;
  707. min-width: 36rpx;
  708. text-align: center;
  709. }
  710. }
  711. &.user-message {
  712. display: flex;
  713. background: #ffffff;
  714. border: 0;
  715. box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.04);
  716. align-items: center;
  717. .message-avatar {
  718. width: 60rpx;
  719. height: 60rpx;
  720. border-radius: 50%;
  721. background: linear-gradient(135deg, #b39ddb 0%, #ce93d8 100%);
  722. color: #FFFFFF;
  723. font-size: 28rpx;
  724. font-weight: bold;
  725. display: flex;
  726. align-items: center;
  727. justify-content: center;
  728. margin-right: 20rpx;
  729. flex-shrink: 0;
  730. }
  731. .message-avatar-img {
  732. width: 60rpx;
  733. height: 60rpx;
  734. border-radius: 50%;
  735. margin-right: 20rpx;
  736. flex-shrink: 0;
  737. }
  738. .message-body {
  739. flex: 1;
  740. min-width: 0;
  741. }
  742. .message-type {
  743. display: block;
  744. font-size: 30rpx;
  745. font-weight: 500;
  746. color: #333;
  747. margin-bottom: 6rpx;
  748. }
  749. .message-content {
  750. display: block;
  751. font-size: 26rpx;
  752. color: #777;
  753. line-height: 1.4;
  754. overflow: hidden;
  755. text-overflow: ellipsis;
  756. white-space: nowrap;
  757. }
  758. .message-right {
  759. display: flex;
  760. flex-direction: column;
  761. align-items: flex-end;
  762. margin-left: 20rpx;
  763. }
  764. .message-time {
  765. font-size: 24rpx;
  766. color: #b0a6c5;
  767. margin-bottom: 10rpx;
  768. }
  769. .unread-badge {
  770. background: #ff5c9a;
  771. color: #FFFFFF;
  772. font-size: 20rpx;
  773. padding: 4rpx 10rpx;
  774. border-radius: 20rpx;
  775. min-width: 36rpx;
  776. text-align: center;
  777. }
  778. }
  779. }
  780. /* 加载和空状态 */
  781. .loading-container,
  782. .empty-container {
  783. display: flex;
  784. justify-content: center;
  785. align-items: center;
  786. padding: 100rpx 0;
  787. color: #999;
  788. font-size: 28rpx;
  789. }
  790. /* 时间分组 */
  791. .time-group {
  792. display: flex;
  793. justify-content: center;
  794. margin: 20rpx 0;
  795. .time-label {
  796. display: inline-block;
  797. background: #ffe6f0;
  798. color: #e573ab;
  799. font-size: 24rpx;
  800. padding: 8rpx 20rpx;
  801. border-radius: 20rpx;
  802. font-weight: bold;
  803. }
  804. }
  805. /* 底部导航 */
  806. .tabbar {
  807. position: fixed;
  808. bottom: 0;
  809. left: 0;
  810. right: 0;
  811. height: 100rpx;
  812. background: #FFFFFF;
  813. border-top: 1rpx solid #F0F0F0;
  814. display: flex;
  815. justify-content: space-around;
  816. align-items: center;
  817. padding-bottom: env(safe-area-inset-bottom);
  818. .tabbar-item {
  819. display: flex;
  820. flex-direction: column;
  821. align-items: center;
  822. gap: 8rpx;
  823. padding: 10rpx 0;
  824. .tabbar-icon {
  825. width: 44rpx;
  826. height: 44rpx;
  827. background-size: contain;
  828. background-repeat: no-repeat;
  829. background-position: center;
  830. position: relative;
  831. .badge {
  832. position: absolute;
  833. top: -8rpx;
  834. right: -8rpx;
  835. background: #FF4444;
  836. color: #FFFFFF;
  837. font-size: 20rpx;
  838. font-weight: bold;
  839. width: 32rpx;
  840. height: 32rpx;
  841. display: flex;
  842. align-items: center;
  843. justify-content: center;
  844. border-radius: 16rpx;
  845. }
  846. }
  847. .tabbar-text {
  848. font-size: 20rpx;
  849. color: #999;
  850. }
  851. &.active .tabbar-text {
  852. color: #9C27B0;
  853. font-weight: bold;
  854. }
  855. &.home .tabbar-icon {
  856. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>');
  857. }
  858. &.home.active .tabbar-icon {
  859. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239C27B0"><path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>');
  860. }
  861. &.resources .tabbar-icon {
  862. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"/></svg>');
  863. }
  864. &.resources.active .tabbar-icon {
  865. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239C27B0"><path d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"/></svg>');
  866. }
  867. &.trophy .tabbar-icon {
  868. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M19 5h-2V3H7v2H5c-1.1 0-2 .9-2 2v1c0 2.55 1.92 4.63 4.39 4.94.63 1.5 1.98 2.63 3.61 2.96V19H7v2h10v-2h-4v-3.1c1.63-.33 2.98-1.46 3.61-2.96C19.08 12.63 21 10.55 21 8V7c0-1.1-.9-2-2-2zM5 8V7h2v3.82C5.84 10.4 5 9.3 5 8zm14 0c0 1.3-.84 2.4-2 2.82V7h2v1z"/></svg>');
  869. }
  870. &.trophy.active .tabbar-icon {
  871. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239C27B0"><path d="M19 5h-2V3H7v2H5c-1.1 0-2 .9-2 2v1c0 2.55 1.92 4.63 4.39 4.94.63 1.5 1.98 2.63 3.61 2.96V19H7v2h10v-2h-4v-3.1c1.63-.33 2.98-1.46 3.61-2.96C19.08 12.63 21 10.55 21 8V7c0-1.1-.9-2-2-2zM5 8V7h2v3.82C5.84 10.4 5 9.3 5 8zm14 0c0 1.3-.84 2.4-2 2.82V7h2v1z"/></svg>');
  872. }
  873. &.message .tabbar-icon {
  874. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/></svg>');
  875. }
  876. &.message.active .tabbar-icon {
  877. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239C27B0"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/></svg>');
  878. }
  879. &.mine .tabbar-icon {
  880. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>');
  881. }
  882. &.mine.active .tabbar-icon {
  883. background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239C27B0"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>');
  884. }
  885. }
  886. }
  887. </style>