NotificationBubble.vue 4.7 KB

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