Home.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div>
  3. <el-row class="movie-list">
  4. <el-col v-if="user" :md="24">
  5. <el-card :body-style="{ padding: '0px' }" class="card">
  6. <div slot="header" class="clearfix">
  7. <el-row>
  8. <el-col :md="1">
  9. <el-avatar>
  10. <el-image :src="user.avatarUrl" />
  11. </el-avatar>
  12. </el-col>
  13. <el-col :md="22">
  14. <span>{{ user.screenName }}</span>
  15. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'" />
  16. <el-button
  17. type="danger"
  18. size="mini"
  19. :icon="followButton.icon"
  20. @click="followUser(user.userId)"
  21. >
  22. <span>{{ followButton.text }}</span>
  23. </el-button>
  24. <el-button
  25. type="danger"
  26. size="mini"
  27. icon="el-icon-message"
  28. @click="sendMessage(user.userId)"
  29. >
  30. <span>发消息</span>
  31. </el-button>
  32. <el-tag v-if="user.biliUserId !== undefined && user.biliUserId !== null" size="mini" type="'success'" disable-transitions>
  33. <a target="_blank" :href="`https://space.bilibili.com/` + user.biliUserId">bili</a>
  34. </el-tag>
  35. </el-col>
  36. <el-col :md="1">
  37. <StampBadge
  38. v-if="user.vip"
  39. style="position: relative; top: 0; right: 0"
  40. size="small"
  41. color="warning"
  42. content="小会员"
  43. :rotate="0"
  44. />
  45. </el-col>
  46. </el-row>
  47. <el-row>
  48. <span v-if="user.signature !== null" v-html="user.signature" />
  49. <span v-if="user.signature === undefined || user.signature === null">-</span>
  50. </el-row>
  51. <el-row>
  52. <br>
  53. <router-link target="_blank" :to="`/user/${user.userId}/following`">
  54. <span class="el-icon-user">关注数: {{ user.following }}</span>
  55. </router-link>
  56. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'" />
  57. <router-link target="_blank" :to="`/user/${user.userId}/follower`">
  58. <span class="el-icon-user">粉丝数: {{ user.follower }}</span>
  59. </router-link>
  60. </el-row>
  61. </div>
  62. </el-card>
  63. </el-col>
  64. </el-row>
  65. <el-row>
  66. <el-col :md="24" class="movie-list">
  67. <el-tabs v-if="userContentData !== null" v-model="activeName" @tab-click="tabClick">
  68. <el-tab-pane name="video">
  69. <span slot="label">
  70. 视频<el-badge :value="userContentData.videoCount" :max="9999" class="item" type="warning" />
  71. </span>
  72. <div v-if="activeName === 'video'">
  73. <el-col v-for="(video, index) in dataList" :key="index" :md="6" :sm="12" :xs="12">
  74. <video-card :video="video" />
  75. </el-col>
  76. </div>
  77. </el-tab-pane>
  78. <el-tab-pane name="image">
  79. <span slot="label">
  80. 相册<el-badge :value="userContentData.albumCount" :max="9999" class="item" type="warning" />
  81. </span>
  82. <div v-if="activeName === 'image'">
  83. <el-col v-for="(album, index) in dataList" :key="index" :md="6" :sm="12" :xs="12">
  84. <image-album-card :image-album="album" />
  85. </el-col>
  86. </div>
  87. </el-tab-pane>
  88. <!-- <el-tab-pane name="audio">
  89. <span slot="label">
  90. 音频<el-badge :value="userContentData.audioCount" :max="9999" class="item" type="warning" />
  91. </span>
  92. <div v-if="activeName === 'audio'">
  93. <el-col v-for="(audio, index) in dataList" :key="index" :md="6" :sm="12" :xs="12">
  94. <audio-card :audio="audio" />
  95. </el-col>
  96. </div>
  97. </el-tab-pane>
  98. <el-tab-pane name="article">
  99. <span slot="label">
  100. 文章<el-badge :value="userContentData.articleCount" :max="9999" class="item" type="warning" />
  101. </span>
  102. <div v-if="activeName === 'article'">
  103. <el-col v-for="(article, index) in dataList" :key="index" :md="6" :sm="12" :xs="12">
  104. <article-card :article="article" />
  105. </el-col>
  106. </div>
  107. </el-tab-pane>-->
  108. <!-- <el-tab-pane name="status">
  109. <span slot="label">
  110. 状态<el-badge :value="userContentData.statusCount" :max="9999" class="item" type="warning"/>
  111. </span>
  112. <div v-if="activeName === 'status'">
  113. <el-col v-for="(status, index) in dataList" :key="index" :md="16" :sm="12" :xs="12">
  114. <span>发布的状态</span>
  115. </el-col>
  116. </div>
  117. </el-tab-pane>-->
  118. </el-tabs>
  119. </el-col>
  120. <el-col :span="24" class="pagination">
  121. <el-pagination
  122. background
  123. :small="screenWidth <= 768"
  124. hide-on-single-page
  125. layout="prev, pager, next"
  126. :page-size="pageSize"
  127. :current-page="currentPage"
  128. :total="totalSize"
  129. @current-change="handleCurrentChange"
  130. @prev-click="handleCurrentChange"
  131. @next-click="handleCurrentChange"
  132. />
  133. </el-col>
  134. </el-row>
  135. <el-row v-if="showEmpty" class="not-result">
  136. <el-col :span="12" :offset="6">
  137. <img src="@/assets/img/icon/not-collection.png">
  138. <div>该用户还没发布任何东西呢</div>
  139. </el-col>
  140. </el-row>
  141. </div>
  142. </template>
  143. <script>
  144. import StampBadge from '@/components/StampBadge'
  145. import VideoCard from '@/components/card/VideoCard'
  146. import AudioCard from '@/components/card/AudioCard'
  147. import ImageAlbumCard from '@/components/card/ImageAlbumCard'
  148. import ArticleCard from '@/components/card/ArticleCard'
  149. import { getUserInfo, checkRelation, followUser, unfollowUser } from '@/api/user'
  150. import { getUserContentData, getUserVideos } from '@/api/video'
  151. import { getUserAlbums1 } from '@/api/image'
  152. import { getUserAudios } from '@/api/audio'
  153. import { getUserArticles } from '@/api/article'
  154. export default {
  155. name: 'Home',
  156. components: { StampBadge, VideoCard, ImageAlbumCard, AudioCard, ArticleCard },
  157. data() {
  158. return {
  159. // 屏幕宽度, 为了控制分页条的大小
  160. screenWidth: document.body.clientWidth,
  161. user: null,
  162. userId: null,
  163. followButton: {
  164. icon: 'el-icon-plus',
  165. text: '关注'
  166. },
  167. activeName: 'video',
  168. currentPage: 1,
  169. pageSize: 12,
  170. totalSize: 0,
  171. dataList: [],
  172. showEmpty: true,
  173. userContentData: null
  174. }
  175. },
  176. watch: {
  177. $route() {
  178. this.$router.go()
  179. }
  180. },
  181. created() {
  182. this.userId = this.$route.params.id
  183. getUserInfo(this.userId).then(resp => {
  184. if (resp.code === 0) {
  185. this.user = resp.data
  186. const path = this.$route.path
  187. if (path.endsWith('video')) {
  188. this.activeName = 'video'
  189. document.title = this.user.screenName + '的视频'
  190. } else if (path.endsWith('image')) {
  191. this.activeName = 'image'
  192. document.title = this.user.screenName + '的相册'
  193. } else if (path.endsWith('audio')) {
  194. this.activeName = 'audio'
  195. document.title = this.user.screenName + '的音频'
  196. } else if (path.endsWith('article')) {
  197. this.activeName = 'article'
  198. document.title = this.user.screenName + '的文章'
  199. } else if (path.endsWith('status')) {
  200. this.activeName = 'status'
  201. document.title = this.user.screenName + '的状态'
  202. } else {
  203. document.title = this.user.screenName + '的个人主页'
  204. }
  205. this.getData()
  206. }
  207. })
  208. checkRelation(this.userId).then(resp => {
  209. if (resp.code === 0) {
  210. if (resp.data) {
  211. this.followButton.text = '已关注'
  212. this.followButton.icon = 'el-icon-check'
  213. }
  214. }
  215. })
  216. getUserContentData(this.userId).then(resp => {
  217. if (resp.code === 0) {
  218. this.userContentData = resp.data
  219. }
  220. })
  221. },
  222. mounted() {
  223. // 当窗口宽度改变时获取屏幕宽度
  224. window.onresize = () => {
  225. return () => {
  226. window.screenWidth = document.body.clientWidth
  227. this.screenWidth = window.screenWidth
  228. }
  229. }
  230. },
  231. methods: {
  232. followUser(userId) {
  233. if (this.followButton.text === '关注') {
  234. followUser(userId).then(resp => {
  235. if (resp.code === 0) {
  236. this.followButton.text = '已关注'
  237. this.followButton.icon = 'el-icon-check'
  238. }
  239. })
  240. } else {
  241. unfollowUser(userId).then(resp => {
  242. if (resp.code === 0) {
  243. this.followButton.text = '关注'
  244. this.followButton.icon = 'el-icon-plus'
  245. }
  246. })
  247. }
  248. },
  249. sendMessage(userId) {
  250. console.log('发送消息')
  251. },
  252. handleCurrentChange(pageNumber) {
  253. this.currentPage = pageNumber
  254. this.getData()
  255. // 回到顶部
  256. scrollTo(0, 0)
  257. },
  258. tabClick(tab) {
  259. this.activeName = tab.name
  260. this.goToTab(this.activeName)
  261. },
  262. goToTab(activeName) {
  263. const path = '/user/' + this.userId + '/' + activeName
  264. if (this.$route.path === path) {
  265. this.$router.go(0)
  266. return
  267. }
  268. this.$router.push(path)
  269. },
  270. getData() {
  271. this.dataList = []
  272. if (this.activeName === 'video') {
  273. this.userVideoListWrapper(this.currentPage, this.userId)
  274. } else if (this.activeName === 'image') {
  275. this.userAlbumWrapper(this.currentPage, this.userId)
  276. } else if (this.activeName === 'audio') {
  277. getUserAudios(this.userId, this.currentPage).then(resp => {
  278. if (resp.code === 0) {
  279. const respData = resp.data.list
  280. if (respData.length !== 0) {
  281. this.showEmpty = false
  282. for (const item of respData) {
  283. this.dataList.push(item)
  284. }
  285. } else {
  286. this.showEmpty = true
  287. }
  288. }
  289. })
  290. } else if (this.activeName === 'article') {
  291. getUserArticles(this.userId, this.currentPage).then(resp => {
  292. if (resp.code === 0) {
  293. const respData = resp.data.list
  294. if (respData.length !== 0) {
  295. this.showEmpty = false
  296. for (const item of respData) {
  297. this.dataList.push(item)
  298. }
  299. } else {
  300. this.showEmpty = true
  301. }
  302. }
  303. })
  304. } else if (this.activeName === 'status') {
  305. this.userStatusListWrapper(this.currentPage, this.userId)
  306. }
  307. },
  308. userVideoListWrapper(pageNumber, userId) {
  309. getUserVideos(userId, pageNumber).then(resp => {
  310. if (resp.code === 0) {
  311. const respData = resp.data
  312. this.dataList = respData.list
  313. this.totalSize = respData.totalSize
  314. if (this.dataList.length !== 0) {
  315. this.showEmpty = false
  316. } else {
  317. this.showEmpty = true
  318. }
  319. }
  320. })
  321. },
  322. userAlbumWrapper(pageNumber, userId) {
  323. getUserAlbums1(pageNumber, userId).then(resp => {
  324. if (resp.code === 0) {
  325. const respData = resp.data
  326. this.dataList = respData.list
  327. this.totalSize = respData.totalSize
  328. if (this.dataList.length !== 0) {
  329. this.showEmpty = false
  330. } else {
  331. this.showEmpty = true
  332. }
  333. }
  334. })
  335. },
  336. userStatusListWrapper(pageNumber, userId) {
  337. userStatus(userId, pageNumber).then(resp => {
  338. if (resp.code === 0) {
  339. this.dataList = resp.data.list
  340. this.showEmpty = this.dataList.length === 0
  341. }
  342. })
  343. }
  344. }
  345. }
  346. </script>
  347. <style scoped>
  348. .movie-list {
  349. padding-top: 15px;
  350. padding-left: 6%;
  351. padding-right: 6%;
  352. }
  353. .pagination {
  354. text-align: center;
  355. padding: 10px;
  356. }
  357. /*处于手机屏幕时*/
  358. @media screen and (max-width: 768px){
  359. .movie-list {
  360. padding-top: 8px;
  361. padding-left: 0.5%;
  362. padding-right: 0.5%;
  363. }
  364. }
  365. .not-result {
  366. padding-top: 100px;
  367. padding-bottom: 100px;
  368. text-align: center;
  369. }
  370. .item {
  371. margin-top: 10px;
  372. margin-right: 40px;
  373. }
  374. </style>