VideoPage.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <el-row class="movie-list">
  3. <el-col :md="15">
  4. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  5. <el-card class="box-card">
  6. <div slot="header" class="clearfix">
  7. <el-row>
  8. <h3 v-html="video.title" />
  9. </el-row>
  10. <el-row style="color: #999;font-size: 16px;padding-top: 0px;">
  11. <span><i class="el-icon-video-play">{{ video.view }}</i></span>
  12. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;'" />
  13. <span><i class="el-icon-s-comment">{{ video.comment }}</i></span>
  14. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;'" />
  15. <span><i class="el-icon-watch">{{ video.pubDate }}</i></span>
  16. </el-row>
  17. </div>
  18. <div class="text item">
  19. <video-player :video-prop="video"/>
  20. </div>
  21. </el-card>
  22. </el-row>
  23. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  24. <el-card class="box-card">
  25. <div slot="header" class="clearfix">
  26. <div class="video-data-row">
  27. <el-button
  28. type="danger"
  29. size="mini"
  30. icon="el-icon-collection"
  31. :disabled="isCollected"
  32. @click="collection(video.videoId)"
  33. >
  34. <span>收藏 {{ video.favorite }}</span>
  35. </el-button>
  36. <el-button
  37. type="danger"
  38. size="mini"
  39. icon="el-icon-thumb"
  40. :disabled="isCollected"
  41. @click="collection(video.videoId)"
  42. >
  43. <span>喜欢 {{ video.thumbUp }}</span>
  44. </el-button>
  45. <el-button
  46. type="danger"
  47. size="mini"
  48. icon="el-icon-share"
  49. :disabled="isCollected"
  50. @click="collection(video.videoId)"
  51. >
  52. <span>分享 {{ video.share }}</span>
  53. </el-button>
  54. <el-button
  55. type="danger"
  56. size="mini"
  57. icon="el-icon-download"
  58. @click="getDownloadUrl(video.videoId)"
  59. >
  60. <span>下载</span>
  61. </el-button>
  62. <el-button
  63. v-if="video.cache != null"
  64. type="danger"
  65. size="mini"
  66. icon="el-icon-download"
  67. @click="cacheBiliVideo(video.videoId)"
  68. >
  69. <span>{{video.cache.msg}}</span>
  70. </el-button>
  71. <el-button
  72. type="danger"
  73. size="mini"
  74. icon="el-icon-help"
  75. @click="displayErrorReportDialog"
  76. >
  77. <span>报错</span>
  78. </el-button>
  79. </div>
  80. </div>
  81. <div class="text item">
  82. <!--视频描述行-->
  83. <span class="description" v-html="video.description"/>
  84. <el-divider/>
  85. <!--视频标签行-->
  86. <div class="v-tag">
  87. <el-tag
  88. v-for="(tag,index) in video.tags"
  89. :key="index"
  90. class="tag"
  91. size="medium"
  92. effect="plain"
  93. >
  94. <router-link target="_blank" :to="`/video/tag/` + tag">
  95. {{ tag }}
  96. </router-link>
  97. </el-tag>
  98. </div>
  99. </div>
  100. </el-card>
  101. </el-row>
  102. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  103. <el-card class="box-card">
  104. <div slot="header" class="clearfix">
  105. <el-row>
  106. <h3>视频评论</h3>
  107. </el-row>
  108. </div>
  109. <div class="text item">
  110. <comment :videoId="video.videoId" />
  111. </div>
  112. </el-card>
  113. </el-row>
  114. </el-col>
  115. <el-col :md="9">
  116. <el-row>
  117. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  118. <user-avatar-card :userAvatar="user" />
  119. </el-row>
  120. <el-row v-if="showPlaylist" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  121. <el-card class="box-card">
  122. <div slot="header" class="clearfix">
  123. <el-row>
  124. <h3>播放列表</h3>
  125. </el-row>
  126. <el-row>
  127. <span>自动播放 <el-switch v-model="autoPlay"/></span>
  128. </el-row>
  129. </div>
  130. <div class="text item">
  131. <el-table
  132. :data="similarVideos"
  133. style="width: 100%"
  134. >
  135. <el-table-column
  136. prop="title">
  137. <template slot-scope="scope">
  138. <router-link target="_blank" :to="`/video/${scope.row.videoId}`">
  139. <span>{{scope.row.videoId}}</span>
  140. </router-link>
  141. </template>
  142. </el-table-column>
  143. <el-table-column
  144. prop="coverUrl">
  145. <template slot-scope="scope">
  146. <span>10:00</span>
  147. </template>
  148. </el-table-column>
  149. </el-table>
  150. </div>
  151. </el-card>
  152. </el-row>
  153. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  154. <el-card class="box-card">
  155. <div slot="header" class="clearfix">
  156. <el-row>
  157. <h3>推荐视频</h3>
  158. </el-row>
  159. <el-row>
  160. <span>自动播放 <el-switch v-model="autoPlay"/></span>
  161. </el-row>
  162. </div>
  163. <div class="text item">
  164. <el-row v-for="(item,index) in similarVideos" :key="index" class="item">
  165. <video-card :video="item" />
  166. </el-row>
  167. </div>
  168. </el-card>
  169. </el-row>
  170. </el-row>
  171. </el-col>
  172. <!-- 视频报错对话框 -->
  173. <el-dialog
  174. append-to-body
  175. :visible.sync="showErrorReportDialog"
  176. width="30%"
  177. center
  178. >
  179. <el-card class="box-card">
  180. <div slot="header" class="clearfix">
  181. <span>视频报错</span>
  182. <el-button style="float: right; padding: 3px 0" type="text" @click="submitErrorReport">提交错误</el-button>
  183. </div>
  184. <div class="text item">
  185. <el-form ref="form" :model="errorReportForm" label-width="80px">
  186. <el-form-item label="错误类型">
  187. <el-select v-model="errorReportForm.errorCode" placeholder="选择视频错误类型">
  188. <el-option label="视频无封面" value="1" />
  189. <el-option label="视频无声音" value="2" />
  190. <el-option label="视频无画面" value="3" />
  191. <el-option label="视频无资源" value="4" />
  192. <el-option label="视频待删除" value="5" />
  193. </el-select>
  194. </el-form-item>
  195. </el-form>
  196. </div>
  197. </el-card>
  198. </el-dialog>
  199. </el-row>
  200. </template>
  201. <script>
  202. import VideoPlayer from 'components/VideoPlayer'
  203. import Comment from 'components/comment/Comment'
  204. import VideoCard from 'components/card/VideoCard'
  205. import UserAvatarCard from '@/components/card/UserAvatarCard'
  206. import {similarVideo, videoInfo, videoErrorReport, downloadVideo, cacheBiliVideo} from '@/api/video'
  207. import { collectVideo } from "@/api/collect";
  208. import {getUserInfo} from "@/api/user";
  209. export default {
  210. name: 'VideoPage',
  211. components: { Comment, VideoCard, VideoPlayer, UserAvatarCard },
  212. data() {
  213. return {
  214. video: null,
  215. videoProp: {
  216. info: null,
  217. autoPlay: false,
  218. playlist: []
  219. },
  220. user: null,
  221. similarVideos: [],
  222. isCollected: false,
  223. showErrorReportDialog: false,
  224. errorReportForm: {
  225. videoId: null,
  226. errorCode: null
  227. },
  228. showPlaylist: false,
  229. autoPlay: false,
  230. }
  231. },
  232. watch: {
  233. // 地址栏 url 发生变化时重新加载本页面
  234. $route(){
  235. this.$router.go()
  236. }
  237. },
  238. created() {
  239. const videoId = this.$route.params.id
  240. this.getVideoInfo(videoId)
  241. this.getSimilarVideos(videoId)
  242. },
  243. methods: {
  244. // 获取视频的详细信息
  245. getVideoInfo(videoId) {
  246. videoInfo(videoId).then(res => {
  247. if (res.code === 0) {
  248. this.videoProp = res.data
  249. this.video = res.data
  250. document.title = res.data.title
  251. this.userId = res.data.userId
  252. getUserInfo(this.userId).then(res => {
  253. if (res.code === 0) {
  254. this.user = res.data
  255. } else {
  256. this.$notify.error({
  257. message: '用户数据获取失败',
  258. type: 'warning',
  259. duration: 3000
  260. })
  261. }
  262. })
  263. } else {
  264. this.$notify.error({
  265. message: '视频数据获取失败',
  266. type: 'warning',
  267. duration: 3000
  268. })
  269. this.$router.push('/404')
  270. }
  271. }).catch(error => {
  272. this.$notify.error({
  273. message: error.message,
  274. type: 'warning',
  275. duration: 3000
  276. })
  277. })
  278. },
  279. // 获取和当前视频类似的其他视频
  280. getSimilarVideos(videoId) {
  281. similarVideo(videoId).then(res => {
  282. if (res.code === 0) {
  283. this.similarVideos = res.data
  284. } else {
  285. this.$notify.error({
  286. message: '推荐视频数据获取失败',
  287. type: 'warning',
  288. duration: 3000
  289. })
  290. }
  291. }).catch(error => {
  292. this.$notify.error({
  293. message: error.message,
  294. type: 'warning',
  295. duration: 3000
  296. })
  297. })
  298. },
  299. // 换一换
  300. refreshSimilar() {
  301. console.log('刷新相关推荐')
  302. },
  303. // 用户点击收藏
  304. collection(videoId) {
  305. collectVideo({videoId: videoId}).then(res => {
  306. if (res.code === 0) {
  307. this.$notify.success({
  308. title: '视频已收藏',
  309. duration: 2000
  310. })
  311. } else {
  312. }
  313. })
  314. },
  315. getDownloadUrl(videoId) {
  316. let filename
  317. downloadVideo(videoId).then(res => {
  318. if (res.code === 0) {
  319. const downloadUrl = res.data
  320. fetch(downloadUrl.url, {
  321. headers: {
  322. Authorization: 'Bearer ' + downloadUrl.token
  323. },
  324. method: 'GET',
  325. credentials: 'include',
  326. }).then(res => {
  327. /*
  328. 遍历 formdata
  329. for (const key of res.headers.keys()) {
  330. console.log(key + ' : ' + res.headers.get(key))
  331. }*/
  332. const header = res.headers.get('Content-Disposition');
  333. const parts = header.split(';');
  334. const encodeFilename = parts[1].split('=')[1];
  335. filename = decodeURI(encodeFilename)
  336. return res.blob()
  337. }).then(data => {
  338. const blobUrl = window.URL.createObjectURL(data);
  339. const a = document.createElement('a');
  340. a.download = filename;
  341. a.href = blobUrl;
  342. a.click();
  343. }).catch(e => {
  344. this.$notify({
  345. title: '提示',
  346. message: '视频下载失败',
  347. type: 'warning',
  348. duration: 3000
  349. })
  350. })
  351. } else {
  352. this.$notify({
  353. title: '提示',
  354. message: res.msg,
  355. type: 'warning',
  356. duration: 3000
  357. })
  358. }
  359. }).catch(error => {
  360. this.$notify({
  361. title: '提示',
  362. message: error.message,
  363. type: 'error',
  364. duration: 3000
  365. })
  366. })
  367. },
  368. cacheBiliVideo(bvId) {
  369. cacheBiliVideo(bvId).then(res => {
  370. if (res.code === 0) {
  371. const resData = res.data
  372. this.$notify({
  373. title: '提示',
  374. message: resData.msg,
  375. type: 'warning',
  376. duration: 3000
  377. })
  378. }
  379. })
  380. },
  381. displayErrorReportDialog() {
  382. this.errorReportForm.videoId = this.video.videoId
  383. this.showErrorReportDialog = true
  384. },
  385. submitErrorReport() {
  386. this.showErrorReportDialog = false
  387. videoErrorReport(this.errorReportForm).then(res => {
  388. if (res.code === 0) {
  389. this.$notify({
  390. title: '提示',
  391. message: '视频错误已提交',
  392. type: 'warning',
  393. duration: 3000
  394. })
  395. }
  396. }).catch(error => {
  397. this.$notify({
  398. title: '提示',
  399. message: error.message,
  400. type: 'warning',
  401. duration: 3000
  402. })
  403. })
  404. },
  405. }
  406. }
  407. </script>
  408. <style scoped>
  409. /*处于手机屏幕时*/
  410. @media screen and (max-width: 768px) {
  411. .movie-list {
  412. padding-top: 8px;
  413. padding-left: 0.5%;
  414. padding-right: 0.5%;
  415. }
  416. }
  417. .movie-list {
  418. padding-top: 15px;
  419. padding-left: 5%;
  420. padding-right: 5%;
  421. }
  422. .clearfix:before,
  423. .clearfix:after {
  424. display: table;
  425. content: "";
  426. }
  427. .clearfix:after {
  428. clear: both;
  429. }
  430. .v-tag {
  431. padding-top: 10px;
  432. }
  433. .tag{
  434. margin-right: 3px;
  435. }
  436. </style>