Timeline.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <el-row v-if="userInfo !== null" style="height: 80vh;">
  3. <el-scrollbar style="width: 100%; height: 100%;">
  4. <el-row class="movie-list">
  5. <el-col :md="8">
  6. <user-avatar-card :user-avatar="userInfo" />
  7. </el-col>
  8. <el-col :md="8">
  9. <el-row>
  10. <text-card />
  11. </el-row>
  12. <el-row>
  13. <el-tabs v-model="activeName" @tab-click="tabClick">
  14. <el-tab-pane label="视频" name="video">
  15. <div v-if="activeName === 'video'">
  16. <el-col>
  17. <el-row v-for="(video, index) in dataList" :key="index">
  18. <side-video-card :video="video" />
  19. </el-row>
  20. </el-col>
  21. </div>
  22. </el-tab-pane>
  23. <el-tab-pane label="状态" name="status">
  24. <div v-if="activeName === 'status'">
  25. <el-col :md="15">
  26. <el-row v-for="(status, index) in dataList" :key="index" :md="15" :sm="12" :xs="12">
  27. <status-card :status="status" />
  28. </el-row>
  29. </el-col>
  30. </div>
  31. </el-tab-pane>
  32. </el-tabs>
  33. </el-row>
  34. </el-col>
  35. <el-col :md="8">
  36. <user-avatar-card :user-avatar="userInfo" />
  37. </el-col>
  38. </el-row>
  39. </el-scrollbar>
  40. </el-row>
  41. </template>
  42. <script>
  43. import TextCard from '@/components/card/TextCard'
  44. import StatusCard from '@/components/card/StatusCard'
  45. import SideVideoCard from '@/components/card/SideVideoCard'
  46. import UserAvatarCard from '@/components/card/UserAvatarCard'
  47. import { statusTimeline, videoTimeline } from '@/api/timeline'
  48. import { getUserInfo } from '@/api/user'
  49. import Vue from 'vue'
  50. export default {
  51. name: 'Timeline',
  52. components: { TextCard, StatusCard, SideVideoCard, UserAvatarCard },
  53. data() {
  54. return {
  55. // 屏幕宽度, 为了控制分页条的大小
  56. screenWidth: document.body.clientWidth,
  57. nextId: 0,
  58. userInfo: null,
  59. videoInfo: null,
  60. dataList: [],
  61. activeName: 'video'
  62. }
  63. },
  64. created() {
  65. const userInfo = getUserInfo()
  66. if (userInfo === null) {
  67. return null
  68. }
  69. this.userInfo = userInfo
  70. document.title = userInfo.screenName + '的时间线'
  71. this.videoTimelineWrapper(this.nextId)
  72. },
  73. mounted() {
  74. // 当窗口宽度改变时获取屏幕宽度
  75. window.onresize = () => {
  76. return () => {
  77. window.screenWidth = document.body.clientWidth
  78. this.screenWidth = window.screenWidth
  79. }
  80. }
  81. },
  82. methods: {
  83. tabClick(tab) {
  84. this.nextId = 0
  85. const tabName = tab.name
  86. if (tabName === 'video') {
  87. this.videoTimelineWrapper(this.nextId)
  88. } else if (tabName === 'status') {
  89. this.statusTimelineWrapper(this.nextId)
  90. }
  91. },
  92. statusTimelineWrapper(nextId) {
  93. statusTimeline(nextId).then(resp => {
  94. if (resp.code === 0) {
  95. this.dataList = resp.data.list
  96. this.nextId = resp.data.nextId
  97. }
  98. })
  99. },
  100. videoTimelineWrapper(nextId) {
  101. videoTimeline(nextId).then(resp => {
  102. if (resp.code === 0) {
  103. this.dataList = resp.data.list
  104. this.nextId = resp.data.nextId
  105. }
  106. })
  107. }
  108. }
  109. }
  110. </script>
  111. <style scoped>
  112. /*处于手机屏幕时*/
  113. @media screen and (max-width: 768px){
  114. .movie-list {
  115. padding-top: 8px;
  116. padding-left: 0.5%;
  117. padding-right: 0.5%;
  118. }
  119. }
  120. .movie-list {
  121. padding-top: 15px;
  122. padding-left: 3%;
  123. padding-right: 3%;
  124. }
  125. </style>