NotificationBubble.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="message-row-wrap">
  3. <view v-if="showDateLabel" class="date-separator">
  4. <view class="date-line-cell">
  5. <view class="date-line" />
  6. </view>
  7. <view class="date-text-wrap">
  8. <text class="date-text">{{ dateLabel }}</text>
  9. </view>
  10. <view class="date-line-cell">
  11. <view class="date-line" />
  12. </view>
  13. </view>
  14. <view
  15. :id="'msg-' + (msg.id || msg.tempId)"
  16. class="message-row"
  17. >
  18. <!-- 左侧:应用头像 -->
  19. <view class="side-left">
  20. <view class="avatar-box">
  21. <SystemAvatar
  22. :name="appName"
  23. :size="64"
  24. unit="rpx"
  25. />
  26. </view>
  27. </view>
  28. <!-- 中间:通知卡片(绿色标题 + 白底正文 + 蓝色按钮) -->
  29. <view class="bubble notify-card">
  30. <!-- 顶部绿色标题条 -->
  31. <view class="notify-header">
  32. <text class="notify-header-text">
  33. {{ msg.title || statusText }}
  34. </text>
  35. </view>
  36. <!-- 中间白底正文 -->
  37. <view class="notify-body">
  38. <text v-if="msg.content" class="notify-content">
  39. {{ msg.content }}
  40. </text>
  41. </view>
  42. <!-- 底部蓝色按钮 -->
  43. <view v-if="msg.actionText || msg.actionUrl" class="notify-footer">
  44. <view class="notify-btn" @click="onOpenNotificationUrl">
  45. <text class="notify-btn-text">{{ msg.actionText || '打开应用' }}</text>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 右侧:占位,保持对齐 -->
  50. <view class="side-right placeholder" />
  51. </view>
  52. <view class="time-row">
  53. <text class="bubble-time">{{ timeText }}</text>
  54. </view>
  55. </view>
  56. </template>
  57. <script setup>
  58. import { computed } from 'vue'
  59. import SystemAvatar from '../SystemAvatar.vue'
  60. const props = defineProps({
  61. msg: {
  62. type: Object,
  63. required: true
  64. },
  65. senderName: {
  66. type: String,
  67. default: ''
  68. },
  69. showDateLabel: {
  70. type: Boolean,
  71. default: false
  72. }
  73. })
  74. const emit = defineEmits(['open-notification-url'])
  75. const appName = computed(() => props.msg.appName || props.msg.app_name || props.senderName || '系统通知')
  76. const dateLabel = computed(() => {
  77. const t = props.msg.createdAt || props.msg.created_at
  78. if (!t) return ''
  79. const d = new Date(t)
  80. return (d.getMonth() + 1) + '月' + d.getDate() + '日'
  81. })
  82. const timeText = computed(() => {
  83. const t = props.msg.createdAt || props.msg.created_at
  84. if (!t) return ''
  85. const d = new Date(t)
  86. const h = d.getHours()
  87. const m = String(d.getMinutes()).padStart(2, '0')
  88. const month = d.getMonth() + 1
  89. const day = d.getDate()
  90. return month + '月' + day + '日 ' + h + ':' + m
  91. })
  92. const statusText = computed(() => {
  93. return props.msg.statusText || '应用审批通过,已发布成功'
  94. })
  95. function onOpenNotificationUrl() {
  96. emit('open-notification-url', props.msg)
  97. }
  98. </script>
  99. <style scoped>
  100. .message-row-wrap {
  101. width: 100%;
  102. margin-bottom: 28rpx;
  103. }
  104. .date-separator {
  105. display: flex;
  106. flex-direction: row;
  107. align-items: center;
  108. width: 100%;
  109. box-sizing: border-box;
  110. margin-bottom: 24rpx;
  111. }
  112. .date-line-cell {
  113. flex: 1 1 0%;
  114. min-width: 0;
  115. display: flex;
  116. align-items: center;
  117. }
  118. .date-line {
  119. width: 100%;
  120. height: 1rpx;
  121. background: rgba(148, 163, 184, 0.4);
  122. }
  123. .date-text-wrap {
  124. flex: 0 0 auto;
  125. max-width: 100%;
  126. margin: 0 20rpx;
  127. }
  128. .date-text {
  129. font-size: 24rpx;
  130. color: #9ca3af;
  131. padding: 6rpx 16rpx;
  132. border-radius: 999rpx;
  133. background: rgba(15, 23, 42, 0.04);
  134. }
  135. .message-row {
  136. display: flex;
  137. align-items: flex-start;
  138. justify-content: center;
  139. padding: 0 24rpx;
  140. gap: 12rpx;
  141. }
  142. .side-left {
  143. flex-shrink: 0;
  144. width: 72rpx;
  145. display: flex;
  146. justify-content: center;
  147. align-items: flex-start;
  148. }
  149. .side-right {
  150. flex-shrink: 0;
  151. width: 72rpx;
  152. display: flex;
  153. justify-content: center;
  154. align-items: flex-start;
  155. }
  156. .avatar-box {
  157. width: 64rpx;
  158. height: 64rpx;
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. }
  163. .bubble {
  164. width: 560rpx;
  165. max-width: calc(100% - 72rpx - 72rpx - 12rpx - 12rpx);
  166. min-width: 88rpx;
  167. border-radius: 18rpx;
  168. box-shadow: 0 4rpx 10rpx rgba(15, 23, 42, 0.06);
  169. background-color: #ffffff;
  170. overflow: hidden;
  171. flex-shrink: 1;
  172. }
  173. .notify-card {
  174. padding: 0;
  175. }
  176. .notify-header {
  177. background-color: #bbf7d0;
  178. padding: 16rpx 20rpx;
  179. }
  180. .notify-header-text {
  181. font-size: 26rpx;
  182. color: #166534;
  183. font-weight: 600;
  184. }
  185. .notify-body {
  186. padding: 20rpx 20rpx 8rpx;
  187. }
  188. .notify-content {
  189. font-size: 26rpx;
  190. color: #111827;
  191. line-height: 1.5;
  192. }
  193. .notify-footer {
  194. padding: 12rpx 20rpx 20rpx;
  195. }
  196. .notify-btn {
  197. width: 100%;
  198. height: 72rpx;
  199. border-radius: 12rpx;
  200. border-width: 2rpx;
  201. border-style: solid;
  202. border-color: #1677ff;
  203. background-color: #ffffff;
  204. display: flex;
  205. align-items: center;
  206. justify-content: center;
  207. }
  208. .notify-btn-text {
  209. font-size: 28rpx;
  210. color: #1677ff;
  211. }
  212. .time-row {
  213. margin-top: 6rpx;
  214. display: flex;
  215. justify-content: center;
  216. }
  217. .bubble-time {
  218. font-size: 22rpx;
  219. color: #9ca3af;
  220. }
  221. </style>