manage-profile.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div v-if="!isUniFrameWork" class="memeber-profile">
  3. <div class="memeber-profile-main">
  4. <img
  5. class="avatar"
  6. :src="
  7. userInfoManager.avatar ||
  8. 'https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png'
  9. "
  10. onerror="this.onerror=null;this.src='https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png'"
  11. />
  12. <ul class="list">
  13. <h2>{{ userInfoManager.nick || userInfoManager.userID }}</h2>
  14. <li>
  15. <label>ID:</label>
  16. <span>{{ userInfoManager.userID }}</span>
  17. </li>
  18. <li>
  19. <label>{{ TUITranslateService.t("TUIContact.个性签名") }}:</label>
  20. <span>{{ userInfoManager.selfSignature }}</span>
  21. </li>
  22. </ul>
  23. </div>
  24. <div class="memeber-profile-footer">
  25. <div
  26. v-if="showEnter()"
  27. class="button"
  28. @click="enter(userInfoManager.userID, 'C2C')"
  29. >
  30. {{ TUITranslateService.t("TUIContact.发送消息") }}
  31. </div>
  32. </div>
  33. </div>
  34. <div v-else class="edit-h5">
  35. <main class="main">
  36. <header class="edit-h5-header">
  37. <aside class="left">
  38. <h1>{{ TUITranslateService.t(`TUIGroup.群成员`) }}</h1>
  39. </aside>
  40. <span class="close" @click="close('profile')">{{
  41. TUITranslateService.t(`关闭`)
  42. }}</span>
  43. </header>
  44. <div class="memeber-profile">
  45. <div class="memeber-profile-main">
  46. <img
  47. class="avatar"
  48. :src="
  49. userInfoManager.avatar ||
  50. 'https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png'
  51. "
  52. onerror="this.onerror=null;this.src='https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png'"
  53. />
  54. <ul class="list">
  55. <h1>{{ userInfoManager.nick || userInfoManager.userID }}</h1>
  56. <li>
  57. <label>ID:</label>
  58. <span>{{ userInfoManager.userID }}</span>
  59. </li>
  60. <li>
  61. <label
  62. >{{ TUITranslateService.t("TUIContact.个性签名") }}:</label
  63. >
  64. <span>{{ userInfoManager.selfSignature }}</span>
  65. </li>
  66. </ul>
  67. </div>
  68. <div class="memeber-profile-footer">
  69. <div
  70. v-if="showEnter()"
  71. class="button"
  72. @click="enter(userInfoManager.userID, 'C2C')"
  73. >
  74. {{ TUITranslateService.t("TUIContact.发送消息") }}
  75. </div>
  76. </div>
  77. </div>
  78. </main>
  79. </div>
  80. </template>
  81. <script lang="ts" setup>
  82. import { ref, watch, watchEffect } from "../../../adapter-vue";
  83. import TUIChatEngine, {
  84. TUITranslateService,
  85. TUIUserService,
  86. TUIConversationService,
  87. TUIFriendService,
  88. TUIStore,
  89. StoreName,
  90. } from "@tencentcloud/chat-uikit-engine";
  91. import { TUIGlobal } from "@tencentcloud/universal-api";
  92. import { IUserProfile } from "../../../interface";
  93. import { isUniFrameWork } from "../../../utils/env";
  94. const props = defineProps({
  95. userInfo: {
  96. type: Object,
  97. default: () => ({}),
  98. },
  99. });
  100. const isFriendShip = ref(false);
  101. const userInfoManager = ref<IUserProfile>({});
  102. watchEffect(() => {
  103. userInfoManager.value = props.userInfo;
  104. });
  105. const emits = defineEmits([
  106. "handleSwitchConversation",
  107. "close",
  108. "openConversation",
  109. ]);
  110. watch(
  111. () => props.userInfo,
  112. async (newVal: any, oldVal: any) => {
  113. if (newVal === oldVal) return;
  114. const res = await TUIUserService.getUserProfile({
  115. userIDList: [props.userInfo.userID],
  116. });
  117. userInfoManager.value = res?.data[0];
  118. // 这里需要确认是否是好友关系
  119. checkFriend();
  120. },
  121. {
  122. deep: true,
  123. immediate: true,
  124. }
  125. );
  126. const enter = async (ID: any, type: string) => {
  127. const name = `${type}${ID}`;
  128. TUIConversationService.getConversationProfile(name)
  129. .then((res: any) => {
  130. TUIConversationService.switchConversation(
  131. res.data.conversation.conversationID
  132. ).then(() => {
  133. TUIStore.update(StoreName.GRP, "isShowManageComponent", false);
  134. if (isUniFrameWork) {
  135. TUIGlobal?.navigateBack();
  136. }
  137. });
  138. })
  139. .catch((err: any) => {
  140. console.warn("获取会话资料失败", err.code, err.msg);
  141. });
  142. };
  143. const checkFriend = async () => {
  144. if (!(userInfoManager.value as any).userID) return;
  145. TUIFriendService.checkFriend({
  146. userIDList: [userInfoManager.value.userID],
  147. type: TUIChatEngine.TYPES.SNS_CHECK_TYPE_BOTH,
  148. }).then((res: any) => {
  149. const relation = res?.data?.successUserIDList?.[0]?.relation;
  150. isFriendShip.value = relation === TUIChatEngine.TYPES.SNS_TYPE_BOTH_WAY;
  151. });
  152. };
  153. const showEnter = () => {
  154. return isFriendShip.value || !TUIStore.getData(StoreName.APP, "isOfficial");
  155. };
  156. const close = (tabName: string) => {
  157. emits("close", tabName);
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. @import "../../../assets/styles/common";
  162. .memeber-profile {
  163. flex: 1;
  164. display: flex;
  165. flex-direction: column;
  166. &-main {
  167. display: flex;
  168. flex-direction: row;
  169. width: 100%;
  170. overflow: hidden;
  171. img {
  172. width: 60px;
  173. height: 60px;
  174. border-radius: 8px;
  175. margin: 20px 10px 20px 20px;
  176. }
  177. .list {
  178. flex: 1;
  179. overflow: hidden;
  180. margin: 20px 10px;
  181. font-weight: 400;
  182. li {
  183. color: #999;
  184. }
  185. h1,
  186. li {
  187. overflow: hidden;
  188. white-space: nowrap;
  189. text-overflow: ellipsis;
  190. }
  191. }
  192. }
  193. &-footer {
  194. border-top: 10px solid #f4f5f9;
  195. padding: 14px;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: center;
  199. justify-content: center;
  200. .button {
  201. width: 100px;
  202. cursor: pointer;
  203. background-color: #006eff;
  204. color: #fff;
  205. padding: 8px 20px;
  206. border-radius: 4px;
  207. border: none;
  208. font-size: 14px;
  209. text-align: center;
  210. line-height: 20px;
  211. }
  212. }
  213. }
  214. .edit-h5 {
  215. position: fixed;
  216. width: 100%;
  217. height: 100%;
  218. top: 0;
  219. left: 0;
  220. background: rgba(0, 0, 0, 0.5);
  221. display: flex;
  222. align-items: flex-end;
  223. z-index: 1;
  224. .main {
  225. background: #fff;
  226. flex: 1;
  227. padding: 18px;
  228. border-radius: 12px 12px 0 0;
  229. width: 80vw;
  230. }
  231. &-header {
  232. display: flex;
  233. align-items: center;
  234. justify-content: space-between;
  235. .close {
  236. font-family: PingFangSC-Regular;
  237. font-weight: 400;
  238. font-size: 18px;
  239. color: #3370ff;
  240. letter-spacing: 0;
  241. line-height: 27px;
  242. }
  243. }
  244. &-footer {
  245. display: flex;
  246. .btn {
  247. flex: 1;
  248. border: none;
  249. background: #00b693;
  250. border-radius: 5px;
  251. font-family: PingFangSC-Regular;
  252. font-weight: 400;
  253. font-size: 16px;
  254. color: #fff;
  255. letter-spacing: 0;
  256. line-height: 27px;
  257. padding: 8px 0;
  258. &:disabled {
  259. opacity: 0.3;
  260. }
  261. }
  262. }
  263. }
  264. </style>