message-emoji-react.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div
  3. class="dialog-emoji"
  4. :class="env?.isH5 ? 'dialog-emoji-h5' : ''"
  5. v-if="type === 'dropdown'"
  6. >
  7. <div class="face-list collapse">
  8. <ul class="face-list-collapse">
  9. <li
  10. class="face-list-item"
  11. v-for="(childrenItem, childrenIndex) in emojiCollapseList"
  12. :key="childrenIndex"
  13. @click.stop="select(childrenItem)"
  14. >
  15. <img :src="emojiUrl + emojiMap[childrenItem]" />
  16. </li>
  17. </ul>
  18. <div class="face-list-button" @click.stop="isCollapse = !isCollapse">
  19. <i
  20. class="icon"
  21. :class="[isCollapse ? 'icon-expand' : 'icon-collapse']"
  22. ></i>
  23. </div>
  24. </div>
  25. <ul class="face-list face-list-expand" v-show="!isCollapse">
  26. <li
  27. class="face-list-item"
  28. v-for="(childrenItem, childrenIndex) in emojiExpandList"
  29. :key="childrenIndex"
  30. @click.stop="select(childrenItem)"
  31. >
  32. <img :src="emojiUrl + emojiMap[childrenItem]" />
  33. </li>
  34. </ul>
  35. </div>
  36. <div v-if="type === 'content'" class="emoji-content">
  37. <ul class="emoji-react" ref="container">
  38. <li
  39. class="emoji-react-item"
  40. v-for="(val, key) in handleEmojiReact(message)"
  41. :key="key"
  42. v-show="val && val?.length"
  43. @click.stop="select(key)"
  44. >
  45. <img :src="emojiUrl + emojiMap[key]" />
  46. <div class="emoji-react-item-content">
  47. <span>{{ handleEmojiReactItem(val) }}</span>
  48. </div>
  49. </li>
  50. </ul>
  51. </div>
  52. </template>
  53. <script lang="ts">
  54. import {
  55. defineComponent,
  56. watch,
  57. reactive,
  58. toRefs,
  59. computed,
  60. ref,
  61. onMounted,
  62. nextTick
  63. } from 'vue';
  64. import TIM from '../../../../TUICore/tim';
  65. import { emojiUrl, emojiMap, emojiName } from '../utils/emojiMap';
  66. import { JSONToObject } from '../utils/utils';
  67. import TUIChat from '../index.vue';
  68. import { Message } from '@tencentcloud/chat';
  69. export default defineComponent({
  70. props: {
  71. message: {
  72. type: Object,
  73. default: () => ({})
  74. },
  75. emojiList: {
  76. type: Array,
  77. default: () => []
  78. },
  79. type: {
  80. type: String,
  81. default: ''
  82. }
  83. },
  84. emits: ['handleCollapse'],
  85. setup(props: any, ctx: any) {
  86. const { TUIServer } = TUIChat;
  87. const data = reactive({
  88. message: {} as Message,
  89. emojiUrl,
  90. emojiMap,
  91. emojiName,
  92. isCollapse: true,
  93. types: TIM.TYPES,
  94. env: TUIServer.TUICore.TUIEnv,
  95. type: props.type,
  96. emojiReacts: {},
  97. allMemberList: []
  98. });
  99. const container = ref({} as HTMLElement);
  100. const emojiCollapseList = computed(() => {
  101. return data.emojiName.slice(0, 6);
  102. });
  103. const emojiExpandList = computed(() => {
  104. return data.emojiName.slice(6);
  105. });
  106. const select = (item: any) => {
  107. TUIServer.emojiReact(data.message, item);
  108. };
  109. const handleEmojiReact = (message: any) => {
  110. try {
  111. if (!message?.cloudCustomData) return;
  112. const reactList = JSONToObject(message?.cloudCustomData)?.messageReact
  113. ?.reacts;
  114. if (!reactList) return;
  115. data.emojiReacts = reactList;
  116. return reactList;
  117. } catch (err) {
  118. console.warn(err);
  119. }
  120. };
  121. const handleEmojiReactItem = (userIDList: any) => {
  122. let res = '';
  123. userIDList?.forEach((item: any, index: any) => {
  124. const memberInfo = data.allMemberList?.find(
  125. (member: any) => member.userID === item
  126. );
  127. res = res + (memberInfo ? (memberInfo as any)?.nick : item) + ', ';
  128. });
  129. if (res.length) res = res.substring(0, res.lastIndexOf(','));
  130. return res;
  131. };
  132. const handleAllMemberList = (message: any) => {
  133. const TUIChatStore = TUIServer?.currentStore;
  134. switch (message?.conversationType) {
  135. case TIM.TYPES.CONV_C2C:
  136. data.allMemberList = [
  137. {
  138. userID: TUIChatStore?.conversation?.userProfile?.userID,
  139. nick: TUIChatStore?.conversation?.userProfile?.nick
  140. },
  141. {
  142. userID: TUIChatStore?.selfInfo?.userID,
  143. nick: TUIChatStore?.selfInfo?.nick
  144. }
  145. ] as any;
  146. break;
  147. case TIM.TYPES.CONV_GROUP:
  148. data.allMemberList = TUIChatStore?.allMemberList?.memberList;
  149. break;
  150. default:
  151. break;
  152. }
  153. };
  154. watch(
  155. () => props.message,
  156. (newVal: any, oldVal: any) => {
  157. data.message = props.message;
  158. if (newVal?.conversationID !== oldVal?.conversationID) {
  159. handleAllMemberList(newVal);
  160. }
  161. },
  162. { deep: true, immediate: true }
  163. );
  164. watch(
  165. () => data.isCollapse,
  166. (newVal, oldVal) => {
  167. if (newVal === oldVal) return;
  168. if (!data?.env?.isH5) return;
  169. ctx.emit('handleCollapse', newVal);
  170. }
  171. );
  172. return {
  173. ...toRefs(data),
  174. emojiCollapseList,
  175. emojiExpandList,
  176. select,
  177. handleEmojiReact,
  178. handleEmojiReactItem,
  179. container
  180. };
  181. }
  182. });
  183. </script>
  184. <style lang="scss" scoped>
  185. @import url('../../../styles/common.scss');
  186. @import url('../../../styles/icon.scss');
  187. .dialog-emoji {
  188. margin-left: 2Px;
  189. background: #ffffff;
  190. border: 1Px solid #e0e0e0;
  191. box-shadow: 0 4Px 12Px 0 rgba(0, 0, 0, 0.06);
  192. width: 242Px;
  193. min-height: 28Px;
  194. height: fit-content;
  195. padding: 2Px 6Px;
  196. word-break: keep-all;
  197. top: 30Px;
  198. border-radius: 8Px;
  199. &-h5 {
  200. margin: 0 5Px;
  201. border: none;
  202. border-bottom: 1Px solid #e0e0e0;
  203. box-shadow: none;
  204. border-radius: 10Px 10Px 0 0;
  205. }
  206. .collapse {
  207. padding: 2Px 0Px;
  208. }
  209. .face-list {
  210. display: flex;
  211. overflow: hidden;
  212. flex-wrap: nowrap;
  213. flex-direction: row;
  214. &-collapse {
  215. display: flex;
  216. overflow: hidden;
  217. flex-wrap: nowrap;
  218. justify-content: space-between;
  219. align-items: center;
  220. flex: 1;
  221. }
  222. &-expand {
  223. border-top: 1Px solid #e0e0e0;
  224. display: flex;
  225. overflow-x: hidden;
  226. flex-wrap: wrap;
  227. max-height: 90Px;
  228. overflow-y: auto;
  229. }
  230. &-button {
  231. padding: 5Px 7Px;
  232. height: 20Px;
  233. line-height: 20Px;
  234. text-align: center;
  235. align-items: center;
  236. i {
  237. text-align: center;
  238. }
  239. }
  240. li {
  241. margin: 4Px;
  242. display: flex;
  243. flex-direction: row;
  244. align-items: center;
  245. flex-direction: row;
  246. img {
  247. width: 22Px;
  248. height: 22Px;
  249. }
  250. }
  251. }
  252. }
  253. .emoji-content {
  254. .emoji-react {
  255. margin-top: 3Px;
  256. display: flex;
  257. flex-direction: row;
  258. flex-wrap: wrap;
  259. align-items: center;
  260. &-item {
  261. width: fit-content;
  262. height: 20Px;
  263. background: rgba(0, 0, 0, 0.05);
  264. border-radius: 12Px;
  265. padding: 2Px 6Px;
  266. margin: 2Px;
  267. overflow: hidden;
  268. text-overflow: ellipsis;
  269. max-width: 200Px;
  270. display: flex;
  271. img {
  272. width: 16Px;
  273. height: 16Px;
  274. padding: 2Px;
  275. }
  276. &-content {
  277. overflow: hidden;
  278. text-overflow: ellipsis;
  279. font-size: 10Px;
  280. color: #999999;
  281. align-self: center;
  282. span {
  283. margin: 2Px;
  284. font-size: 10Px;
  285. color: #999999;
  286. overflow: hidden;
  287. text-overflow: ellipsis;
  288. white-space: nowrap;
  289. }
  290. }
  291. }
  292. }
  293. }
  294. </style>