Timeline.vue 3.2 KB

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