message.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  6. <title>消息</title>
  7. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  14. }
  15. body {
  16. background-color: #f5f5f5;
  17. color: #333;
  18. font-size: 14px;
  19. line-height: 1.5;
  20. max-width: 100vw;
  21. overflow-x: hidden;
  22. }
  23. .container {
  24. width: 100%;
  25. max-width: 375px;
  26. margin: 0 auto;
  27. background-color: #fff;
  28. min-height: 100vh;
  29. position: relative;
  30. padding-bottom: 60px;
  31. }
  32. /* 状态栏 */
  33. .status-bar {
  34. height: 44px;
  35. background-color: #fff;
  36. display: flex;
  37. align-items: center;
  38. justify-content: center;
  39. position: relative;
  40. border-bottom: 1px solid #eee;
  41. }
  42. .status-bar .title {
  43. font-size: 17px;
  44. font-weight: 600;
  45. color: #000;
  46. }
  47. .status-bar .action {
  48. position: absolute;
  49. right: 15px;
  50. color: #3478f6;
  51. font-size: 15px;
  52. }
  53. /* 消息列表 */
  54. .message-list {
  55. flex: 1;
  56. overflow-y: auto;
  57. -webkit-overflow-scrolling: touch;
  58. padding-bottom: 60px;
  59. }
  60. .message-item {
  61. display: flex;
  62. padding: 12px 15px;
  63. background-color: #fff;
  64. border-bottom: 1px solid #f0f0f0;
  65. position: relative;
  66. }
  67. .message-item.unread {
  68. background-color: #f9f9f9;
  69. }
  70. .message-avatar {
  71. width: 44px;
  72. height: 44px;
  73. border-radius: 6px;
  74. margin-right: 12px;
  75. flex-shrink: 0;
  76. display: flex;
  77. align-items: center;
  78. justify-content: center;
  79. background-color: #f0f0f0;
  80. color: #999;
  81. font-size: 20px;
  82. }
  83. .message-content {
  84. flex: 1;
  85. min-width: 0;
  86. }
  87. .message-header {
  88. display: flex;
  89. justify-content: space-between;
  90. margin-bottom: 4px;
  91. }
  92. .message-sender {
  93. font-weight: 600;
  94. font-size: 16px;
  95. color: #333;
  96. white-space: nowrap;
  97. overflow: hidden;
  98. text-overflow: ellipsis;
  99. max-width: 60%;
  100. }
  101. .message-time {
  102. font-size: 12px;
  103. color: #999;
  104. }
  105. .message-preview {
  106. font-size: 14px;
  107. color: #666;
  108. white-space: nowrap;
  109. overflow: hidden;
  110. text-overflow: ellipsis;
  111. }
  112. .unread-badge {
  113. position: absolute;
  114. right: 15px;
  115. top: 50%;
  116. transform: translateY(-50%);
  117. width: 8px;
  118. height: 8px;
  119. border-radius: 50%;
  120. background-color: #f44336;
  121. }
  122. .official-tag {
  123. display: inline-block;
  124. padding: 1px 4px;
  125. background-color: #3478f6;
  126. color: #fff;
  127. border-radius: 2px;
  128. font-size: 10px;
  129. margin-left: 4px;
  130. transform: translateY(-1px);
  131. }
  132. /* 底部导航栏 - 使用"我的"页面样式 */
  133. .bottom-nav {
  134. position: fixed;
  135. bottom: 0;
  136. left: 0;
  137. right: 0;
  138. background-color: white;
  139. display: flex;
  140. justify-content: space-around;
  141. padding: 8px 0;
  142. box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  143. max-width: 375px;
  144. margin: 0 auto;
  145. }
  146. .nav-item {
  147. display: flex;
  148. flex-direction: column;
  149. align-items: center;
  150. color: #666;
  151. text-decoration: none;
  152. font-size: 12px;
  153. }
  154. .nav-icon {
  155. font-size: 22px;
  156. margin-bottom: 3px;
  157. }
  158. .nav-item.active {
  159. color: #1971c2;
  160. }
  161. /* 弹窗 */
  162. .modal {
  163. position: fixed;
  164. top: 0;
  165. left: 0;
  166. right: 0;
  167. bottom: 0;
  168. background-color: rgba(0, 0, 0, 0.5);
  169. display: flex;
  170. align-items: center;
  171. justify-content: center;
  172. z-index: 1000;
  173. display: none;
  174. }
  175. .modal-content {
  176. background-color: #fff;
  177. width: 80%;
  178. max-width: 300px;
  179. border-radius: 12px;
  180. overflow: hidden;
  181. animation: modalFadeIn 0.3s;
  182. }
  183. .modal-body {
  184. padding: 20px;
  185. text-align: center;
  186. font-size: 16px;
  187. line-height: 1.4;
  188. }
  189. .modal-footer {
  190. display: flex;
  191. border-top: 1px solid #eee;
  192. }
  193. .modal-button {
  194. flex: 1;
  195. padding: 12px;
  196. text-align: center;
  197. color: #666;
  198. font-size: 16px;
  199. }
  200. .modal-button.primary {
  201. color: #3478f6;
  202. font-weight: 600;
  203. border-left: 1px solid #eee;
  204. }
  205. @keyframes modalFadeIn {
  206. from {
  207. opacity: 0;
  208. transform: translateY(20px);
  209. }
  210. to {
  211. opacity: 1;
  212. transform: translateY(0);
  213. }
  214. }
  215. </style>
  216. </head>
  217. <body>
  218. <div class="container">
  219. <!-- 状态栏 -->
  220. <div class="status-bar">
  221. <div class="title">消息</div>
  222. <div class="action" id="markAllRead">全部已读</div>
  223. </div>
  224. <!-- 消息列表 -->
  225. <div class="message-list">
  226. <!-- 订单消息 -->
  227. <div class="message-item unread" data-id="1">
  228. <div class="message-avatar">
  229. <i class="bi bi-receipt"></i>
  230. </div>
  231. <div class="message-content">
  232. <div class="message-header">
  233. <div class="message-sender">订单消息</div>
  234. <div class="message-time">3分钟前</div>
  235. </div>
  236. <div class="message-preview">你的订单已完结</div>
  237. </div>
  238. <div class="unread-badge"></div>
  239. </div>
  240. <!-- 互动消息 -->
  241. <div class="message-item unread" data-id="2">
  242. <div class="message-avatar">
  243. <i class="bi bi-chat-left-text"></i>
  244. </div>
  245. <div class="message-content">
  246. <div class="message-header">
  247. <div class="message-sender">互动消息</div>
  248. <div class="message-time">5小时前</div>
  249. </div>
  250. <div class="message-preview">@用户1008600评论了你的内容</div>
  251. </div>
  252. <div class="unread-badge"></div>
  253. </div>
  254. <!-- 系统消息 -->
  255. <div class="message-item unread" data-id="3">
  256. <div class="message-avatar">
  257. <i class="bi bi-gear"></i>
  258. </div>
  259. <div class="message-content">
  260. <div class="message-header">
  261. <div class="message-sender">系统消息 <span class="official-tag">官方</span></div>
  262. <div class="message-time">23小时前</div>
  263. </div>
  264. <div class="message-preview">你提交的个人信息审核通过</div>
  265. </div>
  266. <div class="unread-badge"></div>
  267. </div>
  268. <!-- 用户消息1 -->
  269. <div class="message-item unread" data-id="4">
  270. <div class="message-avatar">
  271. <i class="bi bi-person"></i>
  272. </div>
  273. <div class="message-content">
  274. <div class="message-header">
  275. <div class="message-sender">果汁分你一半</div>
  276. <div class="message-time">2天前</div>
  277. </div>
  278. <div class="message-preview">[游记消息]</div>
  279. </div>
  280. <div class="unread-badge"></div>
  281. </div>
  282. <!-- 用户消息2 -->
  283. <div class="message-item" data-id="5">
  284. <div class="message-avatar">
  285. <i class="bi bi-person"></i>
  286. </div>
  287. <div class="message-content">
  288. <div class="message-header">
  289. <div class="message-sender">飞来飞去</div>
  290. <div class="message-time">1周前</div>
  291. </div>
  292. <div class="message-preview">老炮来北京玩啊~</div>
  293. </div>
  294. </div>
  295. </div>
  296. <!-- 底部导航栏 - 使用"我的"页面样式 -->
  297. <div class="bottom-nav">
  298. <a href="#" class="nav-item">
  299. <i class="bi bi-house-door nav-icon"></i>
  300. <span>首页</span>
  301. </a>
  302. <a href="#" class="nav-item">
  303. <i class="bi bi-robot nav-icon"></i>
  304. <span>客服</span>
  305. </a>
  306. <a href="#" class="nav-item active">
  307. <i class="bi bi-chat-dots nav-icon"></i>
  308. <span>消息</span>
  309. <span style="position: absolute; top: 2px; right: 20px; background-color: red; width: 8px; height: 8px; border-radius: 50%;"></span>
  310. </a>
  311. <a href="#" class="nav-item">
  312. <i class="bi bi-person nav-icon"></i>
  313. <span>我的</span>
  314. </a>
  315. </div>
  316. </div>
  317. <!-- 全部已读弹窗 -->
  318. <div class="modal" id="confirmModal">
  319. <div class="modal-content">
  320. <div class="modal-body">
  321. 标记所有消息为已读?
  322. </div>
  323. <div class="modal-footer">
  324. <div class="modal-button" id="cancelBtn">取消</div>
  325. <div class="modal-button primary" id="confirmBtn">确定</div>
  326. </div>
  327. </div>
  328. </div>
  329. <script>
  330. document.addEventListener('DOMContentLoaded', function() {
  331. // 点击消息项
  332. const messageItems = document.querySelectorAll('.message-item');
  333. messageItems.forEach(item => {
  334. item.addEventListener('click', function() {
  335. if (this.classList.contains('unread')) {
  336. this.classList.remove('unread');
  337. const badge = this.querySelector('.unread-badge');
  338. if (badge) badge.remove();
  339. // 检查是否还有未读消息
  340. updateUnreadStatus();
  341. }
  342. // 这里可以添加跳转到具体消息详情的逻辑
  343. });
  344. });
  345. // 全部已读按钮
  346. const markAllReadBtn = document.getElementById('markAllRead');
  347. const confirmModal = document.getElementById('confirmModal');
  348. const cancelBtn = document.getElementById('cancelBtn');
  349. const confirmBtn = document.getElementById('confirmBtn');
  350. markAllReadBtn.addEventListener('click', function() {
  351. confirmModal.style.display = 'flex';
  352. });
  353. cancelBtn.addEventListener('click', function() {
  354. confirmModal.style.display = 'none';
  355. });
  356. confirmBtn.addEventListener('click', function() {
  357. // 移除所有未读标记
  358. document.querySelectorAll('.message-item.unread').forEach(item => {
  359. item.classList.remove('unread');
  360. const badge = item.querySelector('.unread-badge');
  361. if (badge) badge.remove();
  362. });
  363. // 更新未读状态
  364. updateUnreadStatus();
  365. confirmModal.style.display = 'none';
  366. });
  367. // 点击模态框外部关闭
  368. confirmModal.addEventListener('click', function(e) {
  369. if (e.target === this) {
  370. this.style.display = 'none';
  371. }
  372. });
  373. // 更新未读状态
  374. function updateUnreadStatus() {
  375. const unreadCount = document.querySelectorAll('.message-item.unread').length;
  376. const navBadge = document.querySelector('.nav-item.active span[style]');
  377. if (unreadCount === 0 && navBadge) {
  378. navBadge.remove();
  379. } else if (unreadCount > 0 && !navBadge) {
  380. // 如果还有未读消息但底部导航没有红点,则添加红点
  381. const navMessage = document.querySelector('.nav-item.active');
  382. const badge = document.createElement('span');
  383. badge.style.position = 'absolute';
  384. badge.style.top = '2px';
  385. badge.style.right = '20px';
  386. badge.style.backgroundColor = 'red';
  387. badge.style.width = '8px';
  388. badge.style.height = '8px';
  389. badge.style.borderRadius = '50%';
  390. navMessage.appendChild(badge);
  391. }
  392. }
  393. });
  394. </script>
  395. </body>
  396. </html>