user-info.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="page user-info">
  3. <nav-bar back>用户信息</nav-bar>
  4. <uni-card :is-shadow="false" is-full :border="false">
  5. <view class="content">
  6. <head-image :name="userInfo.nickName" :url="userInfo.headImageThumb" :size="160"
  7. @click="onShowFullImage()"></head-image>
  8. <view class="info-item">
  9. <view class="info-primary">
  10. <text class="info-username">{{ userInfo.nickName }}</text>
  11. <text v-show="userInfo.sex == 0" class="iconfont icon-man" color="darkblue"></text>
  12. <text v-show="userInfo.sex == 1" class="iconfont icon-girl" color="darkred"></text>
  13. </view>
  14. <view class="info-text">
  15. <text class="label-text">用户名:</text>
  16. <text class="content-text"> {{ userInfo.userName }}</text>
  17. </view>
  18. <view class="info-text">
  19. <view>
  20. <text class="label-text">签名:</text>
  21. <text class="content-text"> {{ userInfo.signature }} </text>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </uni-card>
  27. <bar-group>
  28. <btn-bar v-show="isFriend" type="primary" title="发送消息" @tap="onSendMessage()">
  29. </btn-bar>
  30. <btn-bar v-show="!isFriend" type="primary" title="加为好友" @tap="onAddFriend()"></btn-bar>
  31. <btn-bar v-show="isFriend" type="danger" title="删除好友" @tap="onDelFriend()"></btn-bar>
  32. </bar-group>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. userInfo: {}
  40. }
  41. },
  42. methods: {
  43. onShowFullImage() {
  44. let imageUrl = this.userInfo.headImage;
  45. if (imageUrl) {
  46. uni.previewImage({
  47. urls: [imageUrl]
  48. })
  49. }
  50. },
  51. onSendMessage() {
  52. let chat = {
  53. type: 'PRIVATE',
  54. targetId: this.userInfo.id,
  55. showName: this.userInfo.nickName,
  56. headImage: this.userInfo.headImage,
  57. };
  58. this.chatStore.openChat(chat);
  59. let chatIdx = this.chatStore.findChatIdx(chat);
  60. uni.navigateTo({
  61. url: "/pages/chat/chat-box?chatIdx=" + chatIdx
  62. })
  63. },
  64. onAddFriend() {
  65. this.$http({
  66. url: "/friend/add?friendId=" + this.userInfo.id,
  67. method: "POST"
  68. }).then((data) => {
  69. let friend = {
  70. id: this.userInfo.id,
  71. nickName: this.userInfo.nickName,
  72. headImage: this.userInfo.headImageThumb,
  73. online: this.userInfo.online,
  74. deleted: false
  75. }
  76. this.friendStore.addFriend(friend);
  77. uni.showToast({
  78. title: '对方已成为您的好友',
  79. icon: 'none'
  80. })
  81. })
  82. },
  83. onDelFriend() {
  84. uni.showModal({
  85. title: "确认删除",
  86. content: `确认删除 '${this.userInfo.nickName}',并删除聊天记录吗?`,
  87. success: (res) => {
  88. if (res.cancel)
  89. return;
  90. this.$http({
  91. url: `/friend/delete/${this.userInfo.id}`,
  92. method: 'delete'
  93. }).then((data) => {
  94. this.friendStore.removeFriend(this.userInfo.id);
  95. this.chatStore.removePrivateChat(this.userInfo.id);
  96. uni.showToast({
  97. title: `与 '${this.userInfo.nickName}'的好友关系已解除`,
  98. icon: 'none'
  99. })
  100. })
  101. }
  102. })
  103. },
  104. updateFriendInfo() {
  105. if (this.isFriend) {
  106. // store的数据不能直接修改,深拷贝一份store的数据
  107. let friend = JSON.parse(JSON.stringify(this.friendInfo));
  108. friend.headImage = this.userInfo.headImageThumb;
  109. friend.nickName = this.userInfo.nickName;
  110. // 更新好友列表中的昵称和头像
  111. this.friendStore.updateFriend(friend);
  112. // 更新会话中的头像和昵称
  113. this.chatStore.updateChatFromFriend(this.userInfo);
  114. }
  115. },
  116. loadUserInfo(id) {
  117. this.$http({
  118. url: "/user/find/" + id,
  119. method: 'GET'
  120. }).then((user) => {
  121. this.userInfo = user;
  122. // 如果发现好友的头像和昵称改了,进行更新
  123. this.updateFriendInfo()
  124. })
  125. }
  126. },
  127. computed: {
  128. isFriend() {
  129. return this.friendStore.isFriend(this.userInfo.id);
  130. },
  131. friendInfo() {
  132. return this.friendStore.findFriend(this.userInfo.id);
  133. }
  134. },
  135. onLoad(options) {
  136. // 查询用户信息
  137. this.loadUserInfo(options.id);
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .user-info {
  143. .content {
  144. height: 200rpx;
  145. display: flex;
  146. align-items: center;
  147. justify-content: space-between;
  148. padding: 20rpx;
  149. .info-item {
  150. display: flex;
  151. align-items: flex-start;
  152. flex-direction: column;
  153. padding-left: 40rpx;
  154. flex: 1;
  155. .info-text {
  156. line-height: 1.5;
  157. //margin-bottom: 10rpx;
  158. }
  159. .label-text {
  160. font-size: $im-font-size-small;
  161. color: $im-text-color-light;
  162. }
  163. .content-text {
  164. font-size: $im-font-size-small;
  165. color: $im-text-color-light;
  166. margin-left: 10rpx;
  167. }
  168. .info-primary {
  169. display: flex;
  170. align-items: center;
  171. margin-bottom: 10rpx;
  172. .info-username {
  173. font-size: $im-font-size-large;
  174. font-weight: 600;
  175. }
  176. .icon-man {
  177. color: $im-text-color;
  178. font-size: $im-font-size-large;
  179. padding-left: 10rpx;
  180. }
  181. .icon-girl {
  182. color: darkred;
  183. }
  184. }
  185. }
  186. }
  187. }
  188. </style>