UserDetailPage.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div class="user-detail-container">
  3. <div class="header">
  4. <div>
  5. <h2>{{ name }}</h2>
  6. <p>你好,野火</p>
  7. </div>
  8. <div>
  9. <img class="avatar" :src="sharedStateContact.currentFriend.portrait">
  10. </div>
  11. </div>
  12. <div class="content">
  13. <ul>
  14. <li>
  15. <label>{{ $t('common.alias') }}</label>
  16. <div class="alias">
  17. <input type="text" ref="input" :value="sharedStateContact.currentFriend.friendAlias" placeholder="备注名" @keyup.enter="updateFriendAlias"/>
  18. </div>
  19. </li>
  20. <li>
  21. <label>{{ $t('common.wfc_id') }}</label>
  22. <p class="single-line">{{ user.name }}</p>
  23. </li>
  24. <li>
  25. <label>{{ $t('common.area') }}</label>
  26. <p>{{ $t('common.unknown') }}</p>
  27. </li>
  28. <li>
  29. <label>{{ $t('common.label') }}</label>
  30. <p>{{ $t('misc.test_user') }}</p>
  31. </li>
  32. </ul>
  33. </div>
  34. <div class="footer">
  35. <a v-if="isFriend" @click="this.chat">{{ $t('message.send_message') }}</a>
  36. <a v-else-if="!isSelf" @click="addFriend">添加好友</a>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import store from "../../store";
  42. import ConversationType from "../../wfc/model/conversationType";
  43. import Conversation from "../../wfc/model/conversation";
  44. import wfc from "../../wfc/client/wfc";
  45. export default {
  46. name: "UserDetailPage",
  47. data() {
  48. return {
  49. sharedStateContact: store.state.contact,
  50. user: store.state.contact.currentFriend,
  51. }
  52. },
  53. mounted() {
  54. wfc.getUserInfo(this.user.uid, true);
  55. // uni.setNavigationBarTitle({
  56. // title:this.user._displayName,
  57. // });
  58. },
  59. onUnload() {
  60. store.setCurrentFriend(null);
  61. },
  62. methods: {
  63. chat() {
  64. let conversation = new Conversation(ConversationType.Single, this.user.uid, 0);
  65. store.setCurrentConversation(conversation);
  66. this.$go2ConversationPage();
  67. },
  68. updateFriendAlias() {
  69. let friendAlias = this.$refs.input.value;
  70. if (friendAlias.trim() && friendAlias !== this.sharedStateContact.currentFriend.friendAlias) {
  71. wfc.setFriendAlias(this.user.uid, friendAlias,
  72. () => {
  73. // do nothing
  74. console.log('setFriendAlias success', this.user, friendAlias);
  75. },
  76. (error) => {
  77. // do nothing
  78. })
  79. }
  80. },
  81. addFriend(){
  82. let userInfo = wfc.getUserInfo(wfc.getUserId());
  83. let reason = '你好,我是' + userInfo.displayName;
  84. wfc.sendFriendRequest(this.user.uid, reason, '', () => {
  85. uni.showToast({
  86. title: '好友请求发送成 ',
  87. icon: 'none'
  88. });
  89. setTimeout(() => {
  90. uni.navigateBack({
  91. delta: 1
  92. })
  93. }, 1000)
  94. }, err => {
  95. uni.showToast({
  96. title: '好友请求发送失败 ' + err,
  97. icon: 'none'
  98. });
  99. })
  100. }
  101. },
  102. computed: {
  103. name: function () {
  104. let name;
  105. let friend = this.sharedStateContact.currentFriend;
  106. if (friend.displayName) {
  107. name = friend.displayName;
  108. } else {
  109. name = friend.name;
  110. }
  111. // side
  112. (async () => {
  113. wfc.getUserInfo(friend.uid, true)
  114. })();
  115. return name;
  116. },
  117. isFriend() {
  118. return wfc.isMyFriend(this.user.uid);
  119. },
  120. isSelf(){
  121. return this.user.uid === wfc.getUserId();
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="css" scoped>
  127. .user-detail-container {
  128. margin-left: 30px;
  129. margin-right: 30px;
  130. border-top-right-radius: var(--main-border-radius);
  131. border-bottom-right-radius: var(--main-border-radius);
  132. }
  133. .header {
  134. margin-top: 30px;
  135. display: flex;
  136. justify-content: space-between;
  137. align-items: center;
  138. padding-bottom: 15px;
  139. border-bottom: 1px solid #e6e6e6;
  140. }
  141. .header .avatar {
  142. width: 80px;
  143. height: 80px;
  144. border-radius: 2px;
  145. }
  146. .header h2 {
  147. font-size: 20px;
  148. font-style: normal;
  149. font-weight: normal;
  150. margin-bottom: 5px;
  151. }
  152. .content {
  153. width: 100%;
  154. text-align: left;
  155. }
  156. .content ul {
  157. list-style: none;
  158. margin: 20px 0;
  159. }
  160. .content ul li {
  161. margin-left: 0;
  162. height: 40px;
  163. line-height: 40px;
  164. display: flex;
  165. }
  166. .content ul li label {
  167. margin-right: 20px;
  168. width: 50px;
  169. text-align: justify;
  170. text-align-last: justify;
  171. }
  172. .content ul li .alias > input {
  173. width: 100%;
  174. border: none;
  175. height: 20px;
  176. }
  177. .content ul li > div {
  178. display: inline-block;
  179. flex: 1;
  180. }
  181. .footer {
  182. display: flex;
  183. justify-content: center;
  184. }
  185. .footer a {
  186. margin-top: 30px;
  187. color: white;
  188. padding: 10px 40px;
  189. background-color: #7497f1;
  190. border-radius: 5px;
  191. border: 1px solid transparent;
  192. }
  193. .footer a:active {
  194. background-color: #4168e0;
  195. }
  196. </style>