Home.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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="status">
  51. <span slot="label">
  52. 状态<el-badge :value="statusCount" :max="9999" class="item" type="warning"/>
  53. </span>
  54. <div v-if="activeName === 'status'">
  55. <el-row v-for="(status, index) in statusList" :key="index" :md="16" :sm="12" :xs="12">
  56. <status-card :status="status" />
  57. </el-row>
  58. </div>
  59. </el-tab-pane>
  60. <el-tab-pane name="video">
  61. <span slot="label">
  62. 视频<el-badge :value="videoCount" :max="9999" class="item" type="warning"/>
  63. </span>
  64. <div v-if="activeName === 'video'">
  65. <el-col v-for="(video, index) in videoList" :key="index" :md="6" :sm="12" :xs="12">
  66. <video-card :video="video" />
  67. </el-col>
  68. </div>
  69. </el-tab-pane>
  70. <el-tab-pane name="image">
  71. <span slot="label">
  72. 相册<el-badge :value="videoCount" :max="9999" class="item" type="warning"/>
  73. </span>
  74. <div v-if="activeName === 'image'">
  75. <el-col v-for="(video, index) in videoList" :key="index" :md="6" :sm="12" :xs="12">
  76. <video-card :video="video" />
  77. </el-col>
  78. </div>
  79. </el-tab-pane>
  80. <el-tab-pane name="audio">
  81. <span slot="label">
  82. 音频<el-badge :value="videoCount" :max="9999" class="item" type="warning"/>
  83. </span>
  84. <div v-if="activeName === 'audio'">
  85. <el-col v-for="(video, index) in videoList" :key="index" :md="6" :sm="12" :xs="12">
  86. <video-card :video="video" />
  87. </el-col>
  88. </div>
  89. </el-tab-pane>
  90. <el-tab-pane name="article">
  91. <span slot="label">
  92. 文章<el-badge :value="videoCount" :max="9999" class="item" type="warning"/>
  93. </span>
  94. <div v-if="activeName === 'article'">
  95. <el-col v-for="(video, index) in videoList" :key="index" :md="6" :sm="12" :xs="12">
  96. <video-card :video="video" />
  97. </el-col>
  98. </div>
  99. </el-tab-pane>
  100. <el-tab-pane name="following">
  101. <span slot="label">
  102. Ta 的关注<el-badge :value="followingCount" :max="9999" class="item" type="warning"/>
  103. </span>
  104. <div v-if="activeName === 'following'">
  105. <el-col v-for="(user, index) in followingList" :key="index" :md="6" :sm="12" :xs="12">
  106. <user-card :user="user"></user-card>
  107. </el-col>
  108. </div>
  109. </el-tab-pane>
  110. <el-tab-pane name="follower">
  111. <span slot="label">
  112. Ta 的粉丝<el-badge :value="followerCount" :max="9999" class="item" type="warning"/>
  113. </span>
  114. <div v-if="activeName === 'follower'">
  115. <el-col v-for="(user, index) in followerList" :key="index" :md="6" :sm="12" :xs="12">
  116. <user-card :user="user"></user-card>
  117. </el-col>
  118. </div>
  119. </el-tab-pane>
  120. </el-tabs>
  121. </el-col>
  122. <el-col :span="24" class="pagination">
  123. <el-pagination
  124. background
  125. :small="screenWidth <= 768"
  126. hide-on-single-page
  127. layout="prev, pager, next"
  128. :page-size="pageSize"
  129. :current-page="currentPage"
  130. :total="totalSize"
  131. @current-change="handleCurrentChange"
  132. @prev-click="handleCurrentChange"
  133. @next-click="handleCurrentChange"
  134. />
  135. </el-col>
  136. </el-row>
  137. <el-row v-if="showEmpty" class="not-result">
  138. <el-col :span="12" :offset="6">
  139. <img src="@/assets/img/icon/not-collection.png">
  140. <div>暂无内容</div>
  141. </el-col>
  142. </el-row>
  143. </div>
  144. </template>
  145. <script>
  146. import UserCard from '@/components/card/UserCard'
  147. import StatusCard from '@/components/card/StatusCard'
  148. import VideoCard from '@/components/card/VideoCard'
  149. import { getUserInfo, getUserFollowing, getUserFollower, checkRelation, followUser, unfollowUser } from "@/api/user";
  150. import { userVideoList, getUserContentData } from "@/api/video";
  151. import { userStatus } from "@/api/status";
  152. export default {
  153. name: 'Home',
  154. components: { UserCard, StatusCard, VideoCard },
  155. data() {
  156. return {
  157. // 屏幕宽度, 为了控制分页条的大小
  158. screenWidth: document.body.clientWidth,
  159. user: null,
  160. userId: null,
  161. followButton: {
  162. icon: 'el-icon-plus',
  163. text: '关注'
  164. },
  165. activeName: 'status',
  166. currentPage: 1,
  167. pageSize: 12,
  168. totalSize: 0,
  169. videoList: [],
  170. statusList: [],
  171. followerList: [],
  172. followingList: [],
  173. showEmpty: false,
  174. videoCount: 0,
  175. statusCount: 0,
  176. followingCount: 0,
  177. followerCount: 0
  178. }
  179. },
  180. created() {
  181. this.userId = this.$route.params.id
  182. getUserInfo(this.userId).then(res => {
  183. if (res.code === 0) {
  184. this.user = res.data
  185. const path = this.$route.path
  186. if (path.endsWith("video")) {
  187. this.activeName = 'video'
  188. document.title = this.user.screenName + '的视频'
  189. } else if (path.endsWith("image")) {
  190. this.activeName = 'image'
  191. document.title = this.user.screenName + '的相册'
  192. } else if (path.endsWith("audio")) {
  193. this.activeName = 'audio'
  194. document.title = this.user.screenName + '的音频'
  195. } else if (path.endsWith("article")) {
  196. this.activeName = 'article'
  197. document.title = this.user.screenName + '的文章'
  198. } else if (path.endsWith("following")) {
  199. this.activeName = 'following'
  200. document.title = this.user.screenName + '的关注'
  201. } else if (path.endsWith("follower")) {
  202. this.activeName = 'follower'
  203. document.title = this.user.screenName + '的粉丝'
  204. } else {
  205. document.title = this.user.screenName + '的个人主页'
  206. }
  207. }
  208. })
  209. checkRelation(this.userId).then(res => {
  210. if (res.code === 0) {
  211. if (res.data) {
  212. this.followButton.text = '已关注'
  213. this.followButton.icon = 'el-icon-check'
  214. }
  215. }
  216. })
  217. getUserContentData(this.userId).then(res => {
  218. if (res.code === 0) {
  219. const resData = res.data
  220. this.videoCount = resData.videoCount
  221. this.statusCount = resData.statusCount
  222. this.followingCount = resData.userFollowCount.followingCount
  223. this.followerCount = resData.userFollowCount.followerCount
  224. }
  225. })
  226. this.userVideoListWrapper(1, this.userId, 0)
  227. },
  228. mounted() {
  229. // 当窗口宽度改变时获取屏幕宽度
  230. window.onresize = () => {
  231. return () => {
  232. window.screenWidth = document.body.clientWidth
  233. this.screenWidth = window.screenWidth
  234. }
  235. }
  236. },
  237. watch: {
  238. $route(){
  239. this.$router.go()
  240. }
  241. },
  242. methods: {
  243. initPagination() {
  244. this.pageSize = 12
  245. this.currentPage = 1
  246. this.totalSize = 0
  247. },
  248. handleCurrentChange(pageNumber) {
  249. this.currentPage = pageNumber
  250. if (this.activeName === 'video') {
  251. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)
  252. } else if (this.activeName === 'status') {
  253. this.userStatusListWrapper(this.currentPage, this.userId, this.lastId)
  254. } else if (this.activeName === 'following') {
  255. getUserFollowing(this.userId).then(res => {
  256. if (res.code === 0) {
  257. this.followingList = res.data
  258. }
  259. })
  260. } else if (this.activeName === 'follower') {
  261. getUserFollower(this.userId).then(res => {
  262. if (res.code === 0) {
  263. this.followerList = res.data
  264. }
  265. })
  266. }
  267. // 回到顶部
  268. scrollTo(0, 0)
  269. },
  270. tabClick(tab) {
  271. this.activeName = tab.name
  272. if (this.activeName === 'status') {
  273. const path = '/user/' + this.userId
  274. if (this.$route.path === path) {
  275. this.$router.go(0)
  276. return
  277. }
  278. this.$router.push(path)
  279. /*this.currentPage = 1
  280. this.lastId = 0
  281. this.userStatusListWrapper(this.currentPage, this.userId, this.lastId)*/
  282. } else if (this.activeName === 'video') {
  283. this.goToTab(this.activeName)
  284. /*this.currentPage = 1
  285. this.lastId = 0
  286. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)*/
  287. } else if (this.activeName === 'image') {
  288. this.goToTab(this.activeName)
  289. /*this.currentPage = 1
  290. this.lastId = 0
  291. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)*/
  292. } else if (this.activeName === 'audio') {
  293. this.goToTab(this.activeName)
  294. /*this.currentPage = 1
  295. this.lastId = 0
  296. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)*/
  297. } else if (this.activeName === 'article') {
  298. this.goToTab(this.activeName)
  299. /*this.currentPage = 1
  300. this.lastId = 0
  301. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)*/
  302. } else if (this.activeName === 'following') {
  303. this.goToTab(this.activeName)
  304. /*getUserFollowing(this.userId).then(res => {
  305. if (res.code === 0) {
  306. this.followingList = res.data
  307. }
  308. })*/
  309. } else if (this.activeName === 'follower') {
  310. this.goToTab(this.activeName)
  311. /*getUserFollower(this.userId).then(res => {
  312. if (res.code === 0) {
  313. this.followerList = res.data
  314. }
  315. })*/
  316. }
  317. },
  318. goToTab(activeName) {
  319. const path = '/user/' + this.userId + '/' + activeName
  320. if (this.$route.path === path) {
  321. this.$router.go(0)
  322. return
  323. }
  324. this.$router.push(path)
  325. },
  326. getData() {
  327. this.activeName = tab.name
  328. if (this.activeName === 'status') {
  329. this.currentPage = 1
  330. this.lastId = 0
  331. this.userStatusListWrapper(this.currentPage, this.userId, this.lastId)
  332. } else if (this.activeName === 'video') {
  333. this.currentPage = 1
  334. this.lastId = 0
  335. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)
  336. } else if (this.activeName === 'image') {
  337. this.currentPage = 1
  338. this.lastId = 0
  339. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)
  340. } else if (this.activeName === 'audio') {
  341. this.currentPage = 1
  342. this.lastId = 0
  343. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)
  344. } else if (this.activeName === 'article') {
  345. this.currentPage = 1
  346. this.lastId = 0
  347. this.userVideoListWrapper(this.currentPage, this.userId, this.lastId)
  348. } else if (this.activeName === 'following') {
  349. getUserFollowing(this.userId).then(res => {
  350. if (res.code === 0) {
  351. this.followingList = res.data
  352. }
  353. })
  354. } else if (this.activeName === 'follower') {
  355. getUserFollower(this.userId).then(res => {
  356. if (res.code === 0) {
  357. this.followerList = res.data
  358. }
  359. })
  360. }
  361. },
  362. followUser(userId) {
  363. if (this.followButton.text === '关注') {
  364. followUser(userId).then(res => {
  365. if (res.code === 0) {
  366. this.followButton.text = '已关注'
  367. this.followButton.icon = 'el-icon-check'
  368. }
  369. })
  370. } else {
  371. unfollowUser(userId).then(res => {
  372. if (res.code === 0) {
  373. this.followButton.text = '关注'
  374. this.followButton.icon = 'el-icon-plus'
  375. }
  376. })
  377. }
  378. },
  379. sendMessage(userId) {
  380. console.log('发送消息')
  381. },
  382. userVideoListWrapper(pageNumber, userId, lastId) {
  383. userVideoList(pageNumber, userId, lastId).then(res => {
  384. if (res.code === 0) {
  385. const resData = res.data
  386. this.videoList = resData.list
  387. this.totalSize = resData.totalSize
  388. this.lastId = resData.lastId
  389. if (this.videoList.length !== 0) {
  390. this.showEmpty = false
  391. } else {
  392. this.showEmpty = true
  393. }
  394. }
  395. })
  396. },
  397. userStatusListWrapper(pageNumber, userId, lastId) {
  398. userStatus(userId, pageNumber).then(res => {
  399. if (res.code === 0) {
  400. this.statusList = res.data.list
  401. if (this.statusList.length === 0) {
  402. this.showEmpty = true
  403. } else {
  404. this.showEmpty = false
  405. }
  406. }
  407. })
  408. }
  409. }
  410. }
  411. </script>
  412. <style scoped>
  413. .movie-list {
  414. padding-top: 15px;
  415. padding-left: 6%;
  416. padding-right: 6%;
  417. }
  418. .pagination {
  419. text-align: center;
  420. padding: 10px;
  421. }
  422. /*处于手机屏幕时*/
  423. @media screen and (max-width: 768px){
  424. .movie-list {
  425. padding-top: 8px;
  426. padding-left: 0.5%;
  427. padding-right: 0.5%;
  428. }
  429. }
  430. .not-result {
  431. padding-top: 100px;
  432. padding-bottom: 100px;
  433. text-align: center;
  434. }
  435. .item {
  436. margin-top: 10px;
  437. margin-right: 40px;
  438. }
  439. </style>