ChatingHeader.vue 11 KB

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