VideoPage.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <el-row v-if="video !== null" 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 :video-id="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 v-if="user !== null" :user-avatar="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. >
  138. <template slot-scope="scope">
  139. <router-link target="_blank" :to="`/video/${scope.row.videoId}`">
  140. <span>{{ scope.row.videoId }}</span>
  141. </router-link>
  142. </template>
  143. </el-table-column>
  144. <el-table-column
  145. prop="coverUrl"
  146. >
  147. <template slot-scope="scope">
  148. <span>10:00</span>
  149. </template>
  150. </el-table-column>
  151. </el-table>
  152. </div>
  153. </el-card>
  154. </el-row>
  155. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  156. <el-card class="box-card">
  157. <div slot="header" class="clearfix">
  158. <el-row>
  159. <h3>推荐视频</h3>
  160. </el-row>
  161. <el-row>
  162. <span>自动播放 <el-switch v-model="autoPlay" /></span>
  163. </el-row>
  164. </div>
  165. <div class="text item">
  166. <el-row v-for="(item,index) in similarVideos" :key="index" class="item">
  167. <video-card :video="item" />
  168. </el-row>
  169. </div>
  170. </el-card>
  171. </el-row>
  172. </el-row>
  173. </el-col>
  174. <!-- 视频报错对话框 -->
  175. <el-dialog
  176. append-to-body
  177. :visible.sync="showErrorReportDialog"
  178. width="30%"
  179. center
  180. >
  181. <el-card class="box-card">
  182. <div slot="header" class="clearfix">
  183. <span>视频报错</span>
  184. <el-button style="float: right; padding: 3px 0" type="text" @click="submitErrorReport">提交错误</el-button>
  185. </div>
  186. <div class="text item">
  187. <el-form ref="form" :model="errorReportForm" label-width="80px">
  188. <el-form-item label="错误类型">
  189. <el-select v-model="errorReportForm.errorCode" placeholder="选择视频错误类型">
  190. <el-option label="视频无封面" value="1" />
  191. <el-option label="视频无声音" value="2" />
  192. <el-option label="视频无画面" value="3" />
  193. <el-option label="视频无资源" value="4" />
  194. <el-option label="视频待删除" value="5" />
  195. </el-select>
  196. </el-form-item>
  197. </el-form>
  198. </div>
  199. </el-card>
  200. </el-dialog>
  201. </el-row>
  202. </template>
  203. <script>
  204. import VideoPlayer from 'components/VideoPlayer'
  205. import Comment from 'components/comment/Comment'
  206. import VideoCard from 'components/card/VideoCard'
  207. import UserAvatarCard from '@/components/card/UserAvatarCard'
  208. import { similarVideo, videoInfo, videoErrorReport, downloadVideo, cacheBiliVideo } from '@/api/video'
  209. import { collectItem } from '@/api/collect'
  210. import { getUserInfo } from '@/api/user'
  211. export default {
  212. name: 'VideoPage',
  213. components: { Comment, VideoCard, VideoPlayer, UserAvatarCard },
  214. data() {
  215. return {
  216. video: null,
  217. videoProp: {
  218. info: null,
  219. autoPlay: false,
  220. playlist: []
  221. },
  222. user: null,
  223. similarVideos: [],
  224. isCollected: false,
  225. showErrorReportDialog: false,
  226. errorReportForm: {
  227. videoId: null,
  228. errorCode: null
  229. },
  230. showPlaylist: false,
  231. autoPlay: false
  232. }
  233. },
  234. watch: {
  235. // 地址栏 url 发生变化时重新加载本页面
  236. $route() {
  237. this.$router.go()
  238. }
  239. },
  240. created() {
  241. const videoId = this.$route.params.id
  242. this.getVideoInfo(videoId)
  243. this.getSimilarVideos(videoId)
  244. },
  245. methods: {
  246. // 获取视频的详细信息
  247. getVideoInfo(videoId) {
  248. videoInfo(videoId).then(res => {
  249. if (res.code === 0) {
  250. this.videoProp = res.data
  251. this.video = res.data
  252. document.title = res.data.title
  253. this.userId = res.data.userId
  254. getUserInfo(this.userId).then(res => {
  255. if (res.code === 0) {
  256. this.user = res.data
  257. } else {
  258. this.$notify.error({
  259. message: '用户数据获取失败',
  260. type: 'warning',
  261. duration: 3000
  262. })
  263. }
  264. })
  265. } else {
  266. this.$notify.error({
  267. message: '视频数据获取失败',
  268. type: 'warning',
  269. duration: 3000
  270. })
  271. this.$router.push('/404')
  272. }
  273. }).catch(error => {
  274. this.$notify.error({
  275. message: error.message,
  276. type: 'warning',
  277. duration: 3000
  278. })
  279. })
  280. },
  281. // 获取和当前视频类似的其他视频
  282. getSimilarVideos(videoId) {
  283. similarVideo(videoId).then(res => {
  284. if (res.code === 0) {
  285. this.similarVideos = res.data
  286. } else {
  287. this.$notify.error({
  288. message: '推荐视频数据获取失败',
  289. type: 'warning',
  290. duration: 3000
  291. })
  292. }
  293. }).catch(error => {
  294. this.$notify.error({
  295. message: error.message,
  296. type: 'warning',
  297. duration: 3000
  298. })
  299. })
  300. },
  301. // 换一换
  302. refreshSimilar() {
  303. console.log('刷新相关推荐')
  304. },
  305. // 用户点击收藏
  306. collection(videoId) {
  307. const jsonData = {}
  308. jsonData.contentType = 1002
  309. jsonData.contentId = videoId
  310. jsonData.collected = true
  311. collectItem(jsonData).then(res => {
  312. if (res.code !== 0) {
  313. this.$notify.success({
  314. title: '视频收藏失败',
  315. type: 'warning',
  316. duration: 3000
  317. })
  318. }
  319. })
  320. },
  321. getDownloadUrl(videoId) {
  322. // let filename
  323. downloadVideo(videoId).then(res => {
  324. if (res.code === 0) {
  325. const downloadUrl = res.data.url
  326. window.open(downloadUrl, '_blank')
  327. /* fetch(downloadUrl.url, {
  328. headers: {
  329. Authorization: 'Bearer ' + downloadUrl.token
  330. },
  331. method: 'GET',
  332. credentials: 'include'
  333. }).then(res => {
  334. /!*
  335. 遍历 formdata
  336. for (const key of res.headers.keys()) {
  337. console.log(key + ' : ' + res.headers.get(key))
  338. }*!/
  339. const header = res.headers.get('Content-Disposition')
  340. const parts = header.split(';')
  341. const encodeFilename = parts[1].split('=')[1]
  342. filename = decodeURI(encodeFilename)
  343. return res.blob()
  344. }).then(data => {
  345. const blobUrl = window.URL.createObjectURL(data)
  346. const a = document.createElement('a')
  347. a.download = filename
  348. a.href = blobUrl
  349. a.click()
  350. }).catch(e => {
  351. this.$notify({
  352. title: '提示',
  353. message: '视频下载失败',
  354. type: 'warning',
  355. duration: 3000
  356. })
  357. })*/
  358. } else {
  359. this.$notify({
  360. title: '提示',
  361. message: res.msg,
  362. type: 'warning',
  363. duration: 3000
  364. })
  365. }
  366. }).catch(error => {
  367. this.$notify({
  368. title: '提示',
  369. message: error.message,
  370. type: 'error',
  371. duration: 3000
  372. })
  373. })
  374. },
  375. cacheBiliVideo(bvId) {
  376. cacheBiliVideo(bvId).then(res => {
  377. if (res.code === 0) {
  378. const resData = res.data
  379. this.$notify({
  380. title: '提示',
  381. message: resData.msg,
  382. type: 'warning',
  383. duration: 3000
  384. })
  385. }
  386. })
  387. },
  388. displayErrorReportDialog() {
  389. this.errorReportForm.videoId = this.video.videoId
  390. this.showErrorReportDialog = true
  391. },
  392. submitErrorReport() {
  393. this.showErrorReportDialog = false
  394. videoErrorReport(this.errorReportForm).then(res => {
  395. if (res.code === 0) {
  396. this.$notify({
  397. title: '提示',
  398. message: '视频错误已提交',
  399. type: 'warning',
  400. duration: 3000
  401. })
  402. }
  403. }).catch(error => {
  404. this.$notify({
  405. title: '提示',
  406. message: error.message,
  407. type: 'warning',
  408. duration: 3000
  409. })
  410. })
  411. }
  412. }
  413. }
  414. </script>
  415. <style scoped>
  416. /*处于手机屏幕时*/
  417. @media screen and (max-width: 768px) {
  418. .movie-list {
  419. padding-top: 8px;
  420. padding-left: 0.5%;
  421. padding-right: 0.5%;
  422. }
  423. }
  424. .movie-list {
  425. padding-top: 15px;
  426. padding-left: 5%;
  427. padding-right: 5%;
  428. }
  429. .clearfix:before,
  430. .clearfix:after {
  431. display: table;
  432. content: "";
  433. }
  434. .clearfix:after {
  435. clear: both;
  436. }
  437. .v-tag {
  438. padding-top: 10px;
  439. }
  440. .tag{
  441. margin-right: 3px;
  442. }
  443. </style>