ChatingHeader.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="chating_header_container" :style="{ paddingTop: statusBarHeight + 'px' }" @click="click">
  3. <view class="chating_header_content">
  4. <view @click="routeBack" class="header_left">
  5. <image class="back_icon" style="width: 12px; height: 20px;" src="/pages_im/static/images/common_left_arrow.png" mode="aspectFit" />
  6. </view>
  7. <view class="header_center">
  8. <view class="chating_info">
  9. <view class="conversation_info">
  10. <text class="title">{{ storeCurrentConversation ? storeCurrentConversation.showName : '' }}</text>
  11. <text v-if="!isSingle && !isNotify" class="sub_title">{{ groupMemberCount }}</text>
  12. <image style="width: 16px; height: 16px; margin-left: 4px;" v-if="isRecvMsgOpt" src="/pages_im/static/images/conversation_not_accept.png" />
  13. </view>
  14. <view v-if="isSingle" class="online_state">
  15. <!-- <view v-if="isSingle && onlineStr" class="dot" :style="{ backgroundColor: isOnline ? '#10CC64' : '#999' }" />
  16. <text class="online_str" v-if="isSingle">{{ onlineStr }}</text> -->
  17. </view>
  18. </view>
  19. </view>
  20. <view class="header_right">
  21. <view class="right_action">
  22. <image @click="goSetting" class="action_item" style="width: 23px; height: 23px;" src="/pages_im/static/images/common_more.png" />
  23. </view>
  24. </view>
  25. </view>
  26. <!-- Group Announcement & Calling (Moved out of header_content for better layout control) -->
  27. <view v-if="showGroupAnnouncement" @click="toGroupAnnouncement(true)" class="group_announcement_tab">
  28. <view class="announcement_header">
  29. <view class="announcement_header_left">
  30. <image class="announcement_icon" style="width: 16px; height: 16px;" src="/pages_im/static/images/chating_message_notice.png" mode=""></image>
  31. <text class="announcement_text" style="margin-left: 8rpx">群公告</text>
  32. </view>
  33. <view @click.stop="toGroupAnnouncement(false)">
  34. <image class="announcement_close" style="width: 16px; height: 16px;" src="/pages_im/static/images/announcement_close.png" mode=""></image>
  35. </view>
  36. </view>
  37. <text class="announcement_content_text">
  38. {{ getGroupAnnouncementContent }}
  39. </text>
  40. </view>
  41. <view class="group_calling_tab" v-if="callingData">
  42. <view class="base_row" @click="showMoreMember = !showMoreMember">
  43. <image style="width: 20px; height: 20px;" src="/pages_im/static/images/group_calling_icon.png" />
  44. <text style="font-size: 14px; margin-left: 5px; color: #333;">{{ `${callingData.participant.length}人正在${callingData.invitation.mediaType === 'video' ? '视频' : '语音'}通话` }}</text>
  45. <image class="arrow" style="width: 9px; height: 6px;" src="/pages_im/static/images/group_calling_arrow.png" />
  46. </view>
  47. <view class="member_row" v-show="showMoreMember">
  48. <my-avatar
  49. size="42"
  50. :src="item.userInfo.faceURL"
  51. :desc="item.userInfo.nickname"
  52. v-for="item in callingData.participant.slice(0, 11)"
  53. :key="item.userInfo.userID"/>
  54. </view>
  55. <view class="action_row" v-show="showMoreMember" @click="joinRtc">
  56. <text style="color: #006FFF; font-size: 14px;">加入</text>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { mapGetters } from 'vuex';
  63. import { PageEvents } from '../../../../constant';
  64. import IMSDK, { IMMethods, GroupAtType, SessionType, MessageReceiveOptType } from 'openim-uniapp-polyfill';
  65. import { Platform } from '../../../../constant/im';
  66. import MyAvatar from '../../../../components/MyAvatar/index.vue';
  67. import { callingModule, getIMSDK } from '../../../../util/imCommon';
  68. export default {
  69. name: 'ChatingHeader',
  70. components: {
  71. MyAvatar
  72. },
  73. props: {
  74. mutipleCheckVisible: Boolean,
  75. storeCurrentConversation: {
  76. type: Object,
  77. default:{}
  78. }
  79. },
  80. data() {
  81. let statusBarHeight = 20;
  82. try {
  83. statusBarHeight = uni.getSystemInfoSync().statusBarHeight || 20;
  84. } catch (e) {}
  85. return {
  86. statusBarHeight: statusBarHeight,
  87. isOnline: false,
  88. isTyping: false,
  89. onlineStr: '',
  90. callingData: null,
  91. showMoreMember: false,
  92. joinLock: false,
  93. inThisGroup: false
  94. };
  95. },
  96. computed: {
  97. ...mapGetters([ 'storeCurrentGroup', 'storeCurrentMemberInGroup', 'storeSelfInfo', 'storeBlackList']),
  98. isRecvMsgOpt() {
  99. // 默认不显示,只有明确设置为非 Normal 状态才显示
  100. const opt = this.storeCurrentConversation?.recvMsgOpt;
  101. return opt !== undefined && opt !== MessageReceiveOptType.Normal;
  102. },
  103. isSingle() {
  104. return this.storeCurrentConversation?.conversationType === SessionType.Single;
  105. },
  106. isBlack() {
  107. if (!this.isSingle) {
  108. return true;
  109. }
  110. return this.storeBlackList.some((black) => black.userID === this.storeCurrentConversation.userID);
  111. },
  112. isNotify() {
  113. return this.storeCurrentConversation.conversationType === SessionType.Notification;
  114. },
  115. groupMemberCount() {
  116. const count = this.storeCurrentGroup?.memberCount;
  117. return (count && count > 0) ? `(${count})` : '';
  118. },
  119. showGroupAnnouncement() {
  120. return this.$store.getters.storeCurrentConversation.groupAtType === GroupAtType.AtGroupNotice;
  121. },
  122. getGroupAnnouncementContent() {
  123. if (this.showGroupAnnouncement) {
  124. const content = this.$store.getters.storeCurrentGroup.notification;
  125. if (content) {
  126. // nvue text组件不支持html标签,需要过滤掉
  127. return content.replace(/<[^>]+>/g, '');
  128. }
  129. }
  130. return '';
  131. },
  132. canGoSetting() {
  133. if (this.isSingle) {
  134. return true;
  135. }
  136. return this.storeCurrentMemberInGroup.groupID === this.storeCurrentConversation.groupID;
  137. }
  138. },
  139. mounted() {
  140. // console.log("qxj storeCurrentConversation",this.storeCurrentConversation);
  141. // 延迟加载 IM 监听,避免阻塞 UI 渲染
  142. setTimeout(() => {
  143. this.setIMListenter();
  144. if (this.storeCurrentConversation.groupID) {
  145. this.joinedGroupChangeHandler({
  146. data: { groupID: this.storeCurrentConversation.groupID }
  147. });
  148. } else {
  149. this.getOnlineState();
  150. }
  151. }, 200);
  152. },
  153. beforeDestroy() {
  154. this.disposeIMListener();
  155. const _IMSDK = getIMSDK();
  156. _IMSDK.asyncApi('unsubscribeUsersStatus', _IMSDK.uuid(), [this.storeCurrentConversation.userID]);
  157. },
  158. methods: {
  159. click(e) {
  160. this.$emit('click', e);
  161. },
  162. routeBack() {
  163. if (this.mutipleCheckVisible) {
  164. this.$emit('mutipleCheckUpdate');
  165. return;
  166. }
  167. this.$emit('back');
  168. // uni.navigateBack()
  169. uni.switchTab({
  170. url: '/pages_im/pages/conversation/conversationList/index'
  171. });
  172. },
  173. goSetting() {
  174. this.$emit('enterSubPage');
  175. const url = this.isSingle ? '/pages_im/pages/conversation/singleSettings/index' : '/pages_im/pages/conversation/groupSettings/index';
  176. uni.navigateTo({url});
  177. },
  178. joinRtc() {
  179. this.$emit('enterSubPage');
  180. callingModule.joinRoomLiveChat(this.callingData);
  181. },
  182. routeCall() {
  183. if (!this.$store.getters.storeCurrentConversation.groupID) {
  184. this.$emit('enterSubPage');
  185. uni.$emit(PageEvents.RtcCall);
  186. return;
  187. }
  188. IMSDK.asyncApi('signalingGetRoomByGroupID', IMSDK.uuid(), this.$store.getters.storeCurrentConversation.groupID).then(({ data }) => {
  189. if (data.invitation) {
  190. uni.showModal({
  191. title: '提示',
  192. content: '群通话进行中,是否直接加入?',
  193. confirmText: '确认',
  194. cancelText: '取消',
  195. success: (res) => {
  196. if (res.confirm) {
  197. this.$emit('enterSubPage');
  198. callingModule.joinRoomLiveChat(data);
  199. }
  200. }
  201. });
  202. } else {
  203. this.$emit('enterSubPage');
  204. uni.$emit(PageEvents.RtcCall);
  205. }
  206. });
  207. },
  208. getOnlineState() {
  209. IMSDK.asyncApi('subscribeUsersStatus', IMSDK.uuid(), [this.storeCurrentConversation.userID])
  210. .then(({ data }) => {
  211. this.isOnline = !!data[0].status;
  212. if (data[0].status) {
  213. const platformStr = data[0].platformIDs.map((id) => Platform[id]).join('/');
  214. this.onlineStr = platformStr + '在线';
  215. } else {
  216. this.onlineStr = '离线';
  217. }
  218. }).catch((err) => {
  219. });
  220. },
  221. checkOnline() {
  222. if (this.isSingle) {
  223. this.getOnlineState();
  224. }
  225. },
  226. toGroupAnnouncement(bool) {
  227. if (bool) {
  228. uni.navigateTo({
  229. url: '/pages_im/pages/conversation/groupAnnouncement/index'
  230. });
  231. } else {
  232. IMSDK.asyncApi('setConversationPrivateChat', IMSDK.uuid(), {
  233. conversationID: this.storeCurrentConversation.conversationID,
  234. isPrivate: false
  235. }).then(() => {
  236. this.$store.commit('conversation/UPDATE_CURRENT_CONVERSATION', {
  237. key: 'groupAtType',
  238. value: GroupAtType.AtNormal
  239. });
  240. });
  241. }
  242. },
  243. setIMListenter() {
  244. // this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight; // 移除此处的重复设置,防止布局跳动
  245. IMSDK.subscribe(IMSDK.IMEvents.OnUserStatusChanged, this.userStatusChangeHandler);
  246. uni.$on(IMSDK.IMEvents.OnJoinedGroupDeleted, this.joinedGroupChangeHandler);
  247. uni.$on(IMSDK.IMEvents.OnJoinedGroupAdded, this.joinedGroupChangeHandler);
  248. },
  249. userStatusChangeHandler({ data }) {
  250. if (data.userID === this.storeCurrentConversation.userID) {
  251. this.isOnline = data.status === 1;
  252. if (data.status === 1) {
  253. const platformStr = data.platformIDs.map((id) => Platform[id]).join('/');
  254. this.onlineStr = platformStr + '在线';
  255. } else {
  256. this.onlineStr = '离线';
  257. }
  258. }
  259. },
  260. updateTyping() {
  261. this.isTyping = true;
  262. if (this.typingTimer) clearTimeout(this.typingTimer);
  263. this.typingTimer = setTimeout(() => {
  264. this.isTyping = false;
  265. }, 2000);
  266. },
  267. updateCallingData(data) {
  268. this.callingData = data;
  269. },
  270. joinedGroupChangeHandler({ data }) {
  271. if (data.groupID === this.storeCurrentConversation.groupID) {
  272. IMSDK.asyncApi(IMMethods.IsJoinGroup, IMSDK.uuid(), data.groupID).then((res) => {
  273. this.inThisGroup = res.data;
  274. });
  275. }
  276. },
  277. disposeIMListener() {
  278. IMSDK.unsubscribe(IMSDK.IMEvents.OnUserStatusChanged, this.userStatusChangeHandler);
  279. uni.$off(IMSDK.IMEvents.OnJoinedGroupDeleted, this.joinedGroupChangeHandler);
  280. uni.$off(IMSDK.IMEvents.OnJoinedGroupAdded, this.joinedGroupChangeHandler);
  281. }
  282. }
  283. };
  284. </script>
  285. <style lang="scss" scoped>
  286. .chating_header_container {
  287. background-color: #ffffff;
  288. border-bottom-width: 1px;
  289. border-bottom-color: #e8eaef;
  290. position: relative; /* Ensure absolute children position relative to this */
  291. flex-direction: column;
  292. }
  293. .chating_header_content {
  294. height: 44px;
  295. flex-direction: row;
  296. align-items: center;
  297. justify-content: space-between;
  298. }
  299. .header_left {
  300. width: 60px;
  301. height: 44px;
  302. flex-direction: row;
  303. align-items: center;
  304. justify-content: flex-start;
  305. padding-left: 12px;
  306. }
  307. .header_center {
  308. flex: 1;
  309. height: 44px;
  310. justify-content: center;
  311. align-items: center;
  312. }
  313. .header_right {
  314. width: 60px;
  315. height: 44px;
  316. flex-direction: row;
  317. align-items: center;
  318. justify-content: flex-end;
  319. padding-right: 12px;
  320. }
  321. .back_icon {
  322. width: 12px;
  323. height: 20px;
  324. }
  325. .action_item {
  326. width: 23px;
  327. height: 23px;
  328. }
  329. .chating_info {
  330. flex-direction: column;
  331. align-items: center;
  332. justify-content: center;
  333. }
  334. .conversation_info {
  335. flex-direction: row;
  336. align-items: center;
  337. justify-content: center;
  338. }
  339. .title {
  340. font-size: 19px;
  341. font-weight: 500;
  342. lines: 1;
  343. text-overflow: ellipsis;
  344. color: #333333;
  345. }
  346. .sub_title {
  347. margin-left: 4px;
  348. font-size: 14px;
  349. color: #333333;
  350. }
  351. .online_state {
  352. flex-direction: row;
  353. align-items: center;
  354. margin-top: 2px;
  355. }
  356. .right_action {
  357. flex-direction: row;
  358. align-items: center;
  359. }
  360. /* Group Announcement */
  361. .group_announcement_tab {
  362. /* Position changed to flow layout */
  363. padding: 10px 16px;
  364. background-color: #f0f6ff;
  365. border-radius: 6px;
  366. flex-direction: column;
  367. margin: 10px 10px 0 10px; /* Add top margin */
  368. }
  369. .announcement_header {
  370. flex-direction: row;
  371. justify-content: space-between;
  372. align-items: center;
  373. margin-bottom: 8px;
  374. }
  375. .announcement_header_left {
  376. flex-direction: row;
  377. align-items: center;
  378. }
  379. .announcement_text {
  380. font-size: 14px;
  381. color: #333;
  382. }
  383. .announcement_content_text {
  384. lines: 2;
  385. text-overflow: ellipsis;
  386. font-size: 12px;
  387. color: #617183;
  388. }
  389. /* Group Calling */
  390. .group_calling_tab {
  391. /* Position changed to flow layout */
  392. padding: 12px;
  393. background-color: #f4f9ff;
  394. border-radius: 4px;
  395. margin: 10px 10px 0 10px; /* Add top margin */
  396. }
  397. .base_row {
  398. flex-direction: row;
  399. align-items: center;
  400. justify-content: space-between;
  401. }
  402. .member_row {
  403. flex-direction: row;
  404. flex-wrap: wrap;
  405. padding: 12px 14px;
  406. margin-top: 12px;
  407. background-color: #ffffff;
  408. border-bottom-width: 1px;
  409. border-bottom-color: rgba(151, 151, 151, 0.16);
  410. }
  411. .action_row {
  412. flex-direction: row;
  413. justify-content: center;
  414. padding: 12px;
  415. background-color: #ffffff;
  416. }
  417. </style>