NotifyMessageRender.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view :id="`auchor${source.clientMsgID}`" class="message_item">
  3. <view class="message_container">
  4. <view class="es x-start">
  5. <my-avatar size="24" :desc="source.senderNickname" style="margin-left: 20rpx;" shape="circle" src="/static/logo.png" />
  6. <view class="message_sender">
  7. <text>{{ source.senderNickname }}</text>
  8. </view>
  9. </view>
  10. <view class="line"></view>
  11. <view class="message_content_wrap">
  12. <view class="notify_message_container">
  13. <!-- <view class="notify_title">
  14. {{ notifyContent.notificationName }}
  15. </view> -->
  16. <view v-if="getMediaSource" class="media_container" @click="preview">
  17. <u--image radius="4" :showLoading="true" :src="getMediaSource" width="220" height="100%" mode="widthFix"></u--image>
  18. <image v-if="isVideo" class="play_icon" src="../../../static/images/chating_message_video_play.png" alt="" srcset="" />
  19. <text v-if="isVideo" class="video_duration">{{ getDuration }}</text>
  20. </view>
  21. <view class="notify_text">
  22. {{ notifyContent.text }}
  23. </view>
  24. <view v-if="hasExternalUrl" class="href" @click="toWebView">点击查看</view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import { myPreview } from '../../../util/preview';
  32. import MyAvatar from '../../../components/MyAvatar/index.vue';
  33. import { formatMessageTime, secFormat } from '../../../util/imCommon';
  34. const NotificationMixTypes = {
  35. Text: 0,
  36. TextAndImage: 1,
  37. TextAndVideo: 2,
  38. TextAndFile: 3
  39. };
  40. export default {
  41. name: 'NotifyMessageRender',
  42. components: {
  43. MyAvatar
  44. },
  45. props: {
  46. source: Object
  47. },
  48. data() {
  49. return {};
  50. },
  51. computed: {
  52. notifyContent() {
  53. let notificationContent = {};
  54. try {
  55. notificationContent = JSON.parse(this.source.notificationElem.detail);
  56. } catch (e) {
  57. //TODO handle the exception
  58. }
  59. return notificationContent;
  60. },
  61. isVideo() {
  62. return this.notifyContent.mixType === NotificationMixTypes.TextAndVideo;
  63. },
  64. hasExternalUrl() {
  65. return this.notifyContent.externalUrl;
  66. },
  67. getDuration() {
  68. if (!this.isVideo) {
  69. return 0;
  70. }
  71. return secFormat(this.notifyContent.videoElem.duration);
  72. },
  73. formattedMessageTime() {
  74. return formatMessageTime(this.source.sendTime);
  75. },
  76. getMediaSource() {
  77. if (this.notifyContent.mixType === NotificationMixTypes.TextAndImage) {
  78. const picEl = this.notifyContent.pictureElem;
  79. return picEl.snapshotPicture?.url ?? picEl.sourcePicture?.url;
  80. }
  81. if (this.notifyContent.mixType === NotificationMixTypes.TextAndVideo) {
  82. const videoEl = this.notifyContent.videoElem;
  83. return videoEl.snapshotUrl;
  84. }
  85. return '';
  86. }
  87. },
  88. methods: {
  89. toWebView() {
  90. uni.navigateTo({
  91. url: `/pages/common/webviewWrapper/index?url=${this.notifyContent.externalUrl}`
  92. });
  93. },
  94. preview() {
  95. if (this.notifyContent.mixType === NotificationMixTypes.TextAndVideo) {
  96. uni.navigateTo({
  97. url: `/pages/conversation/previewVideo/index?previewVideoUrl=${this.notifyContent.videoElem.videoUrl}&snapshotUrl=${this.notifyContent.videoElem.snapshotUrl}`
  98. });
  99. return;
  100. }
  101. if (this.notifyContent.mixType === NotificationMixTypes.TextAndImage) {
  102. const picEl = this.notifyContent.pictureElem;
  103. const url = picEl.SourcePicture?.Url ?? picEl.sourcePicture?.url;
  104. if (url) {
  105. // uni.previewImage({
  106. // urls: [url],
  107. // });
  108. myPreview(0, [url]);
  109. }
  110. }
  111. }
  112. }
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. .message_item {
  117. display: flex;
  118. flex-direction: row;
  119. margin: 10rpx 24rpx;
  120. padding-bottom: 32rpx;
  121. background-color: #fff;
  122. border-radius: 12rpx;
  123. .message_container {
  124. margin-top: 20rpx;
  125. margin-left: 12rpx;
  126. text-align: start;
  127. width: 100%;
  128. position: relative;
  129. .line{
  130. margin:20rpx;
  131. border: 1rpx solid #f7f7f7
  132. }
  133. .message_sender {
  134. @include nomalEllipsis();
  135. max-width: 480rpx;
  136. font-size: 13px;
  137. color: #666;
  138. margin-bottom: 6rpx;
  139. margin-left: 10rpx;
  140. }
  141. .message_content_wrap {
  142. @include vCenterBox();
  143. text-align: start;
  144. font-size: 14px;
  145. color: $uni-text-color;
  146. width: fit-content;
  147. width: 100%;
  148. .notify_message_container {
  149. padding: 0rpx 16rpx;
  150. }
  151. .notify_title {
  152. font-size: 16px;
  153. margin-bottom: 12rpx;
  154. }
  155. .notify_text {
  156. font-size: 14px;
  157. }
  158. .media_container {
  159. position: relative;
  160. margin-bottom: 10rpx;
  161. padding-bottom: 24rpx;
  162. border-bottom: 1px solid #ccc;
  163. }
  164. .play_icon {
  165. width: 48px;
  166. height: 48px;
  167. position: absolute;
  168. top: 50%;
  169. left: 50%;
  170. transform: translate(-50%, -50%);
  171. }
  172. .video_duration {
  173. position: absolute;
  174. bottom: 32rpx;
  175. right: 18rpx;
  176. color: #fff;
  177. }
  178. .href {
  179. margin-top: 4rpx;
  180. color: #0289fa;
  181. }
  182. }
  183. }
  184. }
  185. </style>