Timeline.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 userdata = Vue.$cookies.get('USERDATA')
  66. if (userdata == null) {
  67. return null
  68. }
  69. const userId = userdata.split(':')[0]
  70. getUserInfo(userId).then(resp => {
  71. if (resp.code === 0) {
  72. this.userInfo = resp.data
  73. document.title = this.userInfo.screenName + '的时间线'
  74. }
  75. })
  76. /* getMyInfo().then(resp => {
  77. if (resp.code === 0) {
  78. this.userInfo = resp.data
  79. document.title = this.userInfo.screenName + '的时间线'
  80. }
  81. })*/
  82. this.videoTimelineWrapper(this.nextId)
  83. },
  84. mounted() {
  85. // 当窗口宽度改变时获取屏幕宽度
  86. window.onresize = () => {
  87. return () => {
  88. window.screenWidth = document.body.clientWidth
  89. this.screenWidth = window.screenWidth
  90. }
  91. }
  92. },
  93. methods: {
  94. tabClick(tab) {
  95. this.nextId = 0
  96. const tabName = tab.name
  97. if (tabName === 'video') {
  98. this.videoTimelineWrapper(this.nextId)
  99. } else if (tabName === 'status') {
  100. this.statusTimelineWrapper(this.nextId)
  101. }
  102. },
  103. statusTimelineWrapper(nextId) {
  104. statusTimeline(nextId).then(resp => {
  105. if (resp.code === 0) {
  106. this.dataList = resp.data.list
  107. this.nextId = resp.data.nextId
  108. }
  109. })
  110. },
  111. videoTimelineWrapper(nextId) {
  112. videoTimeline(nextId).then(resp => {
  113. if (resp.code === 0) {
  114. this.dataList = resp.data.list
  115. this.nextId = resp.data.nextId
  116. }
  117. })
  118. }
  119. }
  120. }
  121. </script>
  122. <style scoped>
  123. /*处于手机屏幕时*/
  124. @media screen and (max-width: 768px){
  125. .movie-list {
  126. padding-top: 8px;
  127. padding-left: 0.5%;
  128. padding-right: 0.5%;
  129. }
  130. }
  131. .movie-list {
  132. padding-top: 15px;
  133. padding-left: 3%;
  134. padding-right: 3%;
  135. }
  136. </style>