|
@@ -106,7 +106,6 @@
|
|
|
:value="currentAudioMsg.audioCurrentTime"
|
|
|
:max="currentAudioMsg.audioTime"
|
|
|
@change="sliderChange($event)"
|
|
|
- @changing="sliderChanging($event)"
|
|
|
activeColor="#E6B77DFF"
|
|
|
backgroundColor="#EBEBEBFF"
|
|
|
block-color="#E6B77DFF"
|
|
@@ -114,10 +113,12 @@
|
|
|
/>
|
|
|
<view class="slider-time">
|
|
|
<text>{{
|
|
|
- moment(currentAudioMsg.audioCurrentTime).format("mm:ss")
|
|
|
+ moment(currentAudioMsg.audioCurrentTime * 1000).format(
|
|
|
+ "mm:ss"
|
|
|
+ )
|
|
|
}}</text>
|
|
|
<text>{{
|
|
|
- moment(currentAudioMsg.audioTime).format("mm:ss")
|
|
|
+ moment(currentAudioMsg.audioTime * 1000).format("mm:ss")
|
|
|
}}</text>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -135,7 +136,8 @@
|
|
|
|
|
|
<script>
|
|
|
import mixin from "../mixin/questionMixin";
|
|
|
-import { apiUploadAudio } from "@/api/question";
|
|
|
+import { apiReplayAsk } from "@/api/question";
|
|
|
+import { uploadToServer, uploadAudioToServer } from "@/utils/upload";
|
|
|
export default {
|
|
|
mixins: [mixin],
|
|
|
data() {
|
|
@@ -155,7 +157,7 @@ export default {
|
|
|
loading: false,
|
|
|
reply_status: 2,
|
|
|
chart_permission_name: "苯乙烯",
|
|
|
- recordStatus: 4, //1:未录音;2:正在录音;3:已暂停;4:完成录音
|
|
|
+ recordStatus: 1, //1:未录音;2:正在录音;3:已暂停;4:完成录音
|
|
|
},
|
|
|
pauseImgSrc: "../static/question/recordplay.png",
|
|
|
playImgSrc: "../static/question/recordpause.png",
|
|
@@ -170,9 +172,9 @@ export default {
|
|
|
isplay: false,
|
|
|
};
|
|
|
},
|
|
|
- onLoad() {
|
|
|
+ onLoad(options) {
|
|
|
this.initAudio();
|
|
|
- this.uploadAudio();
|
|
|
+ //this.getQuestionItem(options.id)
|
|
|
},
|
|
|
methods: {
|
|
|
//初始化audio
|
|
@@ -184,22 +186,24 @@ export default {
|
|
|
//audio事件
|
|
|
handleAudioFun() {
|
|
|
this.innerAudio.onPlay(() => {
|
|
|
+ this.isplay = true;
|
|
|
console.log("播放录音了");
|
|
|
this.questionItem.loading = false;
|
|
|
});
|
|
|
this.innerAudio.onTimeUpdate(() => {
|
|
|
+ console.log("时间更新", this.innerAudio.currentTime);
|
|
|
this.currentAudioMsg.audioCurrentTime = parseInt(
|
|
|
- this.innerAudio.currentTime * 1000
|
|
|
+ this.innerAudio.currentTime
|
|
|
);
|
|
|
});
|
|
|
this.innerAudio.onSeeked(() => {
|
|
|
//取this.innerAudio.currentTime为0
|
|
|
- if (this.isPlayed) {
|
|
|
- this.innerAudio.play();
|
|
|
- }
|
|
|
+ console.log("seek完成");
|
|
|
});
|
|
|
this.innerAudio.onPause(() => {
|
|
|
+ this.isplay = false;
|
|
|
console.log("暂停");
|
|
|
+ console.log(this.innerAudio.paused);
|
|
|
});
|
|
|
this.innerAudio.onEnded(() => {
|
|
|
console.log("音频播放完毕");
|
|
@@ -228,8 +232,16 @@ export default {
|
|
|
console.log("res", JSON.stringify(res));
|
|
|
//this.innerAudio.src = res.tempFilePath;
|
|
|
this.cleanTime();
|
|
|
- //上传录制音频
|
|
|
- this.uploadAudio();
|
|
|
+ //初始化音频播放
|
|
|
+ this.innerAudio.src = res.tempFilePath;
|
|
|
+ this.changeCurrentAudio({
|
|
|
+ id: "",
|
|
|
+ answer: {
|
|
|
+ source: res.tempFilePath,
|
|
|
+ audioTime: res.duration / 1000,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ this.pageLoading = false;
|
|
|
});
|
|
|
this.globalRecorder.onError((res) => {
|
|
|
console.log("err", res);
|
|
@@ -263,47 +275,42 @@ export default {
|
|
|
},
|
|
|
//上传音频
|
|
|
async uploadAudio() {
|
|
|
- /* const res = await apiUploadAudio({
|
|
|
- file: this.innerAudio.src,
|
|
|
- }); */
|
|
|
- /* if (res.code === 200) {
|
|
|
+ const res = await uploadAudioToServer(this.innerAudio.src)
|
|
|
+ if (res.code === 200) {
|
|
|
this.audioItem = res.data;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//重新录
|
|
|
- this.questionItem.recordStatus=1
|
|
|
- } */
|
|
|
- //mock上传的结果
|
|
|
- this.audioItem = {
|
|
|
- audio_url:
|
|
|
- "https://hzstatic.hzinsights.com/static/yb_wx/community_question_audio/ctlwQOKUPTtQ43cLjx8khCmjPqkV.mp3", //音频地址
|
|
|
- audio_play_seconds: "492", //音频时长,单位s
|
|
|
- audio_size: "2.82", //音频大小,单位MB
|
|
|
- };
|
|
|
- this.changeCurrentAudio({
|
|
|
- id: "",
|
|
|
- answer: {
|
|
|
- source: this.audioItem.audio_url,
|
|
|
- audioTime: parseInt(this.audioItem.audio_play_seconds) * 1000,
|
|
|
- },
|
|
|
- });
|
|
|
- this.innerAudio.src = this.audioItem.audio_url;
|
|
|
- this.pageLoading = false;
|
|
|
+ this.questionItem.recordStatus = 1;
|
|
|
+ this.audioCount = 0;
|
|
|
+ this.audioTime = this.moment(this.audioCount * 1000).format("mm:ss");
|
|
|
+ }
|
|
|
},
|
|
|
- handleRecode(type) {
|
|
|
+ async handleRecode(type) {
|
|
|
this.questionItem.recordStatus = 4;
|
|
|
this.changeRecodeStatus();
|
|
|
if (type === "finish") {
|
|
|
//生成音频,更改页面布局
|
|
|
- //console.log("aaa");
|
|
|
this.pageLoading = true;
|
|
|
- //this.handleAudioPlay();
|
|
|
- } else if(type==='delete'){
|
|
|
+ } else if (type === "delete") {
|
|
|
+ //重新录
|
|
|
this.questionItem.recordStatus = 1;
|
|
|
this.audioCount = 0;
|
|
|
this.audioTime = this.moment(this.audioCount * 1000).format("mm:ss");
|
|
|
- }else{
|
|
|
- //关闭当前页面,跳转到我的回答
|
|
|
- uni.navigateBack({ delta: 1 })
|
|
|
+ } else {
|
|
|
+ //发布
|
|
|
+ await this.uploadAudio();
|
|
|
+ //如果上传音频成功
|
|
|
+ if (this.questionItem.recordStatus === 4) {
|
|
|
+ //发布回答
|
|
|
+ const res = await apiReplayAsk({
|
|
|
+ question_id: 5,
|
|
|
+ audio_list: [{...this.audioItem,sort:1}],
|
|
|
+ });
|
|
|
+ if (res.code === 200) {
|
|
|
+ //关闭当前页面,跳转到我的回答
|
|
|
+ uni.navigateBack({ delta: 1 });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
//(提问者)问题已被回答,点击回答音频
|
|
@@ -331,26 +338,22 @@ export default {
|
|
|
},
|
|
|
//(回答者)问题被回答,点击回答音频
|
|
|
handleAudioByReplay() {
|
|
|
- this.isPlayed = true;
|
|
|
+ this.isplay = !this.isplay;
|
|
|
if (this.innerAudio.paused) {
|
|
|
this.innerAudio.play();
|
|
|
- this.isplay = true;
|
|
|
} else {
|
|
|
this.innerAudio.pause();
|
|
|
- this.isplay = false;
|
|
|
}
|
|
|
this.playIconKey++;
|
|
|
},
|
|
|
//拖动音频进度条
|
|
|
sliderChange(e) {
|
|
|
+ console.log("拖动完成?");
|
|
|
+ //this.innerAudio.pause();
|
|
|
const value = e.detail.value;
|
|
|
- this.innerAudio.seek(value / 1000);
|
|
|
+ this.innerAudio.seek(value);
|
|
|
this.currentAudioMsg.audioCurrentTime = value;
|
|
|
},
|
|
|
- sliderChanging(e) {
|
|
|
- //拖动时先暂停播放
|
|
|
- this.innerAudio.pause();
|
|
|
- },
|
|
|
//切换当前播放音频
|
|
|
changeCurrentAudio(item) {
|
|
|
const { id } = item;
|
|
@@ -365,6 +368,7 @@ export default {
|
|
|
this.questionItem.loading = true;
|
|
|
}
|
|
|
},
|
|
|
+ //录音计时
|
|
|
clockTime() {
|
|
|
console.log("开始计时");
|
|
|
this.timer = setInterval(() => {
|
|
@@ -374,6 +378,7 @@ export default {
|
|
|
}
|
|
|
}, 1000);
|
|
|
},
|
|
|
+ //清除录音计时
|
|
|
cleanTime() {
|
|
|
this.timer = null;
|
|
|
this.audioTime = this.moment(this.audioCount * 1000).format("mm:ss");
|