index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <view class="user_card_container">
  3. <u-loading-page :loading="isLoading" loading-text="loading..."></u-loading-page>
  4. <custom-nav-bar title="" />
  5. <view v-if="!isLoading" style="flex: 1; display: flex; flex-direction: column">
  6. <view class="base_info">
  7. <my-avatar :desc="sourceUserInfo.remark || sourceUserInfo.nickname" :src="sourceUserInfo.faceURL" size="46" />
  8. <view class="user_name">
  9. <text class="text">{{ getShowName }}</text>
  10. <text class="id" @click="copy(sourceUserInfo.userID)">{{ sourceUserInfo.userID }}</text>
  11. </view>
  12. <view class="add_btn" @click="toAddFriend" v-if="trySendRequest">
  13. <u-button type="primary" icon="man-add" text="添加"></u-button>
  14. </view>
  15. </view>
  16. <view v-if="memberInfo" class="info_row">
  17. <user-info-row-item lable="群昵称" :content="memberInfo.nickname" />
  18. <user-info-row-item lable="入群时间" :content="getJoinGroupTime" />
  19. <user-info-row-item lable="入群方式" :content="getJoinSource" />
  20. </view>
  21. <view v-if="!isSelf && (showSetRole || showSetMuteMember)" class="info_row">
  22. <user-info-row-item v-if="showSetRole" lable="设为管理员" arrow>
  23. <u-switch :loading="switchLoading" @change="changeMemberRole" :asyncChange="true" size="20" :value="isAdmin" />
  24. </user-info-row-item>
  25. <user-info-row-item v-if="showSetMuteMember" @click="toMuteMember" arrow lable="设置禁言">
  26. <view class="mute_right">
  27. <text>{{ getMuteTime }}</text>
  28. <u-icon name="arrow-right" color="#999" size="20"></u-icon>
  29. </view>
  30. </user-info-row-item>
  31. </view>
  32. <view v-if="organizationData.length > 0" class="company_row info_row">
  33. <text class="desc_title">组织信息</text>
  34. <view class="company_info">
  35. <user-info-row-item lable="企业/组织" :content="organizationData[0].companyName" />
  36. <user-info-row-item lable="部门" :content="organizationData[0].departmentName" />
  37. <user-info-row-item lable="职位" :content="organizationData[0].position || '-'" />
  38. <view v-if="organizationData.length > 1" @click="toFullOrganization" class="more_dep">
  39. <text>查看更多</text>
  40. <u-icon name="arrow-right" color="#1D6BED"></u-icon>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="info_row">
  45. <user-info-row-item v-if="!isSelf" @click="toMoreInfo" lable="个人资料" arrow />
  46. <user-info-row-item @click="toPublisher" lable="查看动态" arrow />
  47. </view>
  48. <view v-if="!isSelf" class="action_row">
  49. <view v-if="!isBlack" @click="callUser" class="action_item">
  50. <img src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/user_card_call.png" alt="" />
  51. <text>音视频通话</text>
  52. </view>
  53. <view @click="toDesignatedConversation" class="action_item">
  54. <img src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/user_card_message.png" alt="" />
  55. <text>发消息</text>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { mapGetters } from 'vuex';
  63. import { CommonIsAllow } from '../../../constant';
  64. import { getUserInDepartment } from '../../../api/orgnizaition';
  65. import { navigateToDesignatedConversation, callingModule } from '../../../util/imCommon';
  66. import IMSDK, { GroupJoinSource, GroupMemberRole, SessionType } from 'openim-uniapp-polyfill';
  67. import MyAvatar from '../../../components/MyAvatar/index.vue';
  68. import CustomNavBar from '../../../components/CustomNavBar/index.vue';
  69. import UserInfoRowItem from './components/UserInfoRowItem.vue';
  70. import dayjs from 'dayjs';
  71. import { businessSearchUserInfo } from '../../../api/login';
  72. export default {
  73. components: {
  74. CustomNavBar,
  75. MyAvatar,
  76. UserInfoRowItem
  77. },
  78. data() {
  79. return {
  80. isLoading: true,
  81. sourceID: '',
  82. sourceUserInfo: {},
  83. organizationData: [],
  84. memberInfo: null,
  85. switchLoading: false,
  86. showSetRole: false,
  87. showSetMuteMember: false,
  88. disableAdd: false
  89. };
  90. },
  91. computed: {
  92. ...mapGetters(['storeFriendList', 'storeBlackList', 'storeCurrentMemberInGroup', 'storeCurrentUserID', 'storeSelfInfo', 'storeOrganizationData']),
  93. isFriend() {
  94. return this.storeFriendList.findIndex((friend) => friend.userID === this.sourceID) !== -1;
  95. },
  96. isBlack() {
  97. return this.storeBlackList.some((black) => black.userID === this.sourceID);
  98. },
  99. trySendRequest() {
  100. return !this.isFriend && !this.isSelf && !this.disableAdd && this.sourceUserInfo.allowAddFriend !== 2;
  101. },
  102. isSelf() {
  103. return this.sourceID === this.storeSelfInfo.userID;
  104. },
  105. isAdmin() {
  106. return this.memberInfo?.roleLevel === GroupMemberRole.Admin;
  107. },
  108. getJoinGroupTime() {
  109. return this.memberInfo ? dayjs(this.memberInfo.joinTime).format('YYYY-MM-DD') : '';
  110. },
  111. getJoinSource() {
  112. if (!this.memberInfo) {
  113. return '';
  114. }
  115. switch (this.memberInfo.joinSource) {
  116. case GroupJoinSource.Invitation:
  117. return '邀请进群';
  118. case GroupJoinSource.QrCode:
  119. return '扫码进群';
  120. case GroupJoinSource.Search:
  121. return '搜索进群';
  122. default:
  123. return '-';
  124. }
  125. },
  126. getShowName() {
  127. let suffix = '';
  128. if (this.sourceUserInfo.remark) {
  129. suffix = `(${this.sourceUserInfo.remark})`;
  130. }
  131. return this.sourceUserInfo.nickname + suffix;
  132. },
  133. getMuteTime() {
  134. if (!this.memberInfo.muteEndTime || this.memberInfo.muteEndTime < Date.now()) {
  135. return '';
  136. }
  137. return dayjs(this.memberInfo.muteEndTime).format('YYYY/MM/DD HH:mm');
  138. }
  139. },
  140. onLoad(options) {
  141. const { sourceID, sourceInfo, memberInfo, disableAdd } = options;
  142. this.disableAdd = disableAdd ? JSON.parse(disableAdd) : false;
  143. if (sourceID) {
  144. this.sourceID = sourceID;
  145. } else {
  146. const info = JSON.parse(sourceInfo);
  147. this.sourceID = info.userID;
  148. }
  149. this.getSourceUserInfo();
  150. if (memberInfo) {
  151. this.memberInfo = JSON.parse(memberInfo);
  152. this.checkCurrentMember();
  153. }
  154. this.getOrganizationData();
  155. this.setIMListener();
  156. },
  157. onUnload() {
  158. this.disposeIMListener();
  159. },
  160. methods: {
  161. copy(userID) {
  162. uni.setClipboardData({
  163. showToast: false,
  164. data: userID,
  165. success: function () {
  166. uni.showToast({
  167. icon: 'none',
  168. title: '复制成功'
  169. });
  170. }
  171. });
  172. },
  173. toPublisher() {
  174. uni.$u.route('/pages/moments/designatedMoments/index', {
  175. baseUserInfo: JSON.stringify({
  176. userID: this.sourceUserInfo.userID,
  177. nickname: this.sourceUserInfo.nickname,
  178. faceURL: this.sourceUserInfo.faceURL
  179. })
  180. });
  181. },
  182. async getSourceUserInfo() {
  183. let info = {};
  184. const friendInfo = this.storeFriendList.find((item) => item.userID === this.sourceID);
  185. if (friendInfo) {
  186. info = { ...friendInfo };
  187. } else {
  188. const { data } = await IMSDK.asyncApi(IMSDK.IMMethods.GetUsersInfo, IMSDK.uuid(), [this.sourceID]);
  189. info = { ...(data[0] ?? {}) };
  190. }
  191. this.sourceUserInfo = {
  192. ...info
  193. };
  194. this.isLoading = false;
  195. try {
  196. const { total, users } = await businessSearchUserInfo(this.sourceID);
  197. if (total > 0) {
  198. info = {
  199. ...info,
  200. ...users[0]
  201. };
  202. }
  203. } catch (err) {
  204. console.log(err);
  205. }
  206. this.sourceUserInfo = {
  207. ...info
  208. };
  209. },
  210. getOrganizationData() {
  211. getUserInDepartment(this.sourceID).then((res) => {
  212. this.organizationData = res.users.map((item) => ({
  213. companyName: this.$store.getters.storeOrganizationData.current.name,
  214. departmentName: item.members[0].department.name,
  215. position: item.members[0].position
  216. }));
  217. });
  218. },
  219. async checkCurrentMember() {
  220. let role;
  221. if (this.storeCurrentMemberInGroup.groupID === this.memberInfo.groupID) {
  222. role = this.storeCurrentMemberInGroup.roleLevel;
  223. } else {
  224. try {
  225. const { data } = await IMSDK.asyncApi(IMSDK.IMMethods.GetSpecifiedGroupMembersInfo, IMSDK.uuid(), {
  226. groupID: this.memberInfo.groupID,
  227. userIDList: [this.storeCurrentUserID]
  228. });
  229. role = data[0]?.roleLevel;
  230. } catch (e) {}
  231. }
  232. this.showSetRole = role === GroupMemberRole.Owner;
  233. this.showSetMuteMember = role === GroupMemberRole.Owner || (role === GroupMemberRole.Admin && this.memberInfo.roleLevel === GroupMemberRole.Nomal);
  234. },
  235. toAddFriend() {
  236. uni.$u.route('/pages/common/sendAddRequest/index', {
  237. isGroup: false,
  238. sourceID: this.sourceID,
  239. isScan: false,
  240. notNeedVerification: false
  241. });
  242. },
  243. callUser() {
  244. uni.showActionSheet({
  245. itemList: ['语音通话', '视频通话'],
  246. cancelText: '取消',
  247. success: ({ tapIndex }) => {
  248. callingModule.startLiveChat(!!tapIndex, [this.sourceID], '', this.$store.getters.storeCurrentUserID);
  249. }
  250. });
  251. },
  252. toFullOrganization() {
  253. uni.$u.route('/pages/common/fullOrganization/index', {
  254. organizationData: JSON.stringify(this.organizationData)
  255. });
  256. },
  257. toDesignatedConversation() {
  258. navigateToDesignatedConversation(this.sourceID, SessionType.Single, this.memberInfo !== null).catch(() => uni.$u.toast('获取会话信息失败'));
  259. },
  260. toMoreInfo() {
  261. uni.navigateTo({
  262. url: `/pages/common/userCardMore/index?sourceInfo=${JSON.stringify(this.sourceUserInfo)}`
  263. });
  264. },
  265. changeMemberRole(flag) {
  266. this.switchLoading = true;
  267. const newRole = flag ? GroupMemberRole.Admin : GroupMemberRole.Nomal;
  268. IMSDK.asyncApi(IMSDK.IMMethods.SetGroupMemberInfo, IMSDK.uuid(), {
  269. groupID: this.memberInfo.groupID,
  270. userID: this.sourceUserInfo.userID,
  271. roleLevel: newRole
  272. })
  273. .catch(() => uni.$u.toast('设置失败'))
  274. .finally(() => (this.switchLoading = false));
  275. },
  276. toMuteMember() {
  277. uni.navigateTo({
  278. url: `/pages/common/setMemberMute/index?sourceInfo=${JSON.stringify([this.memberInfo])}`
  279. });
  280. },
  281. friendInfoChangeHandler({ data }) {
  282. if (data.userID === this.sourceUserInfo.userID) {
  283. this.sourceUserInfo = {
  284. ...this.sourceUserInfo,
  285. ...data
  286. };
  287. }
  288. },
  289. groupMemberInfoChangeHandler({ data }) {
  290. if (data.userID === this.memberInfo.userID && data.groupID === this.memberInfo.groupID) {
  291. this.memberInfo = {
  292. ...this.memberInfo,
  293. ...data
  294. };
  295. }
  296. },
  297. setIMListener() {
  298. uni.$on(IMSDK.IMEvents.OnFriendInfoChanged, this.friendInfoChangeHandler);
  299. uni.$on(IMSDK.IMEvents.OnGroupMemberInfoChanged, this.groupMemberInfoChangeHandler);
  300. },
  301. disposeIMListener() {
  302. uni.$off(IMSDK.IMEvents.OnFriendInfoChanged, this.friendInfoChangeHandler);
  303. uni.$off(IMSDK.IMEvents.OnGroupMemberInfoChanged, this.groupMemberInfoChangeHandler);
  304. }
  305. }
  306. };
  307. </script>
  308. <style lang="scss" scoped>
  309. .user_card_container {
  310. @include colBox(false);
  311. height: 100vh;
  312. background-color: #f6f6f6;
  313. overflow-y: auto;
  314. position: relative;
  315. .base_info {
  316. @include vCenterBox();
  317. background-color: #fff;
  318. padding: 44rpx;
  319. margin-bottom: 18rpx;
  320. .add_btn {
  321. width: 140rpx;
  322. height: 60rpx;
  323. margin-left: auto;
  324. .u-button {
  325. width: 140rpx;
  326. height: 60rpx;
  327. }
  328. }
  329. .u-avatar {
  330. margin-right: 24rpx;
  331. }
  332. .user_name {
  333. display: flex;
  334. flex-direction: column;
  335. justify-content: space-between;
  336. margin-bottom: 12rpx;
  337. height: 46px;
  338. .text {
  339. @include nomalEllipsis();
  340. max-width: 300rpx;
  341. }
  342. }
  343. .company {
  344. font-size: 28rpx;
  345. color: $u-primary;
  346. }
  347. }
  348. .info_row {
  349. background-color: #fff;
  350. margin-bottom: 24rpx;
  351. }
  352. .mute_right {
  353. display: flex;
  354. align-items: center;
  355. }
  356. .company_row {
  357. padding: 20rpx 0;
  358. .desc_title {
  359. padding-left: 44rpx;
  360. }
  361. .company_info {
  362. .more_dep {
  363. display: flex;
  364. justify-content: center;
  365. color: #1d6bed;
  366. }
  367. }
  368. ::v-deep .title {
  369. width: 200rpx;
  370. color: #999 !important;
  371. }
  372. }
  373. .action_row {
  374. @include vCenterBox();
  375. align-items: flex-end;
  376. justify-content: space-around;
  377. margin: 44rpx;
  378. flex: 1;
  379. .action_item {
  380. width: 100%;
  381. @include colBox(true);
  382. flex-direction: row;
  383. align-items: center;
  384. justify-content: center;
  385. padding: 22rpx 0;
  386. background: $u-primary;
  387. color: #fff;
  388. border-radius: 6px;
  389. &:first-child {
  390. background-color: #fff;
  391. color: $uni-text-color;
  392. margin-right: 24rpx;
  393. }
  394. img {
  395. margin-right: 16rpx;
  396. width: 40rpx;
  397. height: 40rpx;
  398. }
  399. }
  400. }
  401. .id {
  402. font-size: 24rpx;
  403. color: #999;
  404. }
  405. .online_state {
  406. @include vCenterBox();
  407. margin-left: 24rpx;
  408. font-size: 24rpx;
  409. color: #999;
  410. .dot {
  411. background-color: #10cc64;
  412. width: 12rpx;
  413. height: 12rpx;
  414. border-radius: 50%;
  415. margin-right: 12rpx;
  416. }
  417. .online_str {
  418. @include nomalEllipsis();
  419. max-width: 280rpx;
  420. }
  421. }
  422. }
  423. </style>