UserAvatarCard.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  3. <el-card class="box-card">
  4. <div slot="header" class="clearfix">
  5. <el-row>
  6. <el-col :md="4">
  7. <router-link target="_blank" :to="`/user/` + userAvatar.userId">
  8. <el-avatar>
  9. <el-image :src="userAvatar.avatarUrl" />
  10. </el-avatar>
  11. </router-link>
  12. </el-col>
  13. <el-col :md="16">
  14. <el-row>
  15. <span v-html="userAvatar.screenName" />
  16. </el-row>
  17. <el-row>
  18. <span>关注 {{ userAvatar.following }}</span>
  19. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'" />
  20. <span>粉丝 {{ userAvatar.follower }}</span>
  21. </el-row>
  22. <el-row v-if="userAvatar.signature !== null">
  23. <span>{{ userAvatar.signature }}</span>
  24. </el-row>
  25. </el-col>
  26. </el-row>
  27. </div>
  28. <div class="text item">
  29. <el-row>
  30. <el-col :md="18">
  31. <el-button
  32. v-if="userAvatar.followed"
  33. type="danger"
  34. size="mini"
  35. icon="el-icon-check"
  36. @click="unfollowUser(userAvatar.userId)"
  37. >
  38. <span>已关注</span>
  39. </el-button>
  40. <el-button
  41. v-else
  42. type="danger"
  43. size="mini"
  44. icon="el-icon-plus"
  45. @click="followUser(userAvatar.userId)"
  46. >
  47. <span>关注</span>
  48. </el-button>
  49. <el-button
  50. type="danger"
  51. size="mini"
  52. icon="el-icon-message"
  53. @click="sendMessage(userAvatar.userId)"
  54. >
  55. <span>发消息</span>
  56. </el-button>
  57. </el-col>
  58. </el-row>
  59. </div>
  60. </el-card>
  61. </el-row>
  62. </template>
  63. <script>
  64. import { followUser, unfollowUser } from '@/api/user'
  65. export default {
  66. name: 'UserAvatarCard',
  67. filters: {
  68. ellipsis(value) {
  69. if (!value) return ''
  70. const max = 20
  71. if (value.length > max) {
  72. return value.slice(0, max) + '...'
  73. }
  74. return value
  75. }
  76. },
  77. props: {
  78. userAvatar: {
  79. type: Object,
  80. default: null
  81. },
  82. // 时间前的描述
  83. dateTit: {
  84. type: String,
  85. default: ''
  86. }
  87. },
  88. data() {
  89. return {
  90. followButton: {
  91. icon: 'el-icon-plus',
  92. text: '关注'
  93. }
  94. }
  95. },
  96. created() {
  97. },
  98. methods: {
  99. followUser(userId) {
  100. followUser(userId).then(resp => {
  101. if (resp.code === 0) {
  102. this.userAvatar.followed = true
  103. }
  104. })
  105. },
  106. unfollowUser(userId) {
  107. unfollowUser(userId).then(resp => {
  108. if (resp.code === 0) {
  109. this.userAvatar.followed = false
  110. }
  111. })
  112. },
  113. sendMessage(userId) {
  114. this.$message.info('暂未实现')
  115. }
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. /*处于手机屏幕时*/
  121. @media screen and (max-width: 768px) {
  122. }
  123. .clearfix:before,
  124. .clearfix:after {
  125. display: table;
  126. content: "";
  127. }
  128. .clearfix:after {
  129. clear: both;
  130. }
  131. </style>