dialogueDetail.vue 8.09 KB
<template>
  <div class="dialogue">
    <div class="record">
      <audio id="audio1">
        <!-- <source src="https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/file.mp3" type="audio/mpeg" /> -->
        <source :src="detailObj.fileUrl" type="audio/mpeg" />
        <source :src="detailObj.fileUrl" type="audio/ogg" />
        您的浏览器不支持 audio 标签。
      </audio>
      <div class="play" v-if="isPlay" @click="handleAudio">
        <img src="@/assets/play.png" />
      </div>
      <div class="play" v-else @click="handleAudio">
        <img src="@/assets/pause.png" />
      </div>
      <div class="times">{{ currentTime }}/{{ totalTime }}</div>
      <div id="progressBar" @mousemove="isCircle = true" @mouseout="isCircle = false">
        <div id="progress">
          <div class="circle" @mousemove="isCircle = true" draggable="true" v-if="isCircle"></div>
        </div>
      </div>
      <div class="trumpet" @click="handleMute">
        <img src="@/assets/trumpet.png" v-if="isMuted" />
        <img src="@/assets/mute.png" v-if="!isMuted" />
      </div>
    </div>
    <div class="record-info">
      <div class="dialog">
        <template v-for="item in dialogList">
          <div :class="{ 'dialog-detail': true, 'nth-child': item.role % 2 === 1 }" :key="item.id">
            <div class="name">
              <img class="role" src="@/assets/role-one.png" v-if="item.role % 2 === 0" />
              角色{{ (item.role % 2) + 1 }}
              <img class="role" src="@/assets/role-two.png" v-if="item.role % 2 === 1" />
            </div>
            <div class="dig-content" @click="currentDialog(item)">
              {{ item.content }}
            </div>
          </div>
        </template>
      </div>
      <div class="abstract">
        <div class="title">
          <img class="robot" src="@/assets/robot.png" />
          AI对话摘要
        </div>
        <div class="abText" v-html="formatSrt(detailObj.digest)">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    detailObj: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      myAud: '',
      isPlay: true,
      isMuted:true,
      dialogList: [],
      totalTime: '0:00',
      currentTime: '0:00',
      isCircle: false
    }
  },
  mounted() {
    this.myAud = document.getElementById('audio1')

    this.handleprogress()
    this.conversationDetailPage()
  },
  methods: {
    formatSrt(str) {
      return str.replace(/\n/g, "<br/>")
    },
    currentDialog(data) {
      this.myAud.currentTime = data.mergedOffset
    },
    toMinutesAndSeconds(seconds) {
      let minutes = Math.floor(seconds / 60)
      let remainingSeconds = parseInt(seconds % 60)
      minutes = minutes > 10 ? minutes : `0${minutes}`
      remainingSeconds = remainingSeconds > 10 ? remainingSeconds : `0${remainingSeconds}`
      return `${minutes}:${remainingSeconds}`
    },
    handleprogress() {
      const progress = document.getElementById('progress')
      const progressBar = document.getElementById('progressBar')
      this.myAud.addEventListener('canplay', () => {
        if (this.myAud.duration > 0) {
          this.totalTime = this.toMinutesAndSeconds(this.myAud.duration)
        }
      })
      this.myAud.addEventListener('timeupdate', () => {
        if (this.myAud.duration > 0) {
          this.currentTime = this.toMinutesAndSeconds(this.myAud.currentTime)
          const progressDur = (this.myAud.currentTime / this.myAud.duration) * 100
          progress.style.width = `${progressDur}%`
        }
      })
      this.myAud.addEventListener('ended', () => {
        this.isPlay = !this.isPlay
      })
      progress.addEventListener(
        'click',
        e => {
          let x = e.offsetX / 370

          let currentWidth = x * this.myAud.duration
          this.myAud.currentTime = currentWidth
        },
        false
      )
      progressBar.addEventListener(
        'click',
        e => {
          let x = e.offsetX / 370
          let currentWidth = x * this.myAud.duration
          this.myAud.currentTime = currentWidth
        },
        false
      )
    },
    handleAudio() {
      this.isPlay = !this.isPlay
      if (!this.isPlay) {
        this.myAud.play()
      } else {
        this.myAud.pause()
      }
    },
    handleMute() {
      this.isMuted = !this.isMuted
      console.log(this.isMuted)
      this.myAud.muted=!this.isMuted
    },
    conversationDetailPage() {
      this.$apis.quality
        .conversationDetailPage({
          batchId: this.detailObj.id,
          currentPage: 1,
          pageSize: 9999
        })
        .then(res => {
          this.dialogList = res.list
        })
    }
  }
}
</script>

<style scoped lang="scss">
.dialogue {
  margin: auto;
  .record {
    width: 600px;
    margin: 5px auto 0px;
    height: 56px;
    background: #f7f9fa;
    border-radius: 32px;
    display: flex;
    align-items: center;
    audio {
      width: 600px;
      height: 56px;
      background: #f7f9fa;
      border-radius: 32px;
    }
  }
  .play {
    width: 24px;
    height: 24px;
    margin: 0 20px 0 24px;
    img {
      width: 100%;
    }
  }
  .trumpet {
    width: 16px;
    height: 16px;
    margin-left: 24px;
    img {
      width: 100%;
    }
  }
  .times {
    font-size: 14px;
    color: #666666;
    min-width: 80px;
    text-align: center;
    margin-right: 19px;
  }
  #progressBar {
    // position: absolute;
    height: 6px;
    width: 370px;
    background-color: #e7e7e7; /* 进度条背景颜色 */
    border-radius: 6px;
  }

  #progress {
    width: 0; /* 初始进度为0 */
    height: 6px;
    background-image: linear-gradient(90deg, #9662ff 0%, #5850ff 100%); /* 进度条颜色 */
    transition: width 0.5s; /* 进度条宽度变化动画 */
    border-radius: 6px;
    position: relative;
  }
  .circle {
    width: 16px;
    height: 16px;
    background: #5850ff;
    border: 4.5px solid #ffffff;
    border-radius: 50%;
    position: absolute;
    right: -14px;
    top: -4px;
    box-sizing: border-box;
  }
  .record-info {
    width: 100%;
    float: left;
    position: relative;
    padding-right: 354px;
    box-sizing: border-box;
    height: 544px;
    margin: 20px 0;
    // display: flex;
    // align-items: center;
    .dialog {
      width: 100%;
      min-width: 588px;
      height: 544px;
      background: #f7f9fa;
      border-radius: 4px;
      overflow-y: scroll;
      padding: 20px;
      box-sizing: border-box;
      .dialog-detail {
        margin-bottom: 8px;
        text-align: left;
        .name {
          font-size: 12px;
          color: #666666;
          letter-spacing: 0;
          line-height: 16px;
          .role {
            width: 40px;
            height: 40px;
            vertical-align: top;
            margin-right: 10px;
          }
        }
        .dig-content {
          width: 404px;
          background: #ffffff;
          border-radius: 4px;
          font-size: 14px;
          color: #333333;
          padding: 10px 12px;
          white-space: pre-wrap;
          text-align: left;
          margin-left: 50px;
          margin-top: -20px;
          line-height: 20px;
        }
      }
      .nth-child {
        text-align: right;
        .dig-content {
          display: inline-block;
          background: #ebebff;
          margin-right: 56px;
        }
      }
    }
    .abstract {
      width: 334px;
      height: 544px;
      padding: 12px 20px;
      position: absolute;
      right: 0;
      top: 0;
      background-image: linear-gradient(180deg, #f6f4ff 0%, #f0f3ff 100%);
      border: 1px solid #5850ff80;
      border-radius: 4px;
      box-sizing: border-box;
      .title {
        font-weight: 700;
        font-size: 16px;
        color: #333333;
        .robot {
          width: 28px;
          height: 28px;
          margin-right: 8px;
          display: inline-block;
          vertical-align: middle;
        }
      }
      .abText {
        margin-top: 14px;
        width: 294px;
        height: 472px;
        padding: 12px;
        box-sizing: border-box;
        background: #ffffff;
        border-radius: 4px;
        overflow: scroll;
        line-height: 20px;
      }
    }
  }
}
</style>