VideoPage.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <div class="player">
  3. <el-row style="padding-top: 12px" :gutter="20">
  4. <el-col :md="15">
  5. <el-row>
  6. <h3 v-text="video.title" />
  7. </el-row>
  8. <el-row style="color: #999;font-size: 16px;padding-top: 0px;">
  9. <span><i class="el-icon-video-play">{{ video.viewCount }}</i></span>
  10. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;'" />
  11. <span><i class="el-icon-s-comment">{{ video.commentCount }}</i></span>
  12. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;'" />
  13. <span><i class="el-icon-watch">{{ video.pubDate }}</i></span>
  14. </el-row>
  15. </el-col>
  16. <el-col :md="9">
  17. <el-row>
  18. <el-col :md="3">
  19. <router-link target="_blank" :to="`/user/` + video.userId">
  20. <el-avatar>
  21. <el-image :src="video.avatarUrl" />
  22. </el-avatar>
  23. </router-link>
  24. </el-col>
  25. <el-col :md="6">
  26. <router-link target="_blank" :to="`/user/` + video.userId"><span>{{ video.username }}</span></router-link>
  27. <router-link target="_blank" :to="`/message/` + video.userId"><span class="el-icon-message">发消息</span></router-link>
  28. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;'" />
  29. <el-button small outlined color="primary">
  30. <span>已关注</span>
  31. <!-- <span v-if="!isFollowed">关注</span>-->
  32. <span v-html="'&nbsp;&nbsp;'" />
  33. <span>2000</span>
  34. </el-button>
  35. </el-col>
  36. </el-row>
  37. </el-col>
  38. </el-row>
  39. <el-row style="padding-top: 12px" :gutter="20"><!--gutter为栅格的间隔-->
  40. <!--播放列-->
  41. <el-col :md="15">
  42. <!--视频播放框-->
  43. <video-player :video-prop="video" />
  44. <div class="el-icon-collection">
  45. {{ "已收藏" + video.collectCount + "次" }}
  46. <el-button
  47. type="danger"
  48. size="mini"
  49. icon="el-icon-star-off"
  50. :disabled="isCollection"
  51. @click="collection(video.videoId)"
  52. >
  53. {{ isCollection ? "您已收藏" : "点击收藏" }}
  54. </el-button>
  55. <el-button
  56. type="danger"
  57. size="mini"
  58. icon="el-icon-download"
  59. :disabled="isCollection"
  60. @click="collection(video.videoId)"
  61. >
  62. <span>下载</span>
  63. </el-button>
  64. </div>
  65. <span class="description">{{ video.description }}</span>
  66. <!--视频标签-->
  67. <div class="v-tag">
  68. <el-tag
  69. v-for="(tag,index) in video.tagList"
  70. :key="index"
  71. class="tag"
  72. size="medium"
  73. effect="plain"
  74. >
  75. <router-link target="_blank" :to="`/video/tag/` + tag">
  76. {{ tag }}
  77. </router-link>
  78. </el-tag>
  79. <el-input
  80. v-if="inputVisible"
  81. ref="saveTagInput"
  82. v-model="inputValue"
  83. class="input-new-tag"
  84. size="mini"
  85. @keyup.enter.native="handleInputConfirm"
  86. @blur="handleInputConfirm"
  87. />
  88. <el-button v-else class="button-new-tag" size="mini" @click="showInput">+ 添加标签</el-button>
  89. </div>
  90. <!--评论-->
  91. <comment :vid="video.videoId" />
  92. </el-col>
  93. <!--推荐列-->
  94. <el-col :md="9">
  95. <el-card class="box-card">
  96. <div slot="header" class="clearfix">
  97. <span>弹幕列表</span><i class="el-icon-more" />
  98. <span style="float: right; padding: 3px 0" type="text"><i class="el-icon-arrow-down" /></span>
  99. <el-table
  100. :data="tableData"
  101. size="medium"
  102. class="text"
  103. style="width: 100%"
  104. height="300"
  105. >
  106. <el-table-column
  107. prop="date"
  108. label="时间"
  109. width="60"
  110. />
  111. <el-table-column
  112. prop="name"
  113. label="弹幕内容"
  114. />
  115. <el-table-column
  116. prop="address"
  117. label="发送时间"
  118. width="120"
  119. />
  120. </el-table>
  121. </div>
  122. <div class="bottom clearfix">
  123. <el-button type="text" class="button">查看弹幕历史</el-button>
  124. </div>
  125. </el-card>
  126. <div class="about">
  127. <div>相关推荐</div>
  128. <el-button
  129. type="primary"
  130. size="small"
  131. icon="el-icon-refresh"
  132. circle
  133. @click="updateVideos"
  134. >换一换</el-button>
  135. </div>
  136. <el-row v-for="(item,index) in similarVideos" :key="index" class="item">
  137. <video-card :video="video" />
  138. </el-row>
  139. </el-col>
  140. </el-row>
  141. </div>
  142. </template>
  143. <script>
  144. import { similarVideo, videoInfo, getVideoComment } from '@/api/video'
  145. import VideoPlayer from 'components/VideoPlayer'
  146. import Comment from 'components/comment/Comment'
  147. import VideoCard from 'components/card/VideoCard'
  148. export default {
  149. name: 'VideoPage',
  150. components: { Comment, VideoCard, VideoPlayer },
  151. data() {
  152. return {
  153. video: null,
  154. similarVideos: [],
  155. // 标签的样式数组
  156. types: ['', 'success', 'info', 'danger', 'warning'],
  157. // 标签
  158. tags: [],
  159. // 相关推荐videos
  160. videos: [],
  161. showVideo: true,
  162. isCollection: false, // 用户收藏状态
  163. collectionNum: 0, // 收藏次数
  164. inputVisible: false,
  165. inputValue: '',
  166. tableData: [{
  167. date: '00:09',
  168. name: '王小虎1',
  169. address: '05-02 22:10'
  170. }
  171. ]
  172. }
  173. },
  174. watch: {
  175. // 当video改变时修改标签组
  176. /* video(newVal) {
  177. // 将关键字以逗号分隔为数组保存到标签组
  178. this.tags = newVal.keyword.split(',')
  179. }*/
  180. },
  181. created() {
  182. const videoId = this.$route.params.id
  183. console.log('Video ID -> ' + videoId)
  184. this.getVideoInfo(videoId)
  185. this.getSimilarVideos(videoId)
  186. // 将关键字以逗号分隔为数组保存到标签组
  187. // this.tags = this.video.tags.split(',')
  188. // 相关推荐列表
  189. // this.updateVideos()
  190. // 获取当前登录对象
  191. const user = this.$user
  192. if (user) {
  193. this.isCollection = true
  194. /* isCollection(user.uid, this.video.vid).then(res => {
  195. if (res) {
  196. this.isCollection = true
  197. }
  198. })*/
  199. }
  200. // 获取当前视频收藏次数
  201. /* getCollectionNum(this.video.vid).then(res => {
  202. this.collectionNum = res
  203. })*/
  204. getVideoComment(videoId).then(res => {
  205. console.log(res)
  206. })
  207. },
  208. methods: {
  209. // 获取视频的详细信息
  210. getVideoInfo(videoId) {
  211. videoInfo(videoId)
  212. .then(res => {
  213. if (res.code === 0) {
  214. this.video = res.data
  215. document.title = res.data.title
  216. this.userId = res.data.userId
  217. } else {
  218. console.error(res.msg)
  219. }
  220. })
  221. .catch(error => {
  222. console.error(error.message)
  223. })
  224. },
  225. // 获取和当前视频类似的其他视频
  226. getSimilarVideos(videoId) {
  227. similarVideo(videoId)
  228. .then(res => {
  229. if (res.code === 0) {
  230. this.similarVideos = res.data
  231. } else {
  232. console.error(res.msg)
  233. }
  234. })
  235. .catch(error => {
  236. console.error(error.message)
  237. })
  238. },
  239. // 添加标签相关方法
  240. showInput() {
  241. this.inputVisible = true
  242. this.$nextTick(() => {
  243. this.$refs.saveTagInput.$refs.input.focus()
  244. })
  245. },
  246. handleInputConfirm() {
  247. const inputValue = this.inputValue
  248. if (this.tags.indexOf(inputValue) !== -1) {
  249. this.$message.info('该标签已存在!')
  250. } else {
  251. this.tags.push(inputValue)
  252. // addTag(this.tags.join(','), this.video.vid).then(res => console.log(res)) // 添加标签
  253. }
  254. this.inputVisible = false
  255. this.inputValue = ''
  256. },
  257. // 换一换
  258. updateVideos() {
  259. },
  260. // 跳转到播放页面,携带video数据
  261. toPlayer(item) {
  262. this.showVideo = false
  263. // 异步更新dom,重新渲染pvideo
  264. this.$nextTick(() => {
  265. this.showVideo = true
  266. })
  267. // 回到顶部
  268. scrollTo(0, 0)
  269. this.video = item
  270. // 添加播放次数
  271. // addVisited(item.vid)
  272. // 根据此视频判断当前用户是否收藏
  273. const user = this.$user
  274. if (user) {
  275. /* isCollection(user.uid, item.vid).then(res => {
  276. if (res) {
  277. this.isCollection = true
  278. } else {
  279. this.isCollection = false
  280. }
  281. })*/
  282. }
  283. // 获取当前视频收藏次数
  284. /* getCollectionNum(this.video.vid).then(res => {
  285. this.collectionNum = res
  286. })*/
  287. // 添加播放历史记录
  288. if (user) {
  289. /* addHistory(user.uid, this.video.vid).then(res => {
  290. // console.log(res);
  291. })*/
  292. }
  293. },
  294. /* // 用户点击收藏
  295. collection() {
  296. // 获取user
  297. let user = this.$user
  298. if (!user) {
  299. this.$toast.show("用户未登录",2000)
  300. }
  301. }, */
  302. // 用户点击收藏
  303. collection(vid) {
  304. // 1.判断用户是否登录
  305. // 1.1 通过cookie获取用户
  306. const user = this.$user
  307. if (user) {
  308. // 用户已登录
  309. // console.log(user);
  310. // 添加收藏
  311. /* userCollection(user.uid, vid).then((res) => {
  312. // console.log(res);
  313. if (res === 1) {
  314. this.collectionNum++
  315. this.isCollection = true
  316. // 收藏成功
  317. this.$notify.success({
  318. title: '收藏成功',
  319. duration: 2000
  320. })
  321. }
  322. })*/
  323. } else {
  324. // 用户未登录,给出提示
  325. this.$notify({
  326. title: '提示',
  327. message: '要登陆后才可以收藏哦!',
  328. type: 'warning',
  329. duration: 3000
  330. })
  331. }
  332. }
  333. }
  334. }
  335. </script>
  336. <style scoped>
  337. .text {
  338. font-size: 14px;
  339. }
  340. .item {
  341. margin-bottom: 18px;
  342. }
  343. .clearfix:before,
  344. .clearfix:after {
  345. display: table;
  346. content: "";
  347. }
  348. .clearfix:after {
  349. clear: both
  350. }
  351. .box-card {
  352. width: 480px;
  353. }
  354. .player {
  355. padding-top: 20px;
  356. padding-left: 6%;
  357. padding-right: 6%;
  358. }
  359. .about {
  360. font-size: 18px;
  361. margin-top: 10px;
  362. display: flex;
  363. justify-content: space-between;
  364. }
  365. .content {
  366. padding-bottom: 20px;
  367. }
  368. .item {
  369. cursor: pointer;
  370. margin-bottom: 10px;
  371. border-bottom: 1px solid rgba(34, 36, 38, .15);
  372. box-shadow: 0 1px 2px 0 rgba(34, 36, 38, .15);
  373. }
  374. .item:hover {
  375. background-color: rgb(236, 245, 255);
  376. color: rgb(102, 177, 255);
  377. }
  378. .img-col {
  379. padding-right: 10px;
  380. }
  381. .coverImg {
  382. margin-top: 10px;
  383. margin-bottom: 8px;
  384. width: 100%;
  385. /*height: 120px;*/
  386. border-radius: 3px;
  387. }
  388. .detail {
  389. margin-top: 8%;
  390. }
  391. .vname {
  392. font-weight: 600;
  393. font-size: 15px;
  394. height: 40px;
  395. overflow: hidden;
  396. text-overflow: ellipsis;
  397. display: -webkit-box;
  398. -webkit-line-clamp: 2; /*行数*/
  399. -webkit-box-orient: vertical;
  400. }
  401. .visited {
  402. font-size: 13px;
  403. padding-top: 6px;
  404. }
  405. .video-name {
  406. font-size: 20px;
  407. padding-top: 20px;
  408. display: block;
  409. }
  410. .description {
  411. display: block;
  412. padding-top: 10px;
  413. font-size: 13px;
  414. color: rgb(127, 102, 102);
  415. }
  416. .v-tag {
  417. padding-top: 10px;
  418. }
  419. .tag{
  420. margin-right: 3px;
  421. }
  422. .el-icon-collection {
  423. padding-top: 10px;
  424. font-size: 13px;
  425. padding-right: 10px;
  426. }
  427. .bread {
  428. font-size: 15px;
  429. }
  430. /*处于手机屏幕时*/
  431. @media screen and (max-width: 768px){
  432. .player {
  433. padding-left: 1%;
  434. padding-right: 1%;
  435. }
  436. .vname {
  437. font-size: 13px;
  438. }
  439. .visited {
  440. font-size: 11px;
  441. }
  442. }
  443. .button-new-tag {
  444. height: 28px;
  445. line-height: 28px;
  446. color: #66b1ff;
  447. padding-top: 0;
  448. padding-bottom: 0;
  449. }
  450. .input-new-tag {
  451. width: 90px;
  452. vertical-align: bottom;
  453. }
  454. </style>