ChatHeader.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <template>
  2. <view class="chat_header" :class="$companyUserIsLogin()?'ybc':'yc'">
  3. <view class="self_info">
  4. <block v-if="$companyUserIsLogin()">
  5. <my-avatar :src="storeSelfInfo.faceURL" :desc="storeSelfInfo.nickname" size="46" />
  6. <view class="msgIcon">
  7. <view class="msgTitle">{{ storeSelfInfo.nickname }}</view>
  8. <view class="msgSubTitle">管家</view>
  9. </view>
  10. <!-- <text class="nickname">消息{{getUnReadCount()}}</text> -->
  11. </block>
  12. <block v-else>
  13. <!-- <my-avatar :src="storeSelfInfo.faceURL" :desc="storeSelfInfo.nickname" size="46" />
  14. <text class="nickname">{{ storeSelfInfo.nickname }}</text> -->
  15. <text class="nickname">消息{{getUnReadCount()}}</text>
  16. </block>
  17. <view class="self_info_desc">
  18. <view class="user_state">
  19. <!-- <text class="nickname">{{ storeSelfInfo.nickname }}</text> -->
  20. <view v-if="!storeReinstall">
  21. <view class="tag" v-if="storeIsSyncing">
  22. <image class="loading" style="height: 24rpx; width: 24rpx" src="../../../../static/images/loading.png" alt="" />
  23. <text class="status">同步中</text>
  24. </view>
  25. <view class="tag" v-if="connectStart == 0">
  26. <image class="loading" style="height: 24rpx; width: 24rpx" src="../../../../static/images/loading.png" alt="" />
  27. <text class="status">连接中</text>
  28. </view>
  29. <view class="err-tag" v-if="connectStart == -1">
  30. <image style="height: 24rpx; width: 24rpx" src="../../../../static/images/sync_error.png" alt="" />
  31. <text class="status">连接失败</text>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="right_action">
  38. <!-- <view @click="toNativeCallHistory" class="call_icon">
  39. <image src="../../../../static/images/common_call.png" ></image>
  40. </view> -->
  41. <view @click="showMore" v-if="showMoreMenu" class="more_icon">
  42. <image src="../../../../static/images/new/add_icon24.svg"></image>
  43. </view>
  44. <u-overlay :show="moreMenuVisible" @click="moreMenuVisible = false" opacity="0">
  45. <view :style="{ top: popMenuPosition.top, right: popMenuPosition.right }" class="more_menu">
  46. <view @click="clickMenu(item)" v-for="item in moreMenus" :key="item.idx" class="menu_item">
  47. <image :src="item.icon" mode=""></image>
  48. <text class="es-mr-10">{{ item.title }}</text>
  49. <view v-if="item.num>0" style="background: red;color: white;border-radius: 50%;padding: 10rpx;"></view>
  50. </view>
  51. </view>
  52. </u-overlay>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import { mapGetters } from 'vuex';
  58. import MyAvatar from '../../../../components/MyAvatar/index.vue';
  59. import IMSDK from 'openim-uniapp-polyfill';
  60. import { scanQrCodeResult } from '../../../../util/imCommon';
  61. import { callingModule } from '../../../../util/imCommon';
  62. export default {
  63. name: 'ChatHeader',
  64. components: {
  65. MyAvatar
  66. },
  67. props: {},
  68. data() {
  69. return {
  70. connectStart: -2,
  71. moreMenuVisible: false,
  72. popMenuPosition: {
  73. top: 0,
  74. right: 0
  75. },
  76. showMoreMenu:true,
  77. moreMenus: [
  78. // {
  79. // idx: 0,
  80. // title: '扫一扫',
  81. // icon: require('../../../../static/images/new/scan_icon24.svg')
  82. // },
  83. // {
  84. // idx: 1,
  85. // title: '添加好友',
  86. // icon: require('../../../../static/images/new/add_friend_icon24.svg')
  87. // },
  88. // {
  89. // idx: 2,
  90. // title: '添加群聊',
  91. // icon: require('../../../../static/images/new/add_group_chat_icon24.svg')
  92. // }
  93. // ,{
  94. // idx: 3,
  95. // title: '创建群聊',
  96. // icon: require('../../../../static/images/new/create_group_chat_icon24.svg')
  97. // }
  98. // ,{
  99. // idx: 4,
  100. // title: '视频会议',
  101. // icon: require('../../../../static/images/new/video_conference_icon24.svg')
  102. // }
  103. ]
  104. };
  105. },
  106. computed: {
  107. ...mapGetters(['storeSelfInfo', 'storeIsSyncing', 'storeReinstall','storeUnReadCount','storeUnHandleFriendApplicationNum','storeUnHandleGroupApplicationNum'])
  108. },
  109. mounted() {
  110. this.subscribeAll();
  111. this.initMenu();
  112. uni.$on('refreshIMMenu', () => {
  113. this.initMenu();
  114. });
  115. },
  116. beforeDestroy() {
  117. this.unsubscribeAll();
  118. },
  119. methods: {
  120. initMenu(){
  121. this.moreMenus=[];
  122. if (this.$companyUserIsLogin()) {
  123. this.showMoreMenu=true;
  124. this.addCompanyMenu();
  125. } else {
  126. this.showMoreMenu=true;
  127. this.addUserMenu();
  128. }
  129. },
  130. addCompanyMenu() {
  131. this.moreMenus.push({idx: 0,title: '扫一扫',icon: require('../../../../static/images/new/scan_icon24.svg')});
  132. this.moreMenus.push({idx: 1,title: '添加好友',icon: require('../../../../static/images/new/add_friend_icon24.svg')});
  133. // this.moreMenus.push({idx: 2,title: '添加群组',icon: require('../../../../static/images/new/add_group_chat_icon24.svg')});
  134. this.moreMenus.push({idx: 3, title: '我的好友', icon: require('../../../../static/images/new/add_friend_icon24.svg') });
  135. // this.moreMenus.push({idx: 4, title: '创建群组', icon: require('../../../../static/images/new/add_group_chat_icon24.svg') });
  136. const num = this.storeUnHandleFriendApplicationNum*1+this.storeUnHandleGroupApplicationNum*1
  137. this.moreMenus.push({idx: 5, title: '通讯录', icon: require('../../../../static/images/new/add_friend_icon24.svg') ,num});
  138. },
  139. addUserMenu() {
  140. this.moreMenus.push({idx: 0,title: '扫一扫',icon: require('../../../../static/images/new/scan_icon24.svg')});
  141. this.moreMenus.push({idx: 1,title: '添加好友',icon: require('../../../../static/images/new/add_friend_icon24.svg')});
  142. // this.moreMenus.push({idx: 2,title: '添加群组',icon: require('../../../../static/images/new/add_group_chat_icon24.svg')});
  143. this.moreMenus.push({idx: 3, title: '我的好友', icon: require('../../../../static/images/new/add_friend_icon24.svg') });
  144. const num = this.storeUnHandleFriendApplicationNum*1+this.storeUnHandleGroupApplicationNum*1
  145. this.moreMenus.push({idx: 5, title: '通讯录', icon: require('../../../../static/images/new/add_friend_icon24.svg') ,num});
  146. },
  147. toNativeCallHistory() {
  148. uni.navigateTo({
  149. url: '/pages/moments/index/indexs'
  150. });
  151. },
  152. setStateStart() {
  153. this.connectStart = 0;
  154. },
  155. setStateSuccess() {
  156. // #ifdef APP-PLUS
  157. IMSDK.asyncApi('getSignalingInvitationInfoStartApp', IMSDK.uuid()).then(({ data }) => {
  158. callingModule.launchLiveChat(data);
  159. });
  160. // #endif
  161. this.connectStart = 1;
  162. },
  163. setStateError() {
  164. this.connectStart = -1;
  165. },
  166. subscribeAll() {
  167. IMSDK.subscribe(IMSDK.IMEvents.OnConnecting, this.setStateStart);
  168. IMSDK.subscribe(IMSDK.IMEvents.OnConnectSuccess, this.setStateSuccess);
  169. IMSDK.subscribe(IMSDK.IMEvents.OnConnectFailed, this.setStateError);
  170. },
  171. unsubscribeAll() {
  172. IMSDK.unsubscribe(IMSDK.IMEvents.OnConnecting, this.setStateStart);
  173. IMSDK.unsubscribe(IMSDK.IMEvents.OnConnectSuccess, this.setStateSuccess);
  174. IMSDK.unsubscribe(IMSDK.IMEvents.OnConnectFailed, this.setStateError);
  175. },
  176. clickMenu({ idx }) {
  177. switch (idx) {
  178. case 0:
  179. // uni.scanCode({
  180. // scanType: ['qrCode'],
  181. // success: ({ result }) => scanQrCodeResult(result)
  182. // });
  183. uni.navigateTo({
  184. url: '/pages_watch/healthMonitoring/scanCode?typeFun=getIndexScanCode&isFromIm=1'
  185. });
  186. break;
  187. case 1:
  188. case 2:
  189. {
  190. uni.navigateTo({
  191. url: `/pages_im/pages/common/searchUserOrGroup/index?isSearchGroup=${idx === 2}`
  192. });
  193. }
  194. break;
  195. case 3:
  196. uni.navigateTo({
  197. //url: `/pages_im/pages/contact/index/index`,
  198. url: `/pages_im/pages/contact/friendList/index`
  199. });
  200. break;
  201. case 4:
  202. uni.navigateTo({
  203. url: `/pages_im/pages/common/createGroup/index`
  204. });
  205. break;
  206. // case 4:
  207. // uni.$u.route('/pages_im/pages/common/meetingCenter/index');
  208. // break;
  209. case 5:
  210. uni.navigateTo({
  211. url: `/pages_im/pages/contact/index/index`
  212. });
  213. break;
  214. default:
  215. break;
  216. }
  217. },
  218. async showMore() {
  219. const { right, bottom } = await this.getEl('.more_icon');
  220. this.popMenuPosition.right = uni.getWindowInfo().windowWidth - right + 'px';
  221. this.popMenuPosition.top = bottom + 'px';
  222. this.moreMenuVisible = true;
  223. },
  224. getEl(el) {
  225. return new Promise((resolve) => {
  226. const query = uni.createSelectorQuery().in(this);
  227. query.select(el).boundingClientRect((data) => {
  228. // 存在data,且存在宽和高,视为渲染完毕
  229. resolve(data);
  230. }).exec();
  231. });
  232. },
  233. getUnReadCount(){
  234. if(this.storeUnReadCount>0){
  235. return "("+this.storeUnReadCount+")";
  236. }else{
  237. return "";
  238. }
  239. }
  240. }
  241. };
  242. </script>
  243. <style lang="scss" scoped>
  244. @keyframes loading {
  245. 0% {
  246. transform: rotate(0deg);
  247. }
  248. 100% {
  249. transform: rotate(360deg);
  250. }
  251. }
  252. .chat_header {
  253. display: flex;
  254. justify-content: center;
  255. align-items: center;
  256. position: relative;
  257. padding: 36rpx 44rpx;
  258. margin-top: var(--status-bar-height);
  259. background: #F5F7FA;
  260. .self_info {
  261. display: flex;
  262. justify-content: space-between;
  263. align-items: center;
  264. .nickname {
  265. font-size: 36rpx;
  266. font-weight: bold;
  267. color: #333;
  268. }
  269. &_desc {
  270. @include colBox(true);
  271. // margin-left: 24rpx;
  272. color: $uni-text-color;
  273. .company {
  274. @include nomalEllipsis();
  275. font-size: 24rpx;
  276. margin-bottom: 10rpx;
  277. max-width: 300rpx;
  278. }
  279. .user_state {
  280. @include vCenterBox();
  281. .nickname {
  282. @include nomalEllipsis();
  283. font-size: 26rpx;
  284. max-width: 240rpx;
  285. }
  286. .err-tag {
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. width: 152rpx;
  291. height: 44rpx;
  292. background: #ffe1dd;
  293. border-radius: 12rpx 12rpx 12rpx 12rpx;
  294. margin-left: 8rpx;
  295. .status {
  296. font-size: 24rpx;
  297. margin-left: 8rpx;
  298. font-weight: 400;
  299. color: #ff381f;
  300. }
  301. }
  302. .tag {
  303. display: flex;
  304. justify-content: center;
  305. align-items: center;
  306. width: 152rpx;
  307. height: 44rpx;
  308. background: #f2f8ff;
  309. border-radius: 12rpx 12rpx 12rpx 12rpx;
  310. margin-left: 8rpx;
  311. .loading {
  312. animation: loading 1.5s infinite;
  313. }
  314. .status {
  315. font-size: 24rpx;
  316. margin-left: 8rpx;
  317. font-weight: 400;
  318. color: #0089ff;
  319. }
  320. }
  321. .online_state {
  322. @include vCenterBox();
  323. margin-left: 24rpx;
  324. font-size: 24rpx;
  325. .dot {
  326. background-color: #10cc64;
  327. width: 12rpx;
  328. height: 12rpx;
  329. border-radius: 50%;
  330. margin-right: 12rpx;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. .right_action {
  337. position: absolute;
  338. right: 40rpx;
  339. display: flex;
  340. .call_icon {
  341. margin-right: 24rpx;
  342. image {
  343. width: 56rpx;
  344. height: 56rpx;
  345. }
  346. }
  347. .more_icon {
  348. image {
  349. width: 56rpx;
  350. height: 56rpx;
  351. }
  352. }
  353. .more_menu {
  354. position: absolute;
  355. // bottom: 0;
  356. // left: 100%;
  357. z-index: 999;
  358. // transform: translate(-100%, 100%);
  359. box-shadow: 0px 0px 6px 2px rgba(0, 0, 0, 0.16);
  360. width: max-content;
  361. border-radius: 12rpx;
  362. background-color: #fff;
  363. .menu_item {
  364. display: flex;
  365. justify-content: flex-start;
  366. align-items: center;
  367. padding: 20rpx 24rpx;
  368. font-size: 32rpx;
  369. color: $uni-text-color;
  370. border-bottom: 1px solid #f0f0f0;
  371. image {
  372. width: 24px;
  373. height: 24px;
  374. margin-right: 24rpx;
  375. }
  376. &:last-child {
  377. border: none;
  378. }
  379. }
  380. }
  381. }
  382. .nickname {
  383. font-size: 36rpx;
  384. color: #222;
  385. font-weight: 400;
  386. margin-left: 0rpx;
  387. }
  388. .msgTitle {
  389. font-size: 34rpx;
  390. color: #000;
  391. font-weight: bold;
  392. margin-left: 20rpx;
  393. }
  394. .msgSubTitle {
  395. font-size: 28rpx;
  396. color: #333;
  397. font-weight: bold;
  398. margin-left: 20rpx;
  399. }
  400. .msgIcon {
  401. display: flex;
  402. flex-direction: column;
  403. justify-content: space-between;
  404. }
  405. }
  406. .ybc {
  407. justify-content: space-between;
  408. }
  409. .yc{
  410. justify-content: center;
  411. }
  412. </style>