This commit is contained in:
yanghang
2025-06-25 11:24:35 +08:00
parent 4248ed0e59
commit f9ef91e5fe
3 changed files with 58 additions and 26 deletions
+58 -26
View File
@@ -12,7 +12,7 @@
<uv-radio-group v-model="choiceTeacher">
<view class="voice-item" v-for="item in teacherList" :key="item.teacherNo" @click="choiceTeacher = item.teacherNo">
<view class="avatar-box">
<ImagePreview class="img-box" :imgId="item.imgAddr" :isCache="true" :width="480" :height="660"></ImagePreview>
<ImagePreview class="img-box" :imgId="item.imgAddr" :isCache="true" :width="120" :height="160"></ImagePreview>
</view>
<view class="right-cont">
<view class="right-name">{{item.teacherName}}</view>
@@ -79,8 +79,8 @@
</template>
<script setup>
import { reactive, ref, computed, unref, onMounted } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
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 { getToken } from '@/common/common.js'
import { get_base_url } from '@/api/request'
@@ -101,7 +101,9 @@ const getData = async () => {
step.value = 1
teacherList.value = body.teacheList
}else{
step.value = 2
choiceTeacher.value = body.choiceTeacher
initWS(2)
}
}catch{
@@ -117,37 +119,49 @@ const getData = async () => {
};
let WS = {}
const nextStep = () => {
console.log(choiceTeacher.value)
if(choiceTeacher.value){
initWS()
initWS(1)
}else{
uni.showToast({
title: '请选择一位教师!',
icon: "none",
duration
});
}
}
const initWS = async () => {
let _params = {
url: get_base_url() + '/trastudy/trasoket/open',
header:{
Summary: getToken(),
'Content-Type': 'application/json;charset=UTF-8'
},
}
console.log(_params)
const initWS = async (step) => {
WS = uni.connectSocket({
..._params,
success(res){
console.log(res)
url: get_base_url() + '/trastudy/trasoket/open?summary=' + getToken(),
header:{
'summary': getToken(),
'content-type': 'application/json;charset=UTF-8'
},
file(err){
success:function(res){
WS.onMessage = (event) => {
console.log(event)
}
let _params = step === 1 ?{
"commond" : 'open',
"body" : {
crsId: crsId.value,
teacherNo: choiceTeacher.value
}
}:{
}
WS.send(_params)
},
fail:function(err){
console.log(err)
},
complete:function(res){
console.log(res)
}
})
console.log(WS)
WS.onOpen = () =>{
console.log('建立链接')
step.value = 2
}
// WS.onmessage = (event) => {
// console.log(event)
// }
// WS.onerror = (event) => {
// console.log(event)
// }
@@ -159,7 +173,6 @@ const initWS = async () => {
onLoad((params) => {
crsId.value = params.crsId||'';
crsNum.value = params.crsNum||'';
getData();
});
const showTalkingModel = ref(false)
// 录音
@@ -179,13 +192,27 @@ const startRecord = () => {
const stopRecord = () => {
unref(recordObj).stop()
}
onMounted(()=>{
initRecord()
})
// onMounted(()=>{
// initRecord()
// })
// #endif
//#ifndef APP-PLUS
const recordObj = {}
const initRecord = () => {}
// #endif
onMounted(()=>{
getData();
initRecord?.()
})
onShow(()=>{
getData();
})
onHide(()=>{
WS.close?.()
})
onUnmounted(()=>{
WS.close?.()
})
const playRecord = () => {
audioObj.src = audioPath.value
unref(audioObj).play()
@@ -346,10 +373,15 @@ const handleMove = (obj) => {
overflow: hidden;
}
.right-desc{
width: 380rpx;
line-height: 38rpx;
font-size: 25rpx;
color: #999;
margin-bottom: 12rpx;
word-break: break-all;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.audio-box{
width: 90%;
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB