member-profile.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="memeber-profile">
  3. <div class="memeber-profile-main">
  4. <img
  5. class="avatar"
  6. :src="
  7. userInfo?.avatar ||
  8. 'https://news-info.ks3-cn-beijing.ksyuncs.com/07/1690787574969.png'
  9. "
  10. onerror="this.src='https://news-info.ks3-cn-beijing.ksyuncs.com/07/1690787574969.png'"
  11. />
  12. <ul class="list">
  13. <h1>{{ userInfo?.nick || userInfo?.userID }}</h1>
  14. <li>
  15. <label>ID:</label>
  16. <span>{{ userInfo?.userID }}</span>
  17. </li>
  18. <li>
  19. <label>{{ $t('TUIContact.个性签名') }}:</label>
  20. <span>{{ userInfo?.selfSignature }}</span>
  21. </li>
  22. </ul>
  23. </div>
  24. <div class="memeber-profile-footer">
  25. <div
  26. class="button"
  27. @click="enter(userInfo?.userID, 'C2C')"
  28. v-if="showEnter()"
  29. >
  30. {{ $t('TUIContact.发送消息') }}
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script lang="ts">
  36. import TIM from '../../../../TUICore/tim';
  37. import { reactive, toRefs, watch, watchEffect, defineComponent } from 'vue';
  38. import manage from './manage.vue';
  39. const memberProfile = defineComponent({
  40. props: {
  41. userInfo: {
  42. type: Object,
  43. default: () => ({})
  44. }
  45. },
  46. setup(props: any, ctx: any) {
  47. const TUIServer = manage?.TUIServer;
  48. const data = reactive({
  49. isFriendShip: false,
  50. userInfo: {},
  51. self: {}
  52. });
  53. watchEffect(() => {
  54. data.self = props.self;
  55. });
  56. watch(
  57. () => props.userInfo,
  58. async (newVal: any, oldVal: any) => {
  59. if (newVal === oldVal) return;
  60. const res = await TUIServer.getUserProfile([props?.userInfo?.userID]);
  61. data.userInfo = res?.data[0];
  62. checkFriend();
  63. },
  64. {
  65. deep: true,
  66. immediate: true
  67. }
  68. );
  69. const enter = async (ID: any, type: string) => {
  70. const name = `${type}${ID}`;
  71. TUIServer.TUICore.TUIServer.TUIConversation.getConversationProfile(
  72. name
  73. ).then((imResponse: any) => {
  74. // 通知 TUIConversation 添加当前会话
  75. // Notify TUIConversation to toggle the current conversation
  76. TUIServer.TUICore.TUIServer.TUIConversation.handleCurrentConversation(
  77. imResponse.data.conversation
  78. );
  79. });
  80. };
  81. const checkFriend = async () => {
  82. if (!(data.userInfo as any).userID) return;
  83. const relation = await TUIServer.checkFriend(
  84. (data.userInfo as any).userID,
  85. TIM.TYPES.SNS_CHECK_TYPE_BOTH
  86. );
  87. data.isFriendShip =
  88. relation === TIM.TYPES.SNS_TYPE_BOTH_WAY ? true : false;
  89. };
  90. const showEnter = () => {
  91. return data.isFriendShip || !TUIServer?.TUICore?.isOfficial;
  92. };
  93. return {
  94. ...toRefs(data),
  95. enter,
  96. showEnter
  97. };
  98. }
  99. });
  100. export default memberProfile;
  101. </script>
  102. <style lang="scss" scoped>
  103. @import url('../../../styles/common.scss');
  104. @import url('../../../styles/icon.scss');
  105. .memeber-profile {
  106. flex: 1;
  107. display: flex;
  108. flex-direction: column;
  109. &-main {
  110. display: flex;
  111. flex-direction: row;
  112. width: 100%;
  113. overflow: hidden;
  114. img {
  115. width: 60Px;
  116. height: 60Px;
  117. border-radius: 8Px;
  118. margin: 20Px 10Px 20Px 20Px;
  119. }
  120. .list {
  121. flex: 1;
  122. overflow: hidden;
  123. margin: 20Px 10Px;
  124. font-weight: 400;
  125. li {
  126. color: #999999;
  127. }
  128. h1,
  129. li {
  130. overflow: hidden;
  131. white-space: nowrap;
  132. text-overflow: ellipsis;
  133. }
  134. }
  135. }
  136. &-footer {
  137. border-top: 10Px solid #f4f5f9;
  138. padding: 14Px;
  139. display: flex;
  140. flex-direction: column;
  141. align-items: center;
  142. justify-content: center;
  143. .button {
  144. width: 100Px;
  145. font-size: 14Px;
  146. cursor: pointer;
  147. background-color: #006eff;
  148. color: #ffffff;
  149. padding: 8Px 20Px;
  150. border-radius: 4Px;
  151. border: none;
  152. font-size: 14Px;
  153. text-align: center;
  154. line-height: 20Px;
  155. }
  156. }
  157. }
  158. </style>