index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="video-player-container">
  3. <el-dialog
  4. :visible.sync="dialogVisible"
  5. :title="videoTitle"
  6. width="800px"
  7. @close="handleClose"
  8. >
  9. <video
  10. ref="videoPlayer"
  11. class="video-player"
  12. :src="videoUrl"
  13. autoplay
  14. muted
  15. controls
  16. controlsList="nodownload"
  17. >
  18. 您的浏览器不支持 video 标签
  19. </video>
  20. </el-dialog>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. name: "VideoPlayer",
  26. props: {
  27. videoUrl: {
  28. type: [String, null],
  29. default: null
  30. },
  31. videoTitle: {
  32. type: [String, null],
  33. default: "视频播放"
  34. }
  35. },
  36. data() {
  37. return {
  38. dialogVisible: false
  39. };
  40. },
  41. methods: {
  42. show() {
  43. this.dialogVisible = true;
  44. this.$nextTick(() => {
  45. const video = this.$refs.videoPlayer;
  46. if (video) {
  47. video.muted = false;
  48. }
  49. });
  50. },
  51. handleClose() {
  52. const video = this.$refs.videoPlayer;
  53. if (video) {
  54. video.pause();
  55. video.currentTime = 0;
  56. }
  57. this.dialogVisible = false;
  58. this.$emit("close");
  59. }
  60. }
  61. };
  62. </script>
  63. <style lang="scss" scoped>
  64. .video-player-container {
  65. .video-player {
  66. width: 100%;
  67. height: auto;
  68. max-height: 70vh;
  69. }
  70. }
  71. </style>