Home.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div>
  3. <el-row class="movie-list">
  4. <el-col :md="24">
  5. <el-card :if="!user" :body-style="{ padding: '0px' }" class="card">
  6. <div slot="header" class="clearfix">
  7. <el-row>
  8. <el-col :md="1">
  9. <el-avatar>
  10. <el-image :src="user.avatarUrl" />
  11. </el-avatar>
  12. </el-col>
  13. <el-col :md="23">
  14. <span>{{ user.screenName }}</span>
  15. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'" />
  16. <el-button
  17. type="danger"
  18. size="mini"
  19. :icon="followButton.icon"
  20. @click="followUser(user.userId)"
  21. >
  22. <span>{{followButton.text}}</span>
  23. </el-button>
  24. <el-button
  25. type="danger"
  26. size="mini"
  27. icon="el-icon-message"
  28. @click="sendMessage(user.userId)"
  29. >
  30. <span>发消息</span>
  31. </el-button>
  32. </el-col>
  33. </el-row>
  34. <el-row>
  35. <span v-if="user.signature !== null">{{user.signature}}</span>
  36. <span v-if="user.signature === undefined || user.signature === null">此用户没有签名</span>
  37. </el-row>
  38. <el-row>
  39. <span class="el-icon-user">关注数: {{ user.followingCount }}</span>
  40. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'" />
  41. <span class="el-icon-user">粉丝数: {{ user.followerCount }}</span>
  42. </el-row>
  43. </div>
  44. </el-card>
  45. </el-col>
  46. </el-row>
  47. <el-row>
  48. <el-col :md="24" class="movie-list">
  49. <el-tabs v-model="activeName" @tab-click='tabClick'>
  50. <el-tab-pane name="video">
  51. <span slot="label">
  52. 视频<el-badge :value="videoCount" :max="9999" class="item" type="warning"/>
  53. </span>
  54. <div v-if="activeName === 'video'">
  55. <el-col v-for="(video, index) in videoList" :key="index" :md="6" :sm="12" :xs="12">
  56. <video-card :video="video" />
  57. </el-col>
  58. </div>
  59. </el-tab-pane>
  60. <el-tab-pane name="status">
  61. <span slot="label">
  62. 状态<el-badge :value="statusCount" :max="9999" class="item" type="warning"/>
  63. </span>
  64. <div v-if="activeName === 'status'">
  65. <el-row v-for="(status, index) in statusList" :key="index" :md="16" :sm="12" :xs="12">
  66. <status-card :status="status" />
  67. </el-row>
  68. </div>
  69. </el-tab-pane>
  70. <el-tab-pane name="following">
  71. <span slot="label">
  72. Ta 的关注<el-badge :value="followingCount" :max="9999" class="item" type="warning"/>
  73. </span>
  74. <div v-if="activeName === 'following'">
  75. <el-col v-for="(user, index) in followingList" :key="index" :md="6" :sm="12" :xs="12">
  76. <user-card :user="user"></user-card>
  77. </el-col>
  78. </div>
  79. </el-tab-pane>
  80. <el-tab-pane name="follower">
  81. <span slot="label">
  82. Ta 的粉丝<el-badge :value="followerCount" :max="9999" class="item" type="warning"/>
  83. </span>
  84. <div v-if="activeName === 'follower'">
  85. <el-col v-for="(user, index) in followerList" :key="index" :md="6" :sm="12" :xs="12">
  86. <user-card :user="user"></user-card>
  87. </el-col>
  88. </div>
  89. </el-tab-pane>
  90. </el-tabs>
  91. </el-col>
  92. <el-col :span="24" class="pagination">
  93. <el-pagination
  94. background
  95. :small="screenWidth <= 768"
  96. hide-on-single-page
  97. layout="prev, pager, next"
  98. :page-size="pageSize"
  99. :current-page="currentPage"
  100. :total="totalSize"
  101. @current-change="handleCurrentChange"
  102. @prev-click="handleCurrentChange"
  103. @next-click="handleCurrentChange"
  104. />
  105. </el-col>
  106. </el-row>
  107. <el-row v-if="showEmpty" class="not-result">
  108. <el-col :span="12" :offset="6">
  109. <img src="@/assets/img/icon/not-collection.png">
  110. <div>暂无内容</div>
  111. </el-col>
  112. </el-row>
  113. </div>
  114. </template>
  115. <script>
  116. import UserCard from '@/components/card/UserCard'
  117. import StatusCard from '@/components/card/StatusCard'
  118. import VideoCard from '@/components/card/VideoCard'
  119. import { getUserInfo, getUserFollowing, getUserFollower, checkRelation, followUser, unfollowUser } from "@/api/user";
  120. import { userVideoList, getUserContentData } from "@/api/video";
  121. import { userStatus } from "@/api/status";
  122. export default {
  123. name: 'Home',
  124. components: { UserCard, StatusCard, VideoCard },
  125. data() {
  126. return {
  127. // 屏幕宽度, 为了控制分页条的大小
  128. screenWidth: document.body.clientWidth,
  129. user: null,
  130. userId: null,
  131. followButton: {
  132. icon: 'el-icon-plus',
  133. text: '关注'
  134. },
  135. activeName: 'video',
  136. currentPage: 1,
  137. pageSize: 12,
  138. totalSize: 0,
  139. videoList: [],
  140. statusList: [],
  141. followerList: [],
  142. followingList: [],
  143. showEmpty: false,
  144. videoCount: 0,
  145. statusCount: 0,
  146. followingCount: 0,
  147. followerCount: 0
  148. }
  149. },
  150. created() {
  151. this.userId = this.$route.params.id
  152. getUserInfo(this.userId).then(res => {
  153. if (res.code === 0) {
  154. this.user = res.data
  155. document.title = this.user.screenName + '的个人主页'
  156. }
  157. })
  158. checkRelation(this.userId).then(res => {
  159. if (res.code === 0) {
  160. if (res.data) {
  161. this.followButton.text = '已关注'
  162. this.followButton.icon = 'el-icon-check'
  163. }
  164. }
  165. })
  166. getUserContentData(this.userId).then(res => {
  167. if (res.code === 0) {
  168. const resData = res.data
  169. this.videoCount = resData.videoCount
  170. this.statusCount = resData.statusCount
  171. this.followingCount = resData.userFollowCount.followingCount
  172. this.followerCount = resData.userFollowCount.followerCount
  173. }
  174. })
  175. this.userVideoListWrapper(1, this.userId, 0)
  176. },
  177. mounted() {
  178. // 当窗口宽度改变时获取屏幕宽度
  179. window.onresize = () => {
  180. return () => {
  181. window.screenWidth = document.body.clientWidth
  182. this.screenWidth = window.screenWidth
  183. }
  184. }
  185. },
  186. methods: {
  187. initPagination() {
  188. this.pageSize = 12
  189. this.currentPage = 1
  190. this.totalSize = 0
  191. },
  192. handleCurrentChange(pageNumber) {
  193. this.currentPage = pageNumber
  194. if (this.activeName === 'video') {
  195. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)
  196. } else if (this.activeName === 'status') {
  197. this.userStatusListWrapper(this.currentPage, this.userId, this.lastId)
  198. } else if (this.activeName === 'following') {
  199. getUserFollowing(this.userId).then(res => {
  200. if (res.code === 0) {
  201. this.followingList = res.data
  202. }
  203. })
  204. } else if (this.activeName === 'follower') {
  205. getUserFollower(this.userId).then(res => {
  206. if (res.code === 0) {
  207. this.followerList = res.data
  208. }
  209. })
  210. }
  211. // 回到顶部
  212. scrollTo(0, 0)
  213. },
  214. tabClick(tab) {
  215. this.activeName = tab.name
  216. if (this.activeName === 'video') {
  217. this.currentPage = 1
  218. this.lastId = 0
  219. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)
  220. } else if (this.activeName === 'status') {
  221. this.currentPage = 1
  222. this.lastId = 0
  223. this.userStatusListWrapper(this.currentPage, this.userId, this.lastId)
  224. } else if (this.activeName === 'following') {
  225. getUserFollowing(this.userId).then(res => {
  226. if (res.code === 0) {
  227. this.followingList = res.data
  228. }
  229. })
  230. } else if (this.activeName === 'follower') {
  231. getUserFollower(this.userId).then(res => {
  232. if (res.code === 0) {
  233. this.followerList = res.data
  234. }
  235. })
  236. }
  237. },
  238. followUser(userId) {
  239. if (this.followButton.text === '关注') {
  240. followUser(userId).then(res => {
  241. if (res.code === 0) {
  242. this.followButton.text = '已关注'
  243. this.followButton.icon = 'el-icon-check'
  244. }
  245. })
  246. } else {
  247. unfollowUser(userId).then(res => {
  248. if (res.code === 0) {
  249. this.followButton.text = '关注'
  250. this.followButton.icon = 'el-icon-plus'
  251. }
  252. })
  253. }
  254. },
  255. sendMessage(userId) {
  256. console.log('发送消息')
  257. },
  258. userVideoListWrapper(pageNumber, userId, lastId) {
  259. userVideoList(pageNumber, userId, lastId).then(res => {
  260. if (res.code === 0) {
  261. const resData = res.data
  262. this.videoList = resData.list
  263. this.totalSize = resData.totalSize
  264. this.lastId = resData.lastId
  265. if (this.videoList.length !== 0) {
  266. this.showEmpty = false
  267. } else {
  268. this.showEmpty = true
  269. }
  270. }
  271. })
  272. },
  273. userStatusListWrapper(pageNumber, userId, lastId) {
  274. userStatus(userId, pageNumber).then(res => {
  275. if (res.code === 0) {
  276. this.statusList = res.data.list
  277. if (this.statusList.length === 0) {
  278. this.showEmpty = true
  279. } else {
  280. this.showEmpty = false
  281. }
  282. }
  283. })
  284. }
  285. }
  286. }
  287. </script>
  288. <style scoped>
  289. .movie-list {
  290. padding-top: 15px;
  291. padding-left: 6%;
  292. padding-right: 6%;
  293. }
  294. .pagination {
  295. text-align: center;
  296. padding: 10px;
  297. }
  298. /*处于手机屏幕时*/
  299. @media screen and (max-width: 768px){
  300. .movie-list {
  301. padding-top: 8px;
  302. padding-left: 0.5%;
  303. padding-right: 0.5%;
  304. }
  305. }
  306. .not-result {
  307. padding-top: 100px;
  308. padding-bottom: 100px;
  309. text-align: center;
  310. }
  311. .item {
  312. margin-top: 10px;
  313. margin-right: 40px;
  314. }
  315. </style>