ChatingHeader.vue 11 KB

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