Timeline.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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-row
  17. v-if="dataList.length !== 0"
  18. v-infinite-scroll="load"
  19. infinite-scroll-disabled="loading"
  20. infinite-scroll-distance="10"
  21. >
  22. <el-col>
  23. <el-row v-for="(video, index) in dataList" :key="index">
  24. <side-video-card :video="video" />
  25. </el-row>
  26. </el-col>
  27. </el-row>
  28. </div>
  29. </el-tab-pane>
  30. <el-tab-pane label="状态" name="status">
  31. <div v-if="activeName === 'status'">
  32. <el-col :md="15">
  33. <el-row v-for="(status, index) in dataList" :key="index" :md="15" :sm="12" :xs="12">
  34. <status-card :status="status" />
  35. </el-row>
  36. </el-col>
  37. </div>
  38. </el-tab-pane>
  39. </el-tabs>
  40. </el-row>
  41. </el-col>
  42. <el-col :md="8">
  43. <user-avatar-card :user-avatar="userInfo" />
  44. </el-col>
  45. </el-row>
  46. </el-scrollbar>
  47. </el-row>
  48. </template>
  49. <script>
  50. import TextCard from '@/components/card/TextCard'
  51. import StatusCard from '@/components/card/StatusCard'
  52. import SideVideoCard from '@/components/card/SideVideoCard'
  53. import UserAvatarCard from '@/components/card/UserAvatarCard'
  54. import { videoTimeline } from '@/api/timeline'
  55. import { getAuthedUser } from '@/utils/auth'
  56. export default {
  57. name: 'Timeline',
  58. components: { TextCard, StatusCard, SideVideoCard, UserAvatarCard },
  59. data() {
  60. return {
  61. // 屏幕宽度, 为了控制分页条的大小
  62. screenWidth: document.body.clientWidth,
  63. nextId: 0,
  64. userInfo: null,
  65. videoInfo: null,
  66. dataList: [],
  67. activeName: 'video',
  68. loading: false
  69. }
  70. },
  71. created() {
  72. const loginUser = getAuthedUser()
  73. if (loginUser === null) {
  74. return null
  75. }
  76. this.userInfo = loginUser
  77. document.title = loginUser.screenName + '的时间线'
  78. this.videoTimelineWrapper(this.nextId)
  79. },
  80. mounted() {
  81. // 当窗口宽度改变时获取屏幕宽度
  82. window.onresize = () => {
  83. return () => {
  84. window.screenWidth = document.body.clientWidth
  85. this.screenWidth = window.screenWidth
  86. }
  87. }
  88. },
  89. methods: {
  90. load() {
  91. this.loading = true
  92. setTimeout(() => {
  93. this.videoTimelineWrapper(this.nextId)
  94. }, 1000)
  95. },
  96. tabClick(tab) {
  97. this.nextId = 0
  98. const tabName = tab.name
  99. if (tabName === 'video') {
  100. this.videoTimelineWrapper(this.nextId)
  101. } else if (tabName === 'status') {
  102. this.statusTimelineWrapper(this.nextId)
  103. }
  104. },
  105. statusTimelineWrapper(nextId) {
  106. this.$notify.info({
  107. message: '状态 timeline 未实现',
  108. duration: 3000
  109. })
  110. },
  111. videoTimelineWrapper(nextId) {
  112. videoTimeline(nextId).then(resp => {
  113. if (resp.code === 0) {
  114. for (const item of resp.data.list) {
  115. this.dataList.push(item)
  116. }
  117. this.nextId = resp.data.nextId
  118. this.loading = false
  119. }
  120. })
  121. }
  122. }
  123. }
  124. </script>
  125. <style scoped>
  126. /*处于手机屏幕时*/
  127. @media screen and (max-width: 768px){
  128. .movie-list {
  129. padding-top: 8px;
  130. padding-left: 0.5%;
  131. padding-right: 0.5%;
  132. }
  133. }
  134. .movie-list {
  135. padding-top: 15px;
  136. padding-left: 3%;
  137. padding-right: 3%;
  138. }
  139. </style>