index.vue 4.54 KB
<template>
  <div class="ai-video-container">
    <!-- 左侧图片 -->
    <div class="left-image">
      <img src="@/assets/images/left.png" alt="left" class="left-img" />
    </div>

    <!-- 右侧视频区 -->
    <div class="right-content">
      <div class="video-frame">
        <div class="video-container">
          <video controls class="video-box" ref="video">
            <source :src="videoSrc" type="video/mp4" />
          </video>
          <div class="video-pause" @click="hanldPlay('pause')" v-if="status == 'play'">
            <img src="@/assets/images/play-icon.png" />
          </div>
          <div class="video-play" @click="hanldPlay('play')" v-if="status == 'pause'">
            <img src="@/assets/images/pause-icon.png" />
          </div>
        </div>
        <!-- 四角装饰 -->
        <div class="corner corner-tl"></div>
        <div class="corner corner-tr"></div>
        <div class="corner corner-bl"></div>
        <div class="corner corner-br"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AiVideo',

  data() {
    return {
      videoSrc: 'https://img02.glsx.com.cn/weapp/resource/shuke/video/video.mp4',
      status: 'play',
      timer: null
    }
  },

  mounted() {
    this.watchVideo()
  },
  watch: {
    status(val) {
      if (this.timer) {
        clearTimeout(this.timer)
      }
      if (val == 'pause') {
        this.timer = setTimeout(() => {
          this.status = ''
        }, 3000)
      }
    }
  },
  methods: {
    watchVideo() {
      this.$refs.video.addEventListener('ended', () => {
        this.status = 'play'
      })
      this.$refs.video.addEventListener('play', () => {
        this.status = 'pause'
      })
      this.$refs.video.addEventListener('pause', () => {
        this.status = 'play'
      })
      document.addEventListener('keydown', this.handleDown)
      document.addEventListener('fullscreenchange', function (e) {
        let isFull
        if (document.fullscreenElement) {
          isFull = true
        } else {
          isFull = false
        }
        this.isFull = true
      })
    },
    handleDown(e) {
      if (e.keyCode === 32) {
        // 执行相应的操作
        if (this.status == 'play') {
          this.$refs.video.play()
        } else {
          this.$refs.video.pause()
        }
      }
    },
    hanldPlay(status) {
      if (status == 'pause') {
        this.$refs.video.play()
      } else {
        this.$refs.video.pause()
      }
    }
  },
  beforeDestroy() {
    document.removeEventListener('keydown', this.handleDown)
    // this.$refs.video.pause()
  }
}
</script>

<style lang="scss" scoped>
.ai-video-container {
  width: 100%;
  box-sizing: border-box;
  margin: 20px auto;
  position: relative;
  display: flex;
  justify-content: center;
  padding: 40px 60px;
  gap: 40px;
}

.left-image {
  width: 893px;
  height: 752px;
  display: flex;
  flex-direction: column;
}

.right-content {
  width: 1112px;
  height: 658px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-frame {
  position: relative;
  width: 100%;
  height: 100%;
}

.video-container {
  width: 100%;
  height: 100%;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 184, 255, 0.3);
  box-shadow: 0 0 40px rgba(0, 184, 255, 0.2);

  .video-box {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .video-pause,
  .video-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;

    &:hover {
      transform: translate(-50%, -50%) scale(1.1);
      background: rgba(0, 184, 255, 0.6);
    }

    img {
      width: 40px;
      height: 40px;
      object-fit: contain;
    }
  }
}

.corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 3px solid #00b8ff;
  box-shadow: 0 0 10px rgba(0, 184, 255, 0.5);
}

.corner-tl {
  top: -2px;
  left: -2px;
  border-right: none;
  border-bottom: none;
  border-radius: 8px 0 0 0;
}

.corner-tr {
  top: -2px;
  right: -2px;
  border-left: none;
  border-bottom: none;
  border-radius: 0 8px 0 0;
}

.corner-bl {
  bottom: -2px;
  left: -2px;
  border-right: none;
  border-top: none;
  border-radius: 0 0 0 8px;
}

.corner-br {
  bottom: -2px;
  right: -2px;
  border-left: none;
  border-top: none;
  border-radius: 0 0 8px 0;
}
</style>