index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view>
  3. <text v-if="isNeedShowMessageTime" class="message_time">{{
  4. messageTime(msgBody.time)
  5. }}</text>
  6. <view
  7. :class="[
  8. 'message_list_item',
  9. !isSelf(msgBody) || 'message_list_item_mine',
  10. msgBody.id == quoteMsgId && 'quote_msg_avtive',
  11. ]"
  12. >
  13. <!--user avatar -->
  14. <view class="message_list_item_avatar">
  15. <u-avatar
  16. :src="messageItemAvatar"
  17. shape="square"
  18. :size="28"
  19. @click="entryContactsDetailPage"
  20. />
  21. </view>
  22. <view class="message_list_item_content" @longpress="callMessagePopup">
  23. <text
  24. :class="[
  25. 'message_list_item_content_nickname',
  26. isSelf(msgBody) && 'message_list_item_content_nickname_mine',
  27. ]"
  28. >{{ messageItemNickName }}</text
  29. >
  30. <!-- 文本消息 -->
  31. <template v-if="msgBody.type === MESSAGE_TYPE.TEXT">
  32. <text-msg-item :msgBody="msgBody" />
  33. </template>
  34. <!-- 图片消息 -->
  35. <template v-if="msgBody.type === MESSAGE_TYPE.IMAGE">
  36. <image-msg-item :msgBody="msgBody" />
  37. </template>
  38. <!-- 语音消息 -->
  39. <template v-if="msgBody.type === MESSAGE_TYPE.AUDIO">
  40. <audio-msg-item
  41. :msgBody="msgBody"
  42. :playAudioMid="playAudioMid"
  43. @onClickPlayAudio="onClickPlayAudio"
  44. />
  45. </template>
  46. <!-- 附件消息 -->
  47. <template v-if="msgBody.type === MESSAGE_TYPE.FILE">
  48. <file-msg-item :msgBody="msgBody" />
  49. </template>
  50. <!-- 个人名片 -->
  51. <template
  52. v-if="
  53. msgBody.type === MESSAGE_TYPE.CUSTOM &&
  54. msgBody.customEvent === CUSTOM_EVENT_NAME.USER_CARD
  55. "
  56. >
  57. <user-card-msg-item
  58. @click.native="entryContactsDetailPage(CUSTOM_EVENT_NAME.USER_CARD)"
  59. :msgBody="msgBody"
  60. />
  61. </template>
  62. <!-- 商品链接 -->
  63. <template
  64. v-if="
  65. msgBody.type === MESSAGE_TYPE.CUSTOM &&
  66. msgBody.customEvent === CUSTOM_EVENT_NAME.PRODUCTLINK
  67. "
  68. >
  69. <product-card-item
  70. @click.native="entryProductDetailPage(CUSTOM_EVENT_NAME.PRODUCTLINK)"
  71. :msgBody="msgBody"
  72. />
  73. </template>
  74. <msg-quote-container
  75. v-if="msgBody.ext && msgBody.ext.msgQuote"
  76. :msgQuoteContent="msgBody.ext.msgQuote"
  77. @click.native="callScrollToQuoteMsg(msgBody.ext.msgQuote)"
  78. />
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. import { MESSAGE_TYPE, CUSTOM_EVENT_NAME, CHAT_TYPE } from "@/EaseIM/constant";
  85. import TextMsgItem from "./messagesItem/textMsgItem";
  86. import ImageMsgItem from "./messagesItem/imageMsgItem";
  87. import AudioMsgItem from "./messagesItem/audioMsgItem";
  88. import FileMsgItem from "./messagesItem/fileMsgItem";
  89. import UserCardMsgItem from "./messagesItem/userCardItem";
  90. import ProductCardItem from "./messagesItem/productCardItem";
  91. import MsgQuoteContainer from "./msgQuoteContainer";
  92. import { EMClient } from "@/EaseIM";
  93. export default {
  94. components: {
  95. TextMsgItem,
  96. ImageMsgItem,
  97. AudioMsgItem,
  98. FileMsgItem,
  99. UserCardMsgItem,
  100. ProductCardItem,
  101. MsgQuoteContainer,
  102. },
  103. props: {
  104. msgBody: {
  105. type: Object,
  106. default: () => ({}),
  107. required: true,
  108. },
  109. isNeedShowMessageTime: {
  110. type: Boolean,
  111. default: false,
  112. },
  113. quoteMsgId: {
  114. type: String,
  115. default: "",
  116. },
  117. },
  118. data() {
  119. return {
  120. MESSAGE_TYPE,
  121. CUSTOM_EVENT_NAME,
  122. playAudioMid: "",
  123. // defaultAvatar: "/static/images/new_ui/defaultAvatar.png",
  124. defaultAvatar:uni.getStorageSync('nowConversationIntem').avatarurl,
  125. defaultAvatarMe: uni.getStorageSync('selectmerchant').merchantIntention.logo,
  126. defaultNicknameMe: uni.getStorageSync('selectmerchant').merchantIntention.mer_name,
  127. };
  128. },
  129. computed: {
  130. isSelf() {
  131. return (item) => {
  132. return (
  133. item.from ===
  134. this.$store.state.LoginStore.loginUserBaseInfos.loginUserId
  135. );
  136. };
  137. },
  138. loginUserProfiles() {
  139. return this.$store.state.LoginStore.loginUserProfiles;
  140. },
  141. messageTime() {
  142. return (time) => {
  143. return this.$u.timeFrom(time);
  144. };
  145. },
  146. friendUserInfoCollection() {
  147. return this.$store.getters.friendUserInfoCollection;
  148. },
  149. groupMembersProfileData() {
  150. return this.$store.getters.groupMembersProfile;
  151. },
  152. messageItemAvatar() {
  153. if (this.isSelf(this.msgBody)) {
  154. return this.loginUserProfiles?.avatarurl || this.defaultAvatarMe;
  155. }
  156. if (this.msgBody.chatType === CHAT_TYPE.SINGLE_CHAT) {
  157. const userId = this.msgBody.from;
  158. if (
  159. this.friendUserInfoCollection[userId] &&
  160. this.friendUserInfoCollection[userId]?.avatarurl
  161. ) {
  162. return (
  163. this.friendUserInfoCollection[userId].avatarurl ||
  164. this.defaultAvatar
  165. );
  166. } else {
  167. return this.defaultAvatar;
  168. }
  169. }
  170. if (this.msgBody.chatType === CHAT_TYPE.GROUP_CHAT) {
  171. const groupId = this.msgBody.to;
  172. const userId = this.msgBody.from;
  173. const groupMemberData = this.groupMembersProfileData[groupId];
  174. if (groupMemberData) {
  175. return groupMemberData[userId]?.avatarurl || this.defaultAvatar;
  176. } else {
  177. return this.defaultAvatar;
  178. }
  179. }
  180. },
  181. messageItemNickName() {
  182. if (this.isSelf(this.msgBody)) {
  183. // console.log('this.loginUserProfiles>>>>>>>>>>>>',this.loginUserProfiles)
  184. // console.log('EMClient.user>>>>>>>>>>>>',EMClient.user)
  185. return this.loginUserProfiles?.nickname || this.defaultNicknameMe;
  186. }
  187. if (this.msgBody.chatType === CHAT_TYPE.SINGLE_CHAT) {
  188. // const userId = this.msgBody.from;
  189. const userId=uni.getStorageSync('nowConversationIntem').nickname
  190. if (
  191. this.friendUserInfoCollection[userId] &&
  192. this.friendUserInfoCollection[userId]?.nickname
  193. ) {
  194. // return this.friendUserInfoCollection[userId].nickname;
  195. return uni.getStorageSync('nowConversationIntem').nickname;
  196. } else {
  197. return userId;
  198. }
  199. }
  200. if (this.msgBody.chatType === CHAT_TYPE.GROUP_CHAT) {
  201. const groupId = this.msgBody.to;
  202. const userId = this.msgBody.from;
  203. const groupMemberData = this.groupMembersProfileData[groupId];
  204. if (groupMemberData) {
  205. return (
  206. groupMemberData[userId]?.nickName ||
  207. groupMemberData[userId]?.nickname ||
  208. userId
  209. );
  210. } else {
  211. return userId;
  212. }
  213. }
  214. },
  215. },
  216. methods: {
  217. onClickPlayAudio(mid) {
  218. this.playAudioMid = mid;
  219. console.log("mid", mid);
  220. console.log("++++++++");
  221. },
  222. callMessagePopup() {
  223. this.$emit("alertMessagePopup", this.msgBody);
  224. },
  225. callScrollToQuoteMsg(msgQuote) {
  226. this.$emit("scrollToQuoteMessge", msgQuote);
  227. },
  228. //前往联系人详情页面
  229. entryContactsDetailPage(type) {
  230. if (type === CUSTOM_EVENT_NAME.USER_CARD) {
  231. const {
  232. customExts: { uid: userId },
  233. } = this.msgBody;
  234. uni.navigateTo({
  235. url: `../contactsDetail/index?userId=${userId}`,
  236. });
  237. } else {
  238. if (this.msgBody.from === EMClient.user) return;
  239. const userId = this.msgBody.from;
  240. uni.navigateTo({
  241. url: `../contactsDetail/index?userId=${userId}`,
  242. });
  243. }
  244. },
  245. //跳转商品详情
  246. entryProductDetailPage(){
  247. const {
  248. customExts: { uid: uid,productId:productId },
  249. } = this.msgBody;
  250. uni.navigateToMiniProgram({
  251. appId: 'wx9082e5ac2fdb513f',
  252. path: `pages/store/product/detail?id=${productId}`,
  253. envVersion: 'trial', // develop(开发版),trial(体验版),release(正式版)
  254. success(res) {
  255. // 打开成功
  256. console.log(res);
  257. },
  258. fail: (error) => {
  259. console.log(error);
  260. }
  261. })
  262. }
  263. },
  264. };
  265. </script>
  266. <style scoped>
  267. @import "./index.css";
  268. </style>