接口联调

This commit is contained in:
yanghang
2025-06-26 10:14:46 +08:00
parent ece5e7e1a9
commit f1bedb2340
3 changed files with 72 additions and 20 deletions
+24 -1
View File
@@ -62,7 +62,30 @@ export function downloadFile(id) {
});
});
}
// 获取音频 通用
export function downloadVoiceFile(url) {
const token = getToken();
const header = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
};
if (token)
header['summary'] = token
let baseUrl = get_base_url();
let _params = new FormData()
return new Promise((resolve, reject) => {
uni.downloadFile({
url: `${baseUrl}${url}`,
header,
success(result) {
console.log(result)
resolve(result)
},
fail(error) {
reject(new Error(error));
}
});
});
}
// 对象存储预览 /traoss/tras3/show/{文件ID}
export function previewFile(id, responseType = 'arraybuffer') {
const token = getToken();
+3 -2
View File
@@ -2,11 +2,12 @@ import request from '@/api/request'
const base_url = '/trastudy'
// 获取课程分类树接口
// 获取课程学习信息接口
export const getCourseStudyInfoApi = (data) => {
return request({
url: base_url + '/traStdyInfo/queryTraStdyProgressAndTeacher',
method: 'post',
data
});
};
};
+45 -17
View File
@@ -18,10 +18,10 @@
<view class="right-name">{{item.teacherName}}</view>
<view class="right-desc">描述{{item.voiceDesc || '--'}}</view>
<view class="audio-box">
<view class="talking-gif"></view>
<view class="play-btn">
<image class="icon" v-if="false" src="@/static/images/course/play.png" style="width: 100%;height: 100%;"></image>
<image class="icon" src="@/static/images/course/pause-focus.png" style="width: 100%;height: 100%;"></image>
<view :class="['talking-gif', activeVoiceTeachNo === item.teacherNo ? 'is-play':'']"></view>
<view class="play-btn" @click="playTeacherVoice(item)">
<image class="icon" v-if="activeVoiceTeachNo !== item.teacherNo" src="@/static/images/course/play-blue.png" style="width: 100%;height: 100%;"></image>
<image class="icon" v-else src="@/static/images/course/stop-blue.png" style="width: 100%;height: 100%;"></image>
</view>
<!-- <view class="talking-time">00:26</view> -->
</view>
@@ -81,7 +81,7 @@
<script setup>
import { reactive, ref, computed, unref, onMounted, onUnmounted } from 'vue';
import { onLoad,onShow,onHide } from '@dcloudio/uni-app';
import { previewFile, downloadFile } from "@/api/common.js"
import { previewFile, downloadFile, downloadVoiceFile } from "@/api/common.js"
import { getToken } from '@/common/common.js'
import { get_base_url } from '@/api/request'
import { getCourseStudyInfoApi } from "@/api/study.js"
@@ -99,7 +99,11 @@ const getData = async () => {
const { body } = await getCourseStudyInfoApi({crsId: crsId.value})
if(body.stdyProgressFlag === 'N'){
step.value = 1
teacherList.value = body.teacheList
teacherList.value = body.teacheList.map(t=>({
...t,
voicePath: '',
voiceObj: null
}))
}else{
step.value = 2
choiceTeacher.value = body.choiceTeacher
@@ -108,24 +112,47 @@ const getData = async () => {
}catch{
}
// downloadFile('S3F0250181220722025062409312400000331622').then(res=>{
// console.log(res)
// audioObj.value = uni.createInnerAudioContext()
// audioObj.value.src = res.tempFilePath
// })
// downloadFile('S3F0250640161332025061618052000000267276').then(res=>{
// videoUrlShow.value = res.tempFilePath
// })
};
const activeVoiceTeachNo = ref('')
const teacherVoiceObj = uni.createInnerAudioContext()
teacherVoiceObj.onEnded(()=>{
activeVoiceTeachNo.value = ''
teacherVoiceObj.src = ''
})
const playTeacherVoice = (item) =>{
teacherVoiceObj.stop()
teacherVoiceObj.src = ''
let _isStop = item.teacherNo === activeVoiceTeachNo.value
activeVoiceTeachNo.value = _isStop ? '' : item.teacherNo
if(_isStop) return
if(item.voicePath){
teacherVoiceObj.src = item.voicePath
teacherVoiceObj.play()
}else{
downloadVoiceFile('/trastudy/traStdyInfo/trialListening?teachNo='+item.teacherNo).then(res=>{
// item.voiceObj = uni.createInnerAudioContext()
console.log(res)
item.voicePath = res.tempFilePath
teacherVoiceObj.src = item.voicePath
teacherVoiceObj.play()
// item.voiceObj.src = res.tempFilePath
// item.voiceObj.play()
})
}
}
var WS = null
const nextStep = () => {
if(choiceTeacher.value){
initWS(1)
teacherVoiceObj.destroy()
}else{
uni.showToast({
title: '请选择一位教师!',
icon: "none",
duration
duration:1000
});
}
}
@@ -135,13 +162,14 @@ const isManualClose = false // 是否手动关闭
const initWS = ($step) => {
WS = uni.connectSocket({
url: get_base_url() + '/trastudy/trasoket/open?summary=' + getToken(),
complete: function(cv){
console.log(cv)
}
complete: function(){}
})
WS.onMessage = (event) => {
console.log(event,111)
}
WS.onmessage = (event) => {
console.log(event,121)
}
WS.onSocketMessage = (event) => {
console.log(event,222)
}
@@ -156,7 +184,6 @@ const initWS = ($step) => {
// // initWS()
// }
setTimeout(()=>{
console.log(WS , WS.readyState)
if( WS && WS.readyState === 1){
let _params = $step === 1 ?{
"commond" : 'open',
@@ -168,6 +195,7 @@ const initWS = ($step) => {
sendMessage(_params)
step.value = 2
}
WS.close()
},100)
}
const reconnect = ()=> {
@@ -221,7 +249,7 @@ const recordObj = {}
const initRecord = () => {}
// #endif
onMounted(()=>{
getData();
// getData();
initRecord?.()
})
onShow(()=>{