index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="container">
  3. <!-- 自定义导航栏 -->
  4. <view class="nav-bar">
  5. <view class="nav-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);">
  7. </image>
  8. </view>
  9. <text class="nav-title">消息中心</text>
  10. <view class="nav-right">
  11. <view class="more-dots">
  12. <view class="dot"></view>
  13. <view class="dot"></view>
  14. <view class="dot"></view>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="nav-placeholder"></view>
  19. <!-- 消息分类列表 -->
  20. <view class="message-list">
  21. <!-- 订单消息 -->
  22. <view class="message-item" @click="navToOrderMsg">
  23. <view class="icon-wrapper">
  24. <image class="msg-icon" src="/static/icons/icon_order_msg.svg"></image>
  25. <view class="red-dot-badge" v-if="orderUnread > 0"></view>
  26. </view>
  27. <view class="content-wrapper">
  28. <view class="top-row">
  29. <text class="msg-title">订单消息</text>
  30. <text class="msg-time" v-if="latestOrderMsg">{{ formatTime(latestOrderMsg.createTime) }}</text>
  31. </view>
  32. <text class="msg-preview text-ellipsis">{{ latestOrderMsg ? latestOrderMsg.content : '暂无新订单消息' }}</text>
  33. </view>
  34. </view>
  35. <!-- 系统消息 -->
  36. <view class="message-item" @click="navToSystemMsg">
  37. <view class="icon-wrapper">
  38. <image class="msg-icon" src="/static/icons/icon_system_msg.svg"></image>
  39. <view class="red-dot-badge" v-if="systemUnread > 0"></view>
  40. </view>
  41. <view class="content-wrapper">
  42. <view class="top-row">
  43. <text class="msg-title">系统消息</text>
  44. <text class="msg-time" v-if="latestSystemMsg">{{ formatTime(latestSystemMsg.createTime) }}</text>
  45. </view>
  46. <text class="msg-preview text-ellipsis">{{ latestSystemMsg ? latestSystemMsg.content : '暂无新系统消息' }}</text>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import { listMyNotice } from '@/api/system/notice'
  54. import { formatTime } from '@/utils/index'
  55. export default {
  56. data() {
  57. return {
  58. orderUnread: 0,
  59. systemUnread: 0,
  60. latestOrderMsg: null,
  61. latestSystemMsg: null
  62. }
  63. },
  64. onShow() {
  65. this.loadMessageSummary();
  66. },
  67. methods: {
  68. formatTime,
  69. async loadMessageSummary() {
  70. try {
  71. // 加载订单消息概览 (type=0)
  72. const orderRes = await listMyNotice({
  73. type: 0,
  74. pageNum: 1,
  75. pageSize: 1
  76. });
  77. this.latestOrderMsg = orderRes.rows && orderRes.rows.length > 0 ? orderRes.rows[0] : null;
  78. const orderUnreadRes = await listMyNotice({
  79. type: 0,
  80. readFlag: false,
  81. pageNum: 1,
  82. pageSize: 1
  83. });
  84. this.orderUnread = Number(orderUnreadRes.total) || 0;
  85. // 加载系统消息概览 (type=1) - 假设系统消息是1
  86. const systemRes = await listMyNotice({
  87. type: 1,
  88. pageNum: 1,
  89. pageSize: 1
  90. });
  91. this.latestSystemMsg = systemRes.rows && systemRes.rows.length > 0 ? systemRes.rows[0] : null;
  92. const systemUnreadRes = await listMyNotice({
  93. type: 1,
  94. readFlag: false,
  95. pageNum: 1,
  96. pageSize: 1
  97. });
  98. this.systemUnread = Number(systemUnreadRes.total) || 0;
  99. } catch (err) {
  100. console.error('加载消息概览失败:', err);
  101. }
  102. },
  103. navBack() {
  104. uni.navigateBack();
  105. },
  106. navToOrderMsg() {
  107. uni.navigateTo({
  108. url: '/pages/mine/message/order/index'
  109. });
  110. },
  111. navToSystemMsg() {
  112. uni.navigateTo({
  113. url: '/pages/mine/message/system/index'
  114. });
  115. }
  116. }
  117. }
  118. </script>
  119. <style>
  120. page {
  121. background-color: #fff;
  122. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  123. }
  124. .nav-bar {
  125. position: fixed;
  126. top: 0;
  127. left: 0;
  128. width: 100%;
  129. height: 88rpx;
  130. padding-top: var(--status-bar-height);
  131. background-color: #fff;
  132. display: flex;
  133. align-items: center;
  134. justify-content: space-between;
  135. padding: 0 30rpx;
  136. padding-top: var(--status-bar-height);
  137. /* Ensure padding top includes status bar */
  138. box-sizing: border-box;
  139. z-index: 100;
  140. border-bottom: 1rpx solid #f5f5f5;
  141. }
  142. .nav-placeholder {
  143. height: calc(88rpx + var(--status-bar-height));
  144. }
  145. .back-icon {
  146. width: 40rpx;
  147. height: 40rpx;
  148. }
  149. .nav-title {
  150. font-size: 34rpx;
  151. font-weight: bold;
  152. color: #333;
  153. }
  154. .nav-right {
  155. width: 40rpx;
  156. display: flex;
  157. justify-content: flex-end;
  158. }
  159. .more-dots {
  160. display: flex;
  161. gap: 4rpx;
  162. }
  163. .dot {
  164. width: 6rpx;
  165. height: 6rpx;
  166. background-color: #333;
  167. border-radius: 50%;
  168. }
  169. .message-list {
  170. padding: 0 30rpx;
  171. }
  172. .message-item {
  173. display: flex;
  174. align-items: center;
  175. padding: 30rpx 0;
  176. border-bottom: 1rpx solid #f5f5f5;
  177. }
  178. .icon-wrapper {
  179. position: relative;
  180. margin-right: 30rpx;
  181. }
  182. .msg-icon {
  183. width: 96rpx;
  184. height: 96rpx;
  185. border-radius: 50%;
  186. }
  187. .red-dot-badge {
  188. position: absolute;
  189. top: 0;
  190. right: 0;
  191. width: 16rpx;
  192. height: 16rpx;
  193. background-color: #FF3B30;
  194. border-radius: 50%;
  195. border: 2rpx solid #fff;
  196. }
  197. .content-wrapper {
  198. flex: 1;
  199. display: flex;
  200. flex-direction: column;
  201. }
  202. .top-row {
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. margin-bottom: 10rpx;
  207. }
  208. .msg-title {
  209. font-size: 28rpx;
  210. font-weight: bold;
  211. color: #333;
  212. }
  213. .msg-time {
  214. font-size: 24rpx;
  215. color: #999;
  216. }
  217. .msg-preview {
  218. font-size: 26rpx;
  219. color: #666;
  220. overflow: hidden;
  221. white-space: nowrap;
  222. text-overflow: ellipsis;
  223. width: 500rpx;
  224. }
  225. </style>