UserInfo.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div class="user-info-mask" @click="$emit('close')">
  3. <div class="user-info" :style="{ left: pos.x + 'px', top: pos.y + 'px' }" @click.stop>
  4. <div class="user-info-box">
  5. <div class="avatar">
  6. <head-image :name="user.nickName" :url="user.headImageThumb" :size="70" :online="user.online"
  7. radius="10%" @click.native="showFullImage()"> </head-image>
  8. </div>
  9. <div>
  10. <el-descriptions :column="1" :title="user.userName" class="user-info-items">
  11. <el-descriptions-item label="昵称">{{ user.nickName }}
  12. </el-descriptions-item>
  13. <el-descriptions-item label="签名">{{ user.signature }}
  14. </el-descriptions-item>
  15. </el-descriptions>
  16. </div>
  17. </div>
  18. <el-divider content-position="center"></el-divider>
  19. <div class="user-btn-group">
  20. <el-button v-show="isFriend" type="primary" @click="onSendMessage()">发消息</el-button>
  21. <el-button v-show="!isFriend" type="primary" @click="onAddFriend()">加为好友</el-button>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. import HeadImage from './HeadImage.vue'
  28. export default {
  29. name: "userInfo",
  30. components: {
  31. HeadImage
  32. },
  33. data() {
  34. return {
  35. }
  36. },
  37. props: {
  38. user: {
  39. type: Object
  40. },
  41. pos: {
  42. type: Object
  43. }
  44. },
  45. methods: {
  46. onSendMessage() {
  47. let user = this.user;
  48. let chat = {
  49. type: 'PRIVATE',
  50. targetId: user.id,
  51. showName: user.nickName,
  52. headImage: user.headImage,
  53. };
  54. this.$store.commit("openChat", chat);
  55. this.$store.commit("activeChat", 0);
  56. if (this.$route.path != "/home/chat") {
  57. this.$router.push("/home/chat");
  58. }
  59. this.$emit("close");
  60. },
  61. onAddFriend() {
  62. this.$http({
  63. url: "/friend/add",
  64. method: "post",
  65. params: {
  66. friendId: this.user.id
  67. }
  68. }).then(() => {
  69. this.$message.success("添加成功,对方已成为您的好友");
  70. let friend = {
  71. id: this.user.id,
  72. nickName: this.user.nickName,
  73. headImage: this.user.headImageThumb,
  74. online: this.user.online,
  75. deleted: false
  76. }
  77. this.$store.commit("addFriend", friend);
  78. })
  79. },
  80. showFullImage() {
  81. if (this.user.headImage) {
  82. this.$store.commit("showFullImageBox", this.user.headImage);
  83. }
  84. }
  85. },
  86. computed: {
  87. isFriend() {
  88. return this.$store.getters.isFriend(this.user.id);
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss">
  94. .user-info-mask {
  95. background-color: rgba($color: #000000, $alpha: 0);
  96. position: fixed;
  97. left: 0;
  98. top: 0;
  99. right: 0;
  100. bottom: 0;
  101. }
  102. .user-info {
  103. position: absolute;
  104. width: 300px;
  105. background-color: white;
  106. box-shadow: var(--im-box-shadow);
  107. border-radius: 4px;
  108. padding: 15px;
  109. .user-info-box {
  110. display: flex;
  111. align-items: center;
  112. .user-info-items {
  113. margin-left: 10px;
  114. white-space: nowrap;
  115. overflow: hidden;
  116. .el-descriptions__header {
  117. margin-bottom: 5px;
  118. }
  119. .el-descriptions__title {
  120. font-size: 18px;
  121. }
  122. .el-descriptions-item__cell {
  123. padding-bottom: 1px;
  124. }
  125. }
  126. }
  127. .el-divider--horizontal {
  128. margin: 18px 0;
  129. }
  130. .user-btn-group {
  131. text-align: center;
  132. }
  133. }
  134. </style>