ChatingHeader.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <template>
  2. <u-navbar @click="click" placeholder class="chating_header">
  3. <view @click="routeBack" class="u-nav-slot back_view x-c" slot="left">
  4. <image class="back_icon" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/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="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/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="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/chating_message_notice.png" mode=""></image>
  23. <text style="margin-left: 8rpx">群公告</text>
  24. </view>
  25. <view @click.stop="toGroupAnnouncement(false)">
  26. <image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/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="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/group_calling_icon.png" />
  36. <text>{{ `${callingData.participant.length}人正在${callingData.invitation.mediaType === 'video' ? '视频' : '语音'}通话` }}</text>
  37. <image class="arrow" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/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="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/common_call.png"
  60. srcset=""/> -->
  61. <u-icon @click="goSetting" class="action_item" name="more-dot-fill" size="23" color="#333"></u-icon>
  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.switchTab({
  152. url: '/pages/im/conversationList/index'
  153. });
  154. },
  155. goSetting() {
  156. const url = this.isSingle ? '/pages_im/pages/conversation/singleSettings/index' : '/pages_im/pages/conversation/groupSettings/index';
  157. uni.navigateTo({url});
  158. },
  159. joinRtc() {
  160. callingModule.joinRoomLiveChat(this.callingData);
  161. },
  162. routeCall() {
  163. if (!this.$store.getters.storeCurrentConversation.groupID) {
  164. uni.$emit(PageEvents.RtcCall);
  165. return;
  166. }
  167. IMSDK.asyncApi('signalingGetRoomByGroupID', IMSDK.uuid(), this.$store.getters.storeCurrentConversation.groupID).then(({ data }) => {
  168. if (data.invitation) {
  169. uni.showModal({
  170. title: '提示',
  171. content: '群通话进行中,是否直接加入?',
  172. confirmText: '确认',
  173. cancelText: '取消',
  174. success: (res) => {
  175. if (res.confirm) {
  176. callingModule.joinRoomLiveChat(data);
  177. }
  178. }
  179. });
  180. } else {
  181. uni.$emit(PageEvents.RtcCall);
  182. }
  183. });
  184. },
  185. getOnlineState() {
  186. IMSDK.asyncApi('subscribeUsersStatus', IMSDK.uuid(), [this.storeCurrentConversation.userID])
  187. .then(({ data }) => {
  188. console.log('getOnlineState', 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. console.log('getOnlineStateErr', 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. display: inherit;
  259. border: 2rpx solid #e8eaef;
  260. ::v-deep .u-navbar__content__left {
  261. padding: 0;
  262. }
  263. .chating_info {
  264. @include vCenterBox();
  265. flex-direction: column;
  266. &_single {
  267. margin-bottom: 24rpx;
  268. }
  269. .conversation_info {
  270. flex-direction: row;
  271. justify-content: center;
  272. @include vCenterBox();
  273. .title {
  274. @include nomalEllipsis();
  275. max-width: 280rpx;
  276. font-size: 14px;
  277. font-weight: 500;
  278. }
  279. .sub_title {
  280. margin-left: 8rpx;
  281. }
  282. }
  283. .online_state {
  284. @include vCenterBox();
  285. flex-direction: row;
  286. margin-top: 6rpx;
  287. // position: absolute;
  288. // top: 2px;
  289. // left: 50%;
  290. // transform: translateX(-50%);
  291. font-size: 20rpx;
  292. color: #999;
  293. .dot {
  294. background-color: #10cc64;
  295. width: 12rpx;
  296. height: 12rpx;
  297. border-radius: 50%;
  298. margin-right: 12rpx;
  299. }
  300. .online_str {
  301. @include nomalEllipsis();
  302. max-width: 280rpx;
  303. }
  304. }
  305. }
  306. ::v-deep .u-navbar__content__right {
  307. padding: 0;
  308. }
  309. .right_action {
  310. @include vCenterBox();
  311. flex-direction: row;
  312. margin-right: 24rpx;
  313. .action_item {
  314. padding: 12rpx;
  315. }
  316. .u-icon {
  317. margin-left: 12rpx;
  318. }
  319. }
  320. }
  321. .back_view{
  322. width:45px;
  323. height: 40px;
  324. }
  325. .back_icon {
  326. padding: 24rpx;
  327. padding-left: 0;
  328. width: 12px;
  329. height: 20px
  330. }
  331. .group_announcement_tab {
  332. display: flex;
  333. flex-direction: column;
  334. align-items: flex-start;
  335. width: 80%;
  336. position: absolute;
  337. left: 6%;
  338. // bottom: -44px;
  339. margin-top: 40rpx;
  340. padding: 14rpx 32rpx;
  341. background-color: #f0f6ff;
  342. border-radius: 12rpx;
  343. .announcement_header {
  344. @include vCenterBox();
  345. width: 100%;
  346. flex-direction: row;
  347. justify-content: space-between;
  348. margin-bottom: 16rpx;
  349. &_left {
  350. @include vCenterBox();
  351. }
  352. }
  353. .announcement_content {
  354. @include ellipsisWithLine(2);
  355. margin: 0 12rpx;
  356. font-size: 24rpx;
  357. color: #617183;
  358. }
  359. image {
  360. width: 16px;
  361. height: 16px;
  362. min-width: 16px;
  363. }
  364. }
  365. .group_calling_tab {
  366. position: absolute;
  367. left: 0;
  368. width: 80%;
  369. margin-top: 12px;
  370. margin-left: 5%;
  371. padding: 24rpx;
  372. background-color: #f4f9ff;
  373. border-radius: 8rpx;
  374. color: #5496eb;
  375. font-size: 24rpx;
  376. .base_row {
  377. display: flex;
  378. align-items: center;
  379. image {
  380. width: 10px;
  381. height: 10px;
  382. }
  383. text {
  384. margin-left: 16rpx;
  385. }
  386. .arrow {
  387. width: 9px;
  388. height: 6px;
  389. position: absolute;
  390. right: 24rpx;
  391. }
  392. }
  393. .member_row {
  394. display: flex;
  395. // justify-content: space-between;
  396. flex-wrap: wrap;
  397. padding: 24rpx 28rpx;
  398. margin-top: 24rpx;
  399. background-color: #fff;
  400. border-bottom: 1px solid rgba(151, 151, 151, 0.16);
  401. border-top-left-radius: 8rpx;
  402. border-top-right-radius: 8rpx;
  403. .u-avatar {
  404. margin-bottom: 16rpx;
  405. &:not(:nth-child(6n)) {
  406. margin-right: calc(6% / 2);
  407. }
  408. }
  409. }
  410. .action_row {
  411. display: flex;
  412. justify-content: center;
  413. padding: 24rpx;
  414. background-color: #fff;
  415. font-size: 28rpx;
  416. border-bottom-left-radius: 8rpx;
  417. border-bottom-right-radius: 8rpx;
  418. }
  419. }
  420. </style>