VideoPage.vue 13 KB

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