Home.vue 12 KB

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