index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <page-meta :root-font-size="$store.getters.storeRootFontSize"></page-meta>
  3. <view :style="{ backgroundColor: '#f8f8f8'}" class="chating_container">
  4. <chating-header @click="pageClick" ref="chatingHeaderRef" :mutipleCheckVisible="mutipleCheckVisible" @mutipleCheckUpdate="mutipleCheckUpdate" />
  5. <chating-list
  6. style="flex: 1;overflow: hidden"
  7. @click="pageClick"
  8. :mutipleCheckVisible="mutipleCheckVisible"
  9. ref="chatingListRef"
  10. @initSuccess="initSuccess"
  11. :menuOutsideFlag="menuOutsideFlag"
  12. @closeMenu="closeMenu" />
  13. <chating-footer v-if="(imType == 1 || imType == 2)" v-show="!mutipleCheckVisible" ref="chatingFooterRef" :footerOutsideFlag="footerOutsideFlag" @scrollToBottom="scrollToBottom" />
  14. <view v-if="mutipleCheckVisible" class="mutiple_action_container">
  15. <view @click="forward('MergeForWard')" class="action_item">
  16. <image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/mutiple_merge.png" />
  17. <text style="margin-top: 12rpx">合并转发</text>
  18. </view>
  19. <view @click="mutipleRemove" class="action_item">
  20. <image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/mutiple_delete.png" />
  21. <text style="margin-top: 12rpx; color: #ff381f">删除</text>
  22. </view>
  23. </view>
  24. <u-loading-page :loading="initLoading"></u-loading-page>
  25. </view>
  26. </template>
  27. <script>
  28. import { mapGetters, mapActions } from 'vuex';
  29. import IMSDK from 'openim-uniapp-polyfill';
  30. import { ContactChooseTypes, GroupMemberListTypes, PageEvents } from '../../../constant';
  31. import ChatingHeader from './components/ChatingHeader.vue';
  32. import ChatingFooter from './components/ChatingFooter/index.vue';
  33. import ChatingList from './components/ChatingList.vue';
  34. import { markConversationAsRead, parseMessageByType, callingModule } from '../../../util/imCommon';
  35. export default {
  36. components: {
  37. ChatingHeader,
  38. ChatingFooter,
  39. ChatingList
  40. },
  41. data() {
  42. return {
  43. listHeight: 0,
  44. footerOutsideFlag: 0,
  45. menuOutsideFlag: 0,
  46. initLoading: true,
  47. mutipleCheckVisible: false,
  48. back2Tab: false,
  49. timer: null,
  50. //imType:null
  51. };
  52. },
  53. watch: {
  54. mutipleCheckVisible: {
  55. handler(newVal, oldVal) {
  56. console.log('qxj mutipleCheckVisible 发生变化:', newVal, oldVal);
  57. },
  58. deep: true // 监听对象或数组内部的变化
  59. }
  60. },
  61. computed: {
  62. ...mapGetters(["timStore"]),
  63. // 响应式派生数据
  64. imType() {
  65. return this.timStore?.imType || '';
  66. },
  67. orderId() {
  68. return this.timStore?.orderId || '';
  69. }
  70. },
  71. onLoad(options) {
  72. this.setPageListener();
  73. this.checkCalling();
  74. if (options?.back2Tab) {
  75. this.back2Tab = JSON.parse(options.back2Tab);
  76. }
  77. console.log("qxj imType:"+this.imType);
  78. //this.imType=this.timStore.imType;
  79. },
  80. onUnload() {
  81. this.disposePageListener();
  82. markConversationAsRead(
  83. {...this.$store.getters.storeCurrentConversation},
  84. true
  85. );
  86. this.resetConversationState();
  87. this.resetMessageState();
  88. if (this.timer) {
  89. clearInterval(this.timer);
  90. }
  91. },
  92. methods: {
  93. ...mapActions('message', ['resetMessageState', 'deleteMessages']),
  94. ...mapActions('conversation', ['resetConversationState']),
  95. scrollToBottom(isRecv = false) {
  96. // this.$refs.chatingListRef.scrollToAnchor(`auchor${clientMsgID}`, isRecv);
  97. this.$refs.chatingListRef.scrollToBottom(false, isRecv);
  98. },
  99. nativeCallEndHandler() {
  100. if (!this.$store.getters.storeCurrentConversation.groupID) {
  101. return;
  102. }
  103. IMSDK.asyncApi('signalingGetRoomByGroupID', IMSDK.uuid(), this.$store.getters.storeCurrentConversation.groupID).then(({ data }) => {
  104. if (data.invitation) {
  105. this.$refs.chatingHeaderRef.updateCallingData(data);
  106. } else {
  107. this.$refs.chatingHeaderRef.updateCallingData(null);
  108. }
  109. });
  110. },
  111. checkCalling() {
  112. if (!this.$store.getters.storeCurrentConversation.groupID) {
  113. return;
  114. }
  115. if (this.timer) {
  116. clearInterval(this.timer);
  117. }
  118. this.nativeCallEndHandler();
  119. this.timer = setInterval(this.nativeCallEndHandler, 10000);
  120. },
  121. mutipleRemove() {
  122. const checkedMessages = this.$store.getters.storeHistoryMessageList.filter((message) => message.checked);
  123. if (checkedMessages.length === 0) {
  124. uni.$u.toast('请先选择要操作的消息');
  125. return;
  126. }
  127. let count = 0;
  128. checkedMessages.map((message) => {
  129. IMSDK.asyncApi(IMSDK.IMMethods.DeleteMessage, IMSDK.uuid(), {
  130. conversationID: this.$store.getters.storeCurrentConversation.conversationID,
  131. clientMsgID: message.clientMsgID
  132. }).then(() => {
  133. count++;
  134. if (count === checkedMessages.length) {
  135. this.deleteMessages(checkedMessages);
  136. this.mutipleCheckUpdateHandler(false);
  137. uni.$u.toast('删除成功');
  138. }
  139. });
  140. });
  141. },
  142. forward(type) {
  143. const checkedMessages = this.$store.getters.storeHistoryMessageList.filter((message) => message.checked);
  144. if (checkedMessages.length === 0) {
  145. uni.$u.toast('请先选择要操作的消息');
  146. return;
  147. }
  148. const currentConversation = this.$store.getters.storeCurrentConversation;
  149. const title = currentConversation.groupID ? `群聊${currentConversation.showName}的聊天记录` : `和${currentConversation.showName}的聊天记录`;
  150. const mergeInfo = {
  151. messageList: [...checkedMessages],
  152. summaryList: checkedMessages.map((message) => `${message.senderNickname}:${parseMessageByType(message)}`),
  153. title
  154. };
  155. uni.navigateTo({
  156. url: `/pages_im/pages/common/contactChoose/index?type=${type}&mergeInfo=${encodeURIComponent(JSON.stringify(mergeInfo))}`
  157. });
  158. },
  159. closeMenu() {
  160. this.getEl('.message_menu_container').then((res) => {
  161. if (res) {
  162. this.menuOutsideFlag += 1;
  163. }
  164. });
  165. },
  166. async pageClick(e) {
  167. this.getEl('.message_menu_container').then((res) => {
  168. if (res) {
  169. this.menuOutsideFlag += 1;
  170. }
  171. });
  172. this.footerOutsideFlag += 1;
  173. },
  174. getEl(el) {
  175. return new Promise((resolve) => {
  176. const query = uni.createSelectorQuery().in(this);
  177. query.select(el)
  178. .boundingClientRect((data) => {
  179. resolve(data);
  180. }).exec();
  181. });
  182. },
  183. initSuccess() {
  184. console.log('initSuccess');
  185. this.initLoading = false;
  186. },
  187. async getCheckedUsers(data) {
  188. this.$refs.chatingFooterRef.customEditorCtx.undo();
  189. for (const item of data) {
  190. this.$refs.chatingFooterRef.insertAt(item.userID, item.nickname);
  191. await uni.$u.sleep(200);
  192. }
  193. },
  194. sendRtcInvite(mediaType, userIDList) {
  195. const isVideo = mediaType === 'video';
  196. const inviteeUserIDList = userIDList ?? [this.$store.getters.storeCurrentConversation.userID];
  197. callingModule.startLiveChat(isVideo, inviteeUserIDList, this.$store.getters.storeCurrentConversation.groupID, this.$store.getters.storeCurrentUserID);
  198. },
  199. chooseCallMediaType(mediaType) {
  200. return new Promise((resolve, reject) => {
  201. console.log("qxj chooseCallMediaType:"+mediaType);
  202. resolve(mediaType);
  203. if (mediaType) {
  204. resolve(mediaType);
  205. return;
  206. }
  207. // uni.showActionSheet({
  208. // itemList: ['语音通话', '视频通话'],
  209. // success: ({ tapIndex }) => {
  210. // resolve(tapIndex ? 'video' : 'audio');
  211. // },
  212. // fail: () => reject()
  213. // });
  214. });
  215. },
  216. // page event
  217. typingHandler() {
  218. this.$refs.chatingHeaderRef.updateTyping();
  219. },
  220. onlineCheckHandler() {
  221. this.$refs.chatingHeaderRef.checkOnline();
  222. },
  223. atSomeOneHandler({ userID, nickname }) {
  224. if (plus.os.name == 'iOS') {
  225. var UIImpactFeedbackGenerator = plus.ios.importClass('UIImpactFeedbackGenerator');
  226. var impact = new UIImpactFeedbackGenerator();
  227. impact.prepare();
  228. impact.init(1);
  229. impact.impactOccurred();
  230. } else {
  231. uni.vibrateLong();
  232. }
  233. this.$refs.chatingFooterRef.insertAt(userID, nickname);
  234. },
  235. mutipleCheckUpdateHandler({ flag, message }) {
  236. console.log("qxj mutipleCheckUpdateHandler--------");
  237. this.mutipleCheckVisible = flag;
  238. if (message) {
  239. this.$store.dispatch('message/updateOneMessage', {
  240. message: {
  241. ...message,
  242. checked: true
  243. }
  244. });
  245. }
  246. if (!flag) {
  247. const tmpMessageList = [...this.$store.getters.storeHistoryMessageList];
  248. tmpMessageList.map((message) => (message.checked = false));
  249. this.$store.commit('message/SET_HISTORY_MESSAGE_LIST', tmpMessageList);
  250. }
  251. },
  252. rtcInvitePrepare(mediaType) {
  253. this.chooseCallMediaType(mediaType).then((callMediaType) => {
  254. if (this.$store.getters.storeCurrentConversation.userID) {
  255. this.sendRtcInvite(callMediaType);
  256. } else {
  257. uni.$u.route('/pages_im/pages/conversation/groupMemberList/index', {
  258. type: GroupMemberListTypes.CallInvite,
  259. groupID: this.$store.getters.storeCurrentConversation.groupID,
  260. callMediaType: callMediaType
  261. });
  262. }
  263. });
  264. },
  265. setPageListener() {
  266. IMSDK.subscribe('onRecvC2CReadReceipt', ({ data: receiptList }) => {
  267. console.log('onRecvC2CReadReceipt', receiptList);
  268. });
  269. uni.$on(PageEvents.TypingUpdate, this.typingHandler);
  270. uni.$on(PageEvents.OnlineStateCheck, this.onlineCheckHandler);
  271. uni.$on(PageEvents.ScrollToBottom, this.scrollToBottom);
  272. uni.$on(PageEvents.AtSomeOne, this.atSomeOneHandler);
  273. uni.$on(PageEvents.MutipleCheckUpdate, this.mutipleCheckUpdateHandler);
  274. uni.$on(PageEvents.RtcCall, this.rtcInvitePrepare);
  275. uni.$on(PageEvents.NativeCallEnd, this.nativeCallEndHandler);
  276. },
  277. disposePageListener() {
  278. uni.$off(PageEvents.TypingUpdate, this.typingHandler);
  279. uni.$off(PageEvents.OnlineStateCheck, this.onlineCheckHandler);
  280. uni.$off(PageEvents.ScrollToBottom, this.scrollToBottom);
  281. uni.$off(PageEvents.AtSomeOne, this.atSomeOneHandler);
  282. uni.$off(PageEvents.MutipleCheckUpdate, this.mutipleCheckUpdateHandler);
  283. uni.$off(PageEvents.RtcCall, this.rtcInvitePrepare);
  284. uni.$off(PageEvents.NativeCallEnd, this.nativeCallEndHandler);
  285. },
  286. mutipleCheckUpdate() {
  287. this.mutipleCheckUpdateHandler({ flag: false });
  288. }
  289. },
  290. onBackPress() {
  291. if (!this.mutipleCheckVisible) {
  292. uni.switchTab({
  293. url: '/pages/im/conversationList/index'
  294. });
  295. } else {
  296. this.mutipleCheckUpdateHandler({ flag: false });
  297. }
  298. return true;
  299. },
  300. beforeDestroy() {
  301. uni.switchTab({
  302. url: '/pages/im/conversationList/index'
  303. });
  304. }
  305. };
  306. </script>
  307. <style lang="scss" scoped>
  308. .chating_container {
  309. @include colBox(false);
  310. height: 100vh;
  311. overflow: hidden;
  312. background-color: #fff !important;
  313. position: relative;
  314. .watermark {
  315. font-size: 16px; /* 水印文字大小 */
  316. color: rgba(0, 0, 0, 0.2); /* 水印文字颜色,使用透明度控制可见度 */
  317. position: absolute; /* 水印相对定位 */
  318. transform: rotate(-45deg);
  319. pointer-events: none; /* 防止水印文字干扰交互 */
  320. /* 为不同的水印元素设置不同的偏移,以避免重叠 */
  321. // transform-origin: top right;
  322. // margin-top: 20px;
  323. // margin-right: 20px;
  324. }
  325. // ::before {
  326. // content: "Your Watermark Text"; /* 替换为你想要的水印文字 */
  327. // font-size: 16px; /* 水印文字大小 */
  328. // color: rgba(0, 0, 0, 0.2); /* 水印文字颜色,使用透明度控制可见度 */
  329. // position: absolute; /* 水印相对定位 */
  330. // top: 20px; /* 距离顶部的距离 */
  331. // right: 20px; /* 距离右侧的距离 */
  332. // transform: rotate(-45deg); /* 将水印旋转为倾斜状态 */
  333. // pointer-events: none; /* 防止水印文字干扰交互 */
  334. // z-index: -1; /* 将水印置于底层 */
  335. // }
  336. .mutiple_action_container {
  337. display: flex;
  338. border-top: 1px solid #eaebed;
  339. background: #f0f2f6;
  340. justify-content: space-evenly;
  341. padding: 12px 24px;
  342. .action_item {
  343. @include centerBox();
  344. flex-direction: column;
  345. image {
  346. width: 48px;
  347. height: 48px;
  348. }
  349. }
  350. }
  351. }
  352. </style>