Timeline.vue 3.7 KB

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