|
@@ -8,25 +8,27 @@
|
|
|
@click="microphone"
|
|
|
/>
|
|
|
<span v-else class="sound-item-span" @click="microphone">
|
|
|
- <SvgIcon icon-class="mic-line" :size="type === 'big' ? 24 : 16" class="record" />
|
|
|
+ <SvgIcon icon-class="mic-line" :size="iconSize" class="record" />
|
|
|
</span>
|
|
|
|
|
|
- <label v-if="type === 'big'" :class="['record-time', microphoneStatus ? 'record-ing' : '']">{{
|
|
|
- handleDateTime(recordTimes)
|
|
|
- }}</label>
|
|
|
+ <label v-if="type === 'big'" :class="['record-time', microphoneStatus ? 'record-ing' : '']">
|
|
|
+ {{ secondFormatConversion(recordTimes) }}
|
|
|
+ </label>
|
|
|
</div>
|
|
|
<div v-if="type === 'small'" class="sound-item">
|
|
|
- <label :class="['record-time', microphoneStatus ? 'record-ing' : '']">{{ handleDateTime(recordTimes) }}</label>
|
|
|
+ <label :class="['record-time', microphoneStatus ? 'record-ing' : '']">
|
|
|
+ {{ secondFormatConversion(recordTimes) }}
|
|
|
+ </label>
|
|
|
</div>
|
|
|
<div class="sound-item">
|
|
|
<span :class="['sound-item-span', wavBlob ? '' : 'not-url']" @click="playMicrophone">
|
|
|
- <SvgIcon :icon-class="iconClass" :size="type === 'big' ? 24 : 16" :class="['audio-play-btn']" />
|
|
|
+ <SvgIcon :icon-class="iconClass" :size="iconSize" :class="['audio-play-btn']" />
|
|
|
</span>
|
|
|
<label v-if="type === 'big'" class="tips">回放</label>
|
|
|
</div>
|
|
|
<div class="sound-item">
|
|
|
<span :class="['sound-item-span', wavBlob ? '' : 'not-url']" @click="delectWav">
|
|
|
- <SvgIcon icon-class="delete-back-line" :size="type === 'big' ? 24 : 16" :class="['delete-btn']" />
|
|
|
+ <SvgIcon icon-class="delete-back-line" :size="iconSize" :class="['delete-btn']" />
|
|
|
</span>
|
|
|
<label v-if="type === 'big'" class="tips">删除</label>
|
|
|
</div>
|
|
@@ -36,6 +38,9 @@
|
|
|
|
|
|
<script>
|
|
|
import Recorder from 'js-audio-recorder'; // 录音插件
|
|
|
+
|
|
|
+import { secondFormatConversion } from '@/utils/transform';
|
|
|
+
|
|
|
export default {
|
|
|
name: 'SoundRecordPreview',
|
|
|
props: {
|
|
@@ -58,6 +63,7 @@ export default {
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ secondFormatConversion,
|
|
|
recorder: new Recorder({
|
|
|
sampleBits: 16, // 采样位数,支持 8 或 16,默认是16
|
|
|
sampleRate: 16000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000
|
|
@@ -77,6 +83,9 @@ export default {
|
|
|
iconClass() {
|
|
|
return this.audio.paused ? 'play-fill' : 'pause';
|
|
|
},
|
|
|
+ iconSize() {
|
|
|
+ return this.type === 'big' ? 24 : 16;
|
|
|
+ },
|
|
|
},
|
|
|
mounted() {
|
|
|
this.$refs.audio.addEventListener('ended', () => {
|
|
@@ -120,18 +129,6 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- // 格式化录音时长
|
|
|
- handleDateTime(time) {
|
|
|
- let times = 0;
|
|
|
- if (parseInt(time / 60) < 10) {
|
|
|
- times = `${`0${parseInt(time / 60)}`.substring(`0${parseInt(time / 60)}`.length - 2)}:${`0${
|
|
|
- time % 60
|
|
|
- }`.substring(`0${time % 60}`.length - 2)}`;
|
|
|
- } else {
|
|
|
- times = `${parseInt(time / 60)}:${`0${time % 60}`.substring(`0${time % 60}`.length - 2)}`;
|
|
|
- }
|
|
|
- return times;
|
|
|
- },
|
|
|
// 开始录音
|
|
|
microphone() {
|
|
|
if (!this.audio.paused) {
|
|
@@ -150,10 +147,12 @@ export default {
|
|
|
reader.readAsDataURL(wav);
|
|
|
reader.onloadend = () => {
|
|
|
this.$emit('updateWav', reader.result, Math.floor(tolTime), this.itemIndex);
|
|
|
+ this.updateData(reader.result, Math.floor(tolTime));
|
|
|
};
|
|
|
} else {
|
|
|
this.hasMicro = '';
|
|
|
this.$emit('updateWav', '', 0, this.itemIndex);
|
|
|
+ this.updateData('', 0);
|
|
|
// 开始录音
|
|
|
this.recorder.start();
|
|
|
this.microphoneStatus = true;
|
|
@@ -173,6 +172,11 @@ export default {
|
|
|
this.recordTimes = 0;
|
|
|
clearInterval(this.timer);
|
|
|
this.$emit('deleteWav', this.itemIndex);
|
|
|
+ this.updateData('', 0);
|
|
|
+ },
|
|
|
+ updateData(wav, time) {
|
|
|
+ this.$emit('update:wavBlob', wav);
|
|
|
+ this.$emit('update:recordTime', time);
|
|
|
},
|
|
|
},
|
|
|
};
|