KeFuChatBox.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <el-container v-if="showChatBox" class="kefu">
  3. <el-header>
  4. <div class="kefu-title">{{ keFuConversation.userNickname }}</div>
  5. </el-header>
  6. <el-main class="kefu-content">
  7. <div
  8. v-for="item in messageList"
  9. :key="item.id"
  10. :class="[
  11. item.senderType === UserTypeEnum.MEMBER
  12. ? `ss-row-left`
  13. : item.senderType === UserTypeEnum.ADMIN
  14. ? `ss-row-right`
  15. : ''
  16. ]"
  17. class="flex mb-20px w-[100%]"
  18. >
  19. <el-avatar
  20. v-show="item.senderType === UserTypeEnum.MEMBER"
  21. :src="keFuConversation.userAvatar"
  22. alt="avatar"
  23. />
  24. <div class="kefu-message flex items-center p-10px">
  25. <!-- 文本消息 -->
  26. <template v-if="KeFuMessageContentTypeEnum.TEXT === item.contentType">
  27. <div
  28. v-dompurify-html="replaceEmoji(item.content)"
  29. :class="[
  30. item.senderType === UserTypeEnum.MEMBER
  31. ? `ml-10px`
  32. : item.senderType === UserTypeEnum.ADMIN
  33. ? `mr-10px`
  34. : ''
  35. ]"
  36. ></div>
  37. </template>
  38. <template v-else>
  39. {{ item.content }}
  40. </template>
  41. </div>
  42. <el-avatar
  43. v-show="item.senderType === UserTypeEnum.ADMIN"
  44. :src="item.senderAvatar"
  45. alt="avatar"
  46. />
  47. </div>
  48. </el-main>
  49. <!-- TODO puhui999: 发送下次提交完善 -->
  50. <el-footer height="230px">
  51. <div class="h-[100%]">
  52. <div class="chat-tools">
  53. <Icon :size="30" class="ml-10px" icon="fa:frown-o" />
  54. </div>
  55. <el-input v-model="message" :rows="6" type="textarea" />
  56. <div class="h-45px flex justify-end">
  57. <el-button class="mt-10px" type="primary">发送</el-button>
  58. </div>
  59. </div>
  60. </el-footer>
  61. </el-container>
  62. <el-empty v-else description="请选择左侧的一个会话后开始" />
  63. </template>
  64. <script lang="ts" setup>
  65. import { KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
  66. import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
  67. import { UserTypeEnum } from '@/utils/constants'
  68. import { replaceEmoji } from '@/views/mall/promotion/kefu/components/emoji'
  69. import { KeFuMessageContentTypeEnum } from '@/views/mall/promotion/kefu/components/constants'
  70. import { isEmpty } from '@/utils/is'
  71. defineOptions({ name: 'KeFuMessageBox' })
  72. const message = ref('') // 消息
  73. const messageList = ref<KeFuMessageRespVO[]>([]) // 消息列表
  74. const keFuConversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) // 用户会话
  75. // 获得消息
  76. const getMessageList = async (conversation: KeFuConversationRespVO) => {
  77. keFuConversation.value = conversation
  78. // const { list } = await KeFuMessageApi.getKeFuMessagePage({
  79. // pageNo: 1,
  80. // conversationId: conversation.id
  81. // })
  82. // TODO puhui999: 方便查看效果
  83. const list = [
  84. {
  85. id: 19,
  86. conversationId: 1,
  87. senderId: 283,
  88. senderAvatar: null,
  89. senderType: 2,
  90. receiverId: null,
  91. receiverType: null,
  92. contentType: 1,
  93. content: '[爱心][爱心][坏笑][坏笑][天使][天使]',
  94. readStatus: false,
  95. createTime: 1718616705000
  96. },
  97. {
  98. id: 18,
  99. conversationId: 1,
  100. senderId: 283,
  101. senderAvatar: null,
  102. senderType: 1,
  103. receiverId: null,
  104. receiverType: null,
  105. contentType: 1,
  106. content: '[瞌睡][瞌睡]',
  107. readStatus: false,
  108. createTime: 1718616690000
  109. },
  110. {
  111. id: 17,
  112. conversationId: 1,
  113. senderId: 283,
  114. senderAvatar: null,
  115. senderType: 1,
  116. receiverId: null,
  117. receiverType: null,
  118. contentType: 1,
  119. content: '[冷酷][冷酷]',
  120. readStatus: false,
  121. createTime: 1718616350000
  122. },
  123. {
  124. id: 16,
  125. conversationId: 1,
  126. senderId: 283,
  127. senderAvatar: null,
  128. senderType: 1,
  129. receiverId: null,
  130. receiverType: null,
  131. contentType: 1,
  132. content: '[天使]',
  133. readStatus: false,
  134. createTime: 1718615505000
  135. },
  136. {
  137. id: 15,
  138. conversationId: 1,
  139. senderId: 283,
  140. senderAvatar: null,
  141. senderType: 2,
  142. receiverId: null,
  143. receiverType: null,
  144. contentType: 1,
  145. content: '[天使]',
  146. readStatus: false,
  147. createTime: 1718615485000
  148. },
  149. {
  150. id: 14,
  151. conversationId: 1,
  152. senderId: 283,
  153. senderAvatar: null,
  154. senderType: 2,
  155. receiverId: null,
  156. receiverType: null,
  157. contentType: 1,
  158. content: '[心碎][心碎]',
  159. readStatus: false,
  160. createTime: 1718615453000
  161. },
  162. {
  163. id: 13,
  164. conversationId: 1,
  165. senderId: 283,
  166. senderAvatar: null,
  167. senderType: 2,
  168. receiverId: null,
  169. receiverType: null,
  170. contentType: 1,
  171. content: '[心碎][心碎]',
  172. readStatus: false,
  173. createTime: 1718615430000
  174. },
  175. {
  176. id: 12,
  177. conversationId: 1,
  178. senderId: 283,
  179. senderAvatar: null,
  180. senderType: 1,
  181. receiverId: null,
  182. receiverType: null,
  183. contentType: 1,
  184. content: '[心碎][心碎]',
  185. readStatus: false,
  186. createTime: 1718615425000
  187. },
  188. {
  189. id: 11,
  190. conversationId: 1,
  191. senderId: 283,
  192. senderAvatar: null,
  193. senderType: 1,
  194. receiverId: null,
  195. receiverType: null,
  196. contentType: 1,
  197. content: '[困~][困~]',
  198. readStatus: false,
  199. createTime: 1718615413000
  200. },
  201. {
  202. id: 10,
  203. conversationId: 1,
  204. senderId: 283,
  205. senderAvatar: null,
  206. senderType: 1,
  207. receiverId: null,
  208. receiverType: null,
  209. contentType: 1,
  210. content: '[睡着][睡着]',
  211. readStatus: false,
  212. createTime: 1718615407000
  213. }
  214. ]
  215. messageList.value = list
  216. }
  217. defineExpose({ getMessageList })
  218. // 是否显示聊天区域
  219. const showChatBox = computed(() => !isEmpty(keFuConversation.value))
  220. </script>
  221. <style lang="scss" scoped>
  222. .kefu {
  223. &-title {
  224. border-bottom: #e4e0e0 solid 1px;
  225. height: 60px;
  226. line-height: 60px;
  227. }
  228. &-content {
  229. .ss-row-left {
  230. justify-content: flex-start;
  231. .kefu-message {
  232. margin-left: 20px;
  233. position: relative;
  234. &::before {
  235. content: '';
  236. width: 10px;
  237. height: 10px;
  238. left: -19px;
  239. top: calc(50% - 10px);
  240. position: absolute;
  241. border-left: 5px solid transparent;
  242. border-bottom: 5px solid transparent;
  243. border-top: 5px solid transparent;
  244. border-right: 5px solid #ffffff;
  245. }
  246. }
  247. }
  248. .ss-row-right {
  249. justify-content: flex-end;
  250. .kefu-message {
  251. margin-right: 20px;
  252. position: relative;
  253. &::after {
  254. content: '';
  255. width: 10px;
  256. height: 10px;
  257. right: -19px;
  258. top: calc(50% - 10px);
  259. position: absolute;
  260. border-left: 5px solid #ffffff;
  261. border-bottom: 5px solid transparent;
  262. border-top: 5px solid transparent;
  263. border-right: 5px solid transparent;
  264. }
  265. }
  266. }
  267. // 消息气泡
  268. .kefu-message {
  269. color: #333;
  270. border-radius: 5px;
  271. box-shadow: 3px 5px 15px rgba(0, 0, 0, 0.2);
  272. padding: 5px 10px;
  273. width: auto;
  274. max-width: 50%;
  275. text-align: left;
  276. display: inline-block !important;
  277. position: relative;
  278. word-break: break-all;
  279. background-color: #ffffff;
  280. transition: all 0.2s;
  281. &:hover {
  282. transform: scale(1.03);
  283. }
  284. }
  285. }
  286. .chat-tools {
  287. width: 100%;
  288. border: #e4e0e0 solid 1px;
  289. height: 44px;
  290. display: flex;
  291. align-items: center;
  292. }
  293. ::v-deep(textarea) {
  294. resize: none;
  295. }
  296. }
  297. </style>