user-home.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div>
  3. <v-card>
  4. <!--<v-container fill-height fluid style="padding: 0px;">
  5. <v-row>
  6. <v-col style="padding: 0px;">
  7. <v-img :src="userInfo.backgroundUrl" :aspect-ratio="5.98" />
  8. </v-col>
  9. </v-row>
  10. </v-container>-->
  11. <v-container fill-height>
  12. <v-row align="center">
  13. <v-col
  14. cols="12"
  15. md="8"
  16. >
  17. <v-avatar size="80" style="float: left;">
  18. <v-img :src="userInfo.avatarUrl" />
  19. </v-avatar>
  20. <h2 style="margin-top: 20px;margin-left: 100px;">
  21. <!--{{ userInfo.username }}-->
  22. {{ userInfo.screenName }}
  23. <!--<v-chip color="yellow" @click="goToVip()">
  24. <v-chip v-if="Power.checkPower(userInfo) === 'vip'" color="yellow" @click="goTOVIP()">
  25. 小会员
  26. </v-chip>-->
  27. </h2>
  28. </v-col>
  29. <v-col
  30. v-if="userInfo && userInfo.userId !== loginUserId"
  31. cols="6"
  32. md="4"
  33. class="hidden-sm-and-down ml-0 pl-4"
  34. >
  35. <!--<v-btn color="primary" @click="goToSetting">自定义频道</v-btn> <v-btn color="primary" @click="goToStudio">创作中心</v-btn>-->
  36. <v-btn color="primary" @click="followUserWrapper">
  37. <span v-if="isFollowed">已关注</span>
  38. <span v-if="!isFollowed">关注TA</span>
  39. </v-btn>
  40. </v-col>
  41. </v-row>
  42. <v-row>
  43. <v-col>
  44. {{ userInfo.intro }}
  45. </v-col>
  46. </v-row>
  47. <v-row>
  48. <v-col
  49. v-if="userInfo || userInfo.userId !== userId"
  50. cols="6"
  51. md="4"
  52. >
  53. 关注数: {{ userInfo.followingCount }}
  54. 粉丝数: {{ userInfo.followerCount }}
  55. </v-col>
  56. </v-row>
  57. <v-tabs>
  58. <v-tab @click="selectTab(1)">主页</v-tab>
  59. <v-tab @click="selectTab(2)">状态</v-tab>
  60. <v-tab @click="selectTab(3)">投稿</v-tab>
  61. </v-tabs>
  62. </v-container>
  63. </v-card>
  64. <v-divider />
  65. <v-divider />
  66. <v-divider />
  67. <v-divider />
  68. <v-divider />
  69. <v-divider />
  70. <div v-if="type === 1">
  71. <v-card
  72. light
  73. >
  74. <v-card-title class="text-h5">
  75. 最近投稿
  76. </v-card-title>
  77. <v-row>
  78. <v-col
  79. v-for="item in cardList"
  80. :key="item.videoId"
  81. >
  82. <video-card :video="item" />
  83. </v-col>
  84. </v-row>
  85. </v-card>
  86. </div>
  87. <v-dialog
  88. v-model="showDialog"
  89. persistent
  90. max-width="600px"
  91. >
  92. <v-card>
  93. <v-card-title>
  94. <span class="text-h5">已关注, 确定要取消关注?</span>
  95. </v-card-title>
  96. <v-card-actions>
  97. <v-spacer />
  98. <v-btn
  99. color="blue darken-1"
  100. text
  101. @click="showDialog = false"
  102. >
  103. 取消
  104. </v-btn>
  105. <v-btn
  106. color="blue darken-1"
  107. text
  108. @click="unfollowUserWrapper"
  109. >
  110. 确定
  111. </v-btn>
  112. </v-card-actions>
  113. </v-card>
  114. </v-dialog>
  115. <v-snackbar
  116. v-model="showMessage"
  117. :top="true"
  118. :timeout="1000"
  119. >
  120. {{ message }}
  121. <template v-slot:action="{ attrs }">
  122. <v-btn
  123. color="pink"
  124. text
  125. v-bind="attrs"
  126. @click="showMessage = false"
  127. >
  128. 关闭
  129. </v-btn>
  130. </template>
  131. </v-snackbar>
  132. </div>
  133. </template>
  134. <script>
  135. import Power from '@/utils/check-power.vue'
  136. import TimeUtil from '@/utils/time-util.vue'
  137. import { getUserInfo, followUser, unfollowUser, checkRelation } from '@/api/user/user'
  138. import { userRecentlyVideoList } from '@/api/media/video'
  139. import VideoCard from '@/components/card/video-card.vue'
  140. export default {
  141. name: 'UserHome',
  142. components: {
  143. VideoCard
  144. },
  145. data() {
  146. return {
  147. TimeUtil,
  148. Power,
  149. loginUserId: 0,
  150. userId: 0,
  151. userInfo: {},
  152. cardList: [],
  153. page: 1,
  154. type: 1,
  155. isFollowed: false,
  156. showDialog: false,
  157. showMessage: false,
  158. message: ''
  159. }
  160. },
  161. created() {
  162. const userIdStr = this.$route.params.userId
  163. if (userIdStr === undefined) {
  164. // 从"个人中心"加载
  165. this.loginUserId = this.$store.state.user.userInfo.userId
  166. this.userId = this.$store.state.user.userInfo.userId
  167. this.userInfo = this.$store.state.user.userInfo
  168. document.title = '我的主页'
  169. } else {
  170. this.userId = parseInt(userIdStr)
  171. this.getUserInfo1(this.userId)
  172. }
  173. this.checkRelationWrapper()
  174. this.getVideoList(this.page)
  175. },
  176. methods: {
  177. selectTab(type) {
  178. if (type === this.type) {
  179. return
  180. }
  181. this.type = type
  182. if (type === 1) {
  183. this.getVideoList(1)
  184. } else if (type === 2) {
  185. this.$router.push('/u/' + this.userId + '/status')
  186. } else if (type === 3) {
  187. this.$router.push('/u/' + this.userId + '/video')
  188. }
  189. },
  190. getUserInfo1(userId) {
  191. getUserInfo(userId).then(res => {
  192. if (res.code === 0) {
  193. this.userInfo = res.data
  194. document.title = this.userInfo.screenName + ' 的主页'
  195. } else {
  196. this.message = res.msg
  197. this.showMessage = true
  198. }
  199. }).catch(error => {
  200. console.error(error.message)
  201. })
  202. },
  203. getVideoList() {
  204. userRecentlyVideoList(this.userId).then(res => {
  205. if (res.code === 0) {
  206. this.$vuetify.goTo(0)
  207. const list = res.data
  208. this.cardList.splice(0, this.cardList.length)
  209. for (const item of list) {
  210. this.cardList.push(item)
  211. }
  212. } else {
  213. this.message = res.msg
  214. this.showMessage = true
  215. }
  216. }).catch(error => {
  217. console.error(error.message)
  218. })
  219. },
  220. goToVip() {
  221. this.$router.push('/vip')
  222. },
  223. goToStudio() {
  224. this.$router.push('/studio')
  225. },
  226. goToSetting() {
  227. this.$router.push('/user/account')
  228. },
  229. checkRelationWrapper() {
  230. checkRelation(this.userId).then(res => {
  231. if (res.code === 0) {
  232. this.isFollowed = res.data
  233. } else {
  234. this.message = res.msg
  235. this.showMessage = true
  236. }
  237. })
  238. },
  239. followUserWrapper() {
  240. if (this.isFollowed) {
  241. this.showDialog = true
  242. return
  243. }
  244. followUser(this.userId).then(res => {
  245. if (res.code === 0) {
  246. this.isFollowed = true
  247. this.message = '已关注'
  248. this.showMessage = true
  249. }
  250. })
  251. },
  252. unfollowUserWrapper() {
  253. if (!this.isFollowed) {
  254. return
  255. }
  256. this.showDialog = false
  257. unfollowUser(this.userId).then(res => {
  258. if (res.code === 0) {
  259. this.isFollowed = false
  260. this.message = '已取消关注'
  261. this.showMessage = true
  262. }
  263. })
  264. }
  265. }
  266. }
  267. </script>
  268. <style>
  269. </style>