message-bubble.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <div :class="containerClassNameList">
  3. <!-- todo 统一组件处理-->
  4. <div
  5. class="message-bubble-main-content"
  6. :class="[message.flow === 'in' ? '' : 'reverse']"
  7. >
  8. <Avatar useSkeletonAnimation :url="message.avatar || ''" />
  9. <main class="message-body" @click.stop>
  10. <div
  11. v-if="message.flow === 'in' && message.conversationType === 'GROUP'"
  12. class="message-body-nick-name"
  13. >
  14. {{ props.content.showName }}
  15. </div>
  16. <div
  17. :class="[
  18. 'message-body-main',
  19. message.flow === 'out' && 'message-body-main-reverse',
  20. ]"
  21. >
  22. <div
  23. :class="[
  24. 'blink',
  25. 'message-body-content',
  26. message.flow === 'out' ? 'content-out' : 'content-in',
  27. message.hasRiskContent && 'content-has-risk',
  28. isNoPadding ? 'content-no-padding' : '',
  29. isNoPadding && isBlink ? 'blink-shadow' : '',
  30. !isNoPadding && isBlink ? 'blink-content' : '',
  31. ]"
  32. :style="{
  33. background: StyleImpl(props),
  34. }"
  35. >
  36. <div class="content-main">
  37. <img
  38. v-if="
  39. (message.type === TYPES.MSG_IMAGE ||
  40. message.type === TYPES.MSG_VIDEO) &&
  41. message.hasRiskContent
  42. "
  43. :class="[
  44. 'message-risk-replace',
  45. !isPC && 'message-risk-replace-h5',
  46. ]"
  47. :src="riskImageReplaceUrl"
  48. />
  49. <template v-else>
  50. <slot />
  51. </template>
  52. </div>
  53. <!-- 敏感信息失败提示 -->
  54. <div v-if="message.hasRiskContent" class="content-has-risk-tips">
  55. {{ riskContentText }}
  56. </div>
  57. </div>
  58. <!-- 发送失败 -->
  59. <div
  60. v-if="message.status === 'fail' || message.hasRiskContent"
  61. class="message-label fail"
  62. @click="resendMessage()"
  63. >
  64. !
  65. </div>
  66. <!-- 加载图标 -->
  67. <Icon
  68. v-if="
  69. message.status === 'unSend' &&
  70. needLoadingIconMessageType.includes(message.type)
  71. "
  72. class="message-label loading-circle"
  73. :file="loadingIcon"
  74. :width="'15px'"
  75. :height="'15px'"
  76. />
  77. <!-- 已读 & 未读 -->
  78. <ReadStatus
  79. class="message-label align-self-bottom"
  80. :message="shallowCopyMessage(message)"
  81. @openReadUserPanel="openReadUserPanel"
  82. />
  83. </div>
  84. </main>
  85. </div>
  86. <!-- message extra area -->
  87. <div class="message-bubble-extra-content">
  88. <!-- extra: message translation -->
  89. <MessageTranslate
  90. :class="message.flow === 'out' ? 'reverse' : 'flex-row'"
  91. :message="message"
  92. />
  93. <!-- extra: message convert voice to text -->
  94. <MessageConvert
  95. :class="message.flow === 'out' ? 'reverse' : 'flex-row'"
  96. :message="message"
  97. />
  98. <!-- extra: message quote -->
  99. <MessageQuote
  100. :class="message.flow === 'out' ? 'reverse' : 'flex-row'"
  101. :message="message"
  102. @blinkMessage="blinkMessage"
  103. @scrollTo="scrollTo"
  104. />
  105. </div>
  106. </div>
  107. </template>
  108. <script lang="ts" setup>
  109. import { computed, toRefs } from "../../../../adapter-vue";
  110. import TUIChatEngine, {
  111. TUITranslateService,
  112. IMessageModel,
  113. } from "@tencentcloud/chat-uikit-engine";
  114. import Icon from "../../../common/Icon.vue";
  115. import ReadStatus from "./read-status/index.vue";
  116. import MessageQuote from "./message-quote/index.vue";
  117. import Avatar from "../../../common/Avatar/index.vue";
  118. import MessageTranslate from "./message-translate/index.vue";
  119. import MessageConvert from "./message-convert/index.vue";
  120. import loadingIcon from "../../../../assets/icon/loading.png";
  121. import { shallowCopyMessage } from "../../utils/utils";
  122. import { isPC } from "../../../../utils/env";
  123. interface IProps {
  124. messageItem: IMessageModel;
  125. content?: any;
  126. blinkMessageIDList?: string[];
  127. classNameList?: string[];
  128. }
  129. interface IEmits {
  130. (e: "resendMessage"): void;
  131. (e: "blinkMessage", messageID: string): void;
  132. (
  133. e: "setReadReceiptPanelVisible",
  134. visible: boolean,
  135. message?: IMessageModel
  136. ): void;
  137. // 下面的方法是 uniapp 专属
  138. (e: "scrollTo", scrollHeight: number): void;
  139. }
  140. const emits = defineEmits<IEmits>();
  141. const StyleImpl = (data) => {
  142. if (data.messageItem) {
  143. let style = data.messageItem._message._elements[0].content.data;
  144. if (style) {
  145. let styleJSON = JSON.parse(style);
  146. if (styleJSON.businessID == "interview_consult_message") {
  147. return "none";
  148. } else {
  149. return "";
  150. }
  151. } else {
  152. return "";
  153. }
  154. }
  155. };
  156. const props = withDefaults(defineProps<IProps>(), {
  157. messageItem: () => ({} as IMessageModel),
  158. content: () => ({}),
  159. blinkMessageIDList: () => [],
  160. classNameList: () => [],
  161. });
  162. const TYPES = TUIChatEngine.TYPES;
  163. const riskImageReplaceUrl =
  164. "https://web.sdk.qcloud.com/component/TUIKit/assets/has_risk_default.png";
  165. const needLoadingIconMessageType = [
  166. TYPES.MSG_LOCATION,
  167. TYPES.MSG_TEXT,
  168. TYPES.MSG_CUSTOM,
  169. TYPES.MSG_MERGER,
  170. TYPES.MSG_FACE,
  171. ];
  172. const { blinkMessageIDList, messageItem: message } = toRefs(props);
  173. const containerClassNameList = computed(() => {
  174. return ["message-bubble", ...props.classNameList];
  175. });
  176. const isNoPadding = computed(() => {
  177. return [TYPES.MSG_IMAGE, TYPES.MSG_VIDEO].includes(message.value.type);
  178. });
  179. const riskContentText = computed<string>(() => {
  180. let content = TUITranslateService.t("TUIChat.涉及敏感内容") + ", ";
  181. if (message.value.flow === "out") {
  182. content += TUITranslateService.t("TUIChat.发送失败");
  183. } else {
  184. content += TUITranslateService.t(
  185. message.value.type === TYPES.MSG_AUDIO
  186. ? "TUIChat.无法收听"
  187. : "TUIChat.无法查看"
  188. );
  189. }
  190. return content;
  191. });
  192. const isBlink = computed(() => {
  193. if (message.value?.ID) {
  194. return blinkMessageIDList?.value?.includes(message.value.ID);
  195. }
  196. return false;
  197. });
  198. function resendMessage() {
  199. if (!message.value?.hasRiskContent) {
  200. emits("resendMessage");
  201. }
  202. }
  203. function blinkMessage(messageID: string) {
  204. emits("blinkMessage", messageID);
  205. }
  206. function scrollTo(scrollHeight: number) {
  207. emits("scrollTo", scrollHeight);
  208. }
  209. function openReadUserPanel() {
  210. emits("setReadReceiptPanelVisible", true, message.value);
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .flex-row {
  215. display: flex;
  216. }
  217. .reverse {
  218. display: flex;
  219. flex-direction: row-reverse;
  220. justify-content: flex-start;
  221. }
  222. .message-bubble {
  223. width: 100%;
  224. box-sizing: border-box;
  225. display: flex;
  226. flex-direction: column;
  227. padding: 0 20px 25px;
  228. user-select: none;
  229. -webkit-touch-callout: none; /* 系统默认菜单被禁用 */
  230. -webkit-user-select: none; /* webkit浏览器 */
  231. -khtml-user-select: none; /* 早期浏览器 */
  232. -moz-user-select: none; /* 火狐 */
  233. -ms-user-select: none; /* IE10 */
  234. .message-bubble-main-content {
  235. display: flex;
  236. .message-avatar {
  237. display: block;
  238. width: 36px;
  239. height: 36px;
  240. border-radius: 5px;
  241. flex: 0 0 auto;
  242. }
  243. .message-body {
  244. display: flex;
  245. flex: 0 1 auto;
  246. flex-direction: column;
  247. align-items: flex-start;
  248. margin: 0 8px;
  249. max-width: calc(100% - 54px);
  250. .message-body-nick-name {
  251. margin-bottom: 4px;
  252. font-size: 12px;
  253. color: #999;
  254. max-width: 150px;
  255. overflow: hidden;
  256. text-overflow: ellipsis;
  257. white-space: nowrap;
  258. }
  259. .message-body-main {
  260. max-width: 100%;
  261. display: flex;
  262. flex-direction: row;
  263. min-width: 0;
  264. box-sizing: border-box;
  265. &-reverse {
  266. flex-direction: row-reverse;
  267. }
  268. .message-body-content {
  269. display: flex;
  270. flex-direction: column;
  271. min-width: 0;
  272. box-sizing: border-box;
  273. padding: 12px;
  274. font-size: 14px;
  275. color: #000;
  276. letter-spacing: 0;
  277. word-wrap: break-word;
  278. word-break: break-all;
  279. position: relative;
  280. .content-main {
  281. box-sizing: border-box;
  282. display: flex;
  283. flex-direction: column;
  284. flex-shrink: 0;
  285. align-content: flex-start;
  286. border: 0 solid black;
  287. margin: 0;
  288. padding: 0;
  289. min-width: 0;
  290. .message-risk-replace {
  291. width: 130px;
  292. height: 130px;
  293. }
  294. }
  295. .content-has-risk-tips {
  296. font-size: 12px;
  297. color: #fa5151;
  298. font-family: PingFangSC-Regular;
  299. margin-top: 5px;
  300. border-top: 1px solid #e5c7c7;
  301. padding-top: 5px;
  302. }
  303. }
  304. .content-in {
  305. background: #fbfbfb;
  306. border-radius: 0 10px 10px;
  307. }
  308. .content-out {
  309. background: #fff;
  310. border-radius: 10px 0 10px 10px;
  311. }
  312. .content-no-padding {
  313. padding: 0;
  314. background: transparent;
  315. border-radius: 10px;
  316. overflow: hidden;
  317. }
  318. .content-no-padding.content-has-risk {
  319. padding: 12px;
  320. }
  321. .content-has-risk {
  322. background: rgba(250, 81, 81, 0.16);
  323. }
  324. .blink-shadow {
  325. @keyframes shadow-blink {
  326. 50% {
  327. box-shadow: rgba(255, 156, 25, 1) 0 0 10px 0;
  328. }
  329. }
  330. box-shadow: rgba(255, 156, 25, 0) 0 0 10px 0;
  331. animation: shadow-blink 1s linear 3;
  332. }
  333. .blink-content {
  334. @keyframes reference-blink {
  335. 50% {
  336. background-color: #ff9c19;
  337. }
  338. }
  339. animation: reference-blink 1s linear 3;
  340. }
  341. .message-label {
  342. align-self: flex-end;
  343. font-family: PingFangSC-Regular;
  344. font-size: 12px;
  345. color: #b6b8ba;
  346. word-break: keep-all;
  347. flex: 0 0 auto;
  348. margin: 0 8px;
  349. &.fail {
  350. width: 15px;
  351. height: 15px;
  352. border-radius: 15px;
  353. background: red;
  354. color: #fff;
  355. display: flex;
  356. justify-content: center;
  357. align-items: center;
  358. cursor: pointer;
  359. }
  360. &.loading-circle {
  361. opacity: 0;
  362. animation: circle-loading 2s linear 1s infinite;
  363. }
  364. @keyframes circle-loading {
  365. 0% {
  366. transform: rotate(0);
  367. opacity: 1;
  368. }
  369. 100% {
  370. opacity: 1;
  371. transform: rotate(360deg);
  372. }
  373. }
  374. }
  375. .align-self-bottom {
  376. align-self: flex-end;
  377. }
  378. }
  379. }
  380. }
  381. .message-bubble-extra-content {
  382. display: flex;
  383. flex-direction: column;
  384. }
  385. }
  386. </style>