MessageList.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div class="flex radius-base overflow-hidden message-list-modal">
  3. <div class="message-list p-base scroll-y-auto">
  4. <div
  5. v-for="message in messageList"
  6. :key="message.id"
  7. class="radius-base fill-blank p-base m-b-mini message-item"
  8. :class="{ active: currentMessage?.sendUserId === message.sendUserId, 'un-read': message.unReadCount > 0 }"
  9. @click="checkMessage(message)"
  10. >
  11. <div class="flex items-center m-b-base message-title">
  12. <div class="message-send-user">{{ message.sendUserName }}</div>
  13. <div class="m-l-auto message-send-time">{{ dayjs(message.sendTime).format('HH:mm') }}</div>
  14. </div>
  15. <pre class="message-content" v-html="message.content"></pre>
  16. </div>
  17. </div>
  18. <div class="radius-base message-info-container">
  19. <div class="flex direction-column message-info">
  20. <div class="flex items-center p-base message-info-header">
  21. <div class="flex items-center send-user">
  22. <span class="m-r-mini">发件人</span>
  23. <span class="radius-base user-name">{{ currentMessage?.sendUserName }}</span>
  24. </div>
  25. <div class="grid pointer m-l-auto close-icon" @click="$emit('close')">
  26. <el-icon><close /></el-icon>
  27. </div>
  28. </div>
  29. <div class="flex-1 overflow-hidden p-base">
  30. <pre
  31. class="full-h radius-base p-extra-base scroll-y-auto message-info-content"
  32. @click="onContentClick"
  33. v-html="currentMessage?.content"
  34. ></pre>
  35. </div>
  36. <div class="p-base flex items-center justify-end">
  37. <el-button size="small" plain :disabled="!currentMessage" @click="toggleHistory">历史消息</el-button>
  38. <el-button size="small" type="primary" :disabled="!currentMessage" @click="onReply">回复</el-button>
  39. </div>
  40. </div>
  41. <message-history v-if="showHistory" :send-user-id="currentMessage?.sendUserId"></message-history>
  42. </div>
  43. </div>
  44. <image-preview v-model="previewModalVisible" :url="paperPath"></image-preview>
  45. </template>
  46. <script setup lang="ts" name="MessageList">
  47. /** 消息列表*/
  48. import { ref, watch } from 'vue'
  49. import { ElButton, ElIcon } from 'element-plus'
  50. import dayjs from 'dayjs'
  51. import { Close } from '@element-plus/icons-vue'
  52. import useFetch from '@/hooks/useFetch'
  53. import MessageHistory from '@/components/shared/message/MessageHistory.vue'
  54. import ImagePreview from '../ImagePreview.vue'
  55. import type { ExtractApiResponse } from '@/api/api'
  56. type MessageType = ExtractArrayValue<ExtractApiResponse<'getMessageList'>>
  57. const emits = defineEmits(['close', 'change-type', 'reply'])
  58. /** 图片预览 */
  59. const previewModalVisible = ref<boolean>(false)
  60. /** 图片路径 */
  61. const paperPath = ref<string>('')
  62. const showHistory = ref<boolean>(false)
  63. const { fetch: getMessageList, result: messageList } = useFetch('getMessageList')
  64. const currentMessage = ref<MessageType>()
  65. watch(currentMessage, () => {
  66. if (currentMessage.value) {
  67. useFetch('handleReadMessage')
  68. .fetch({ id: currentMessage.value.id })
  69. .then(() => {
  70. if (currentMessage.value?.unReadCount) {
  71. currentMessage.value.unReadCount--
  72. }
  73. })
  74. }
  75. })
  76. const checkMessage = (message: MessageType) => {
  77. currentMessage.value = message
  78. }
  79. const toggleHistory = () => {
  80. showHistory.value = !showHistory.value
  81. }
  82. const onReply = () => {
  83. if (currentMessage.value) {
  84. emits('change-type', 'send')
  85. emits('reply', currentMessage.value.sendUserId)
  86. }
  87. }
  88. const onContentClick = (e: Event) => {
  89. const target = e.target as HTMLButtonElement
  90. const path = target.getAttribute('data-path')
  91. if (path) {
  92. previewModalVisible.value = true
  93. paperPath.value = path
  94. }
  95. }
  96. getMessageList().then((result) => (currentMessage.value = result?.[0]))
  97. </script>
  98. <style scoped lang="scss">
  99. .message-list-modal {
  100. width: 880px;
  101. background-color: transparent;
  102. .message-list {
  103. width: 280px;
  104. height: 446px;
  105. background: #fafafa;
  106. box-shadow: 0px 6px 6px 0px rgba(0, 0, 0, 0.1);
  107. .message-item {
  108. &.un-read {
  109. .message-title {
  110. font-size: $MediumFont;
  111. font-weight: 900;
  112. }
  113. }
  114. &.active {
  115. background-color: $color--primary;
  116. color: $color--white;
  117. }
  118. &:not(.active) {
  119. .message-title {
  120. color: $NormalColor;
  121. .message-send-time {
  122. color: $RegularFontColor;
  123. }
  124. }
  125. .message-content {
  126. color: $RegularFontColor;
  127. }
  128. }
  129. .message-title {
  130. font-size: $BaseFont;
  131. .message-send-time {
  132. font-size: $SmallFont;
  133. font-weight: 400;
  134. }
  135. }
  136. .message-content {
  137. font-weight: 400;
  138. overflow: hidden;
  139. text-overflow: ellipsis;
  140. display: -webkit-box;
  141. -webkit-line-clamp: 2;
  142. -webkit-box-orient: vertical;
  143. font-size: $SmallFont;
  144. white-space: pre-wrap;
  145. }
  146. }
  147. }
  148. .message-info-container {
  149. width: 600px;
  150. .message-info {
  151. height: 446px;
  152. background-color: $color--white;
  153. .message-info-header {
  154. border-bottom: $OnePixelLine;
  155. .send-user {
  156. font-size: $SmallFont;
  157. color: $RegularFontColor;
  158. .user-name {
  159. display: inline-block;
  160. width: 160px;
  161. padding: 10px 12px;
  162. border: $OnePixelLine;
  163. }
  164. }
  165. .close-icon {
  166. width: 20px;
  167. height: 20px;
  168. place-items: center;
  169. font-size: 18px;
  170. color: $RegularFontColor;
  171. &:hover {
  172. color: $NormalColor;
  173. }
  174. }
  175. }
  176. .message-info-content {
  177. border: $OnePixelLine;
  178. font-size: $SmallFont;
  179. white-space: pre-wrap;
  180. }
  181. }
  182. }
  183. }
  184. </style>