index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. uni.showToast({ title: err.message || err.msg || '请求失败', icon: 'none' });
  102. }
  103. },
  104. navBack() {
  105. uni.navigateBack();
  106. },
  107. navToOrderMsg() {
  108. uni.navigateTo({
  109. url: '/pages/mine/message/order/index'
  110. });
  111. },
  112. navToSystemMsg() {
  113. uni.navigateTo({
  114. url: '/pages/mine/message/system/index'
  115. });
  116. }
  117. }
  118. }
  119. </script>
  120. <style>
  121. page {
  122. background-color: #fff;
  123. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  124. }
  125. .nav-bar {
  126. position: fixed;
  127. top: 0;
  128. left: 0;
  129. width: 100%;
  130. height: 88rpx;
  131. padding-top: var(--status-bar-height);
  132. background-color: #fff;
  133. display: flex;
  134. align-items: center;
  135. justify-content: space-between;
  136. padding: 0 30rpx;
  137. padding-top: var(--status-bar-height);
  138. /* Ensure padding top includes status bar */
  139. box-sizing: border-box;
  140. z-index: 100;
  141. border-bottom: 1rpx solid #f5f5f5;
  142. }
  143. .nav-placeholder {
  144. height: calc(88rpx + var(--status-bar-height));
  145. }
  146. .back-icon {
  147. width: 40rpx;
  148. height: 40rpx;
  149. }
  150. .nav-title {
  151. font-size: 34rpx;
  152. font-weight: bold;
  153. color: #333;
  154. }
  155. .nav-right {
  156. width: 40rpx;
  157. display: flex;
  158. justify-content: flex-end;
  159. }
  160. .more-dots {
  161. display: flex;
  162. gap: 4rpx;
  163. }
  164. .dot {
  165. width: 6rpx;
  166. height: 6rpx;
  167. background-color: #333;
  168. border-radius: 50%;
  169. }
  170. .message-list {
  171. padding: 0 30rpx;
  172. }
  173. .message-item {
  174. display: flex;
  175. align-items: center;
  176. padding: 30rpx 0;
  177. border-bottom: 1rpx solid #f5f5f5;
  178. }
  179. .icon-wrapper {
  180. position: relative;
  181. margin-right: 30rpx;
  182. }
  183. .msg-icon {
  184. width: 96rpx;
  185. height: 96rpx;
  186. border-radius: 50%;
  187. }
  188. .red-dot-badge {
  189. position: absolute;
  190. top: 0;
  191. right: 0;
  192. width: 16rpx;
  193. height: 16rpx;
  194. background-color: #FF3B30;
  195. border-radius: 50%;
  196. border: 2rpx solid #fff;
  197. }
  198. .content-wrapper {
  199. flex: 1;
  200. display: flex;
  201. flex-direction: column;
  202. }
  203. .top-row {
  204. display: flex;
  205. justify-content: space-between;
  206. align-items: center;
  207. margin-bottom: 10rpx;
  208. }
  209. .msg-title {
  210. font-size: 28rpx;
  211. font-weight: bold;
  212. color: #333;
  213. }
  214. .msg-time {
  215. font-size: 24rpx;
  216. color: #999;
  217. }
  218. .msg-preview {
  219. font-size: 26rpx;
  220. color: #666;
  221. overflow: hidden;
  222. white-space: nowrap;
  223. text-overflow: ellipsis;
  224. width: 500rpx;
  225. }
  226. </style>