index.vue 13 KB

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