ws链接
This commit is contained in:
+58
-26
@@ -12,7 +12,7 @@
|
|||||||
<uv-radio-group v-model="choiceTeacher">
|
<uv-radio-group v-model="choiceTeacher">
|
||||||
<view class="voice-item" v-for="item in teacherList" :key="item.teacherNo" @click="choiceTeacher = item.teacherNo">
|
<view class="voice-item" v-for="item in teacherList" :key="item.teacherNo" @click="choiceTeacher = item.teacherNo">
|
||||||
<view class="avatar-box">
|
<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>
|
||||||
<view class="right-cont">
|
<view class="right-cont">
|
||||||
<view class="right-name">{{item.teacherName}}</view>
|
<view class="right-name">{{item.teacherName}}</view>
|
||||||
@@ -79,8 +79,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, ref, computed, unref, onMounted } from 'vue';
|
import { reactive, ref, computed, unref, onMounted, onUnmounted } from 'vue';
|
||||||
import { onLoad } from '@dcloudio/uni-app';
|
import { onLoad,onShow,onHide } from '@dcloudio/uni-app';
|
||||||
import { previewFile, downloadFile } from "@/api/common.js"
|
import { previewFile, downloadFile } from "@/api/common.js"
|
||||||
import { getToken } from '@/common/common.js'
|
import { getToken } from '@/common/common.js'
|
||||||
import { get_base_url } from '@/api/request'
|
import { get_base_url } from '@/api/request'
|
||||||
@@ -101,7 +101,9 @@ const getData = async () => {
|
|||||||
step.value = 1
|
step.value = 1
|
||||||
teacherList.value = body.teacheList
|
teacherList.value = body.teacheList
|
||||||
}else{
|
}else{
|
||||||
|
step.value = 2
|
||||||
choiceTeacher.value = body.choiceTeacher
|
choiceTeacher.value = body.choiceTeacher
|
||||||
|
initWS(2)
|
||||||
}
|
}
|
||||||
}catch{
|
}catch{
|
||||||
|
|
||||||
@@ -117,37 +119,49 @@ const getData = async () => {
|
|||||||
};
|
};
|
||||||
let WS = {}
|
let WS = {}
|
||||||
const nextStep = () => {
|
const nextStep = () => {
|
||||||
console.log(choiceTeacher.value)
|
|
||||||
if(choiceTeacher.value){
|
if(choiceTeacher.value){
|
||||||
initWS()
|
initWS(1)
|
||||||
|
}else{
|
||||||
|
uni.showToast({
|
||||||
|
title: '请选择一位教师!',
|
||||||
|
icon: "none",
|
||||||
|
duration
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const initWS = async () => {
|
const initWS = async (step) => {
|
||||||
let _params = {
|
|
||||||
url: get_base_url() + '/trastudy/trasoket/open',
|
|
||||||
header:{
|
|
||||||
Summary: getToken(),
|
|
||||||
'Content-Type': 'application/json;charset=UTF-8'
|
|
||||||
},
|
|
||||||
}
|
|
||||||
console.log(_params)
|
|
||||||
WS = uni.connectSocket({
|
WS = uni.connectSocket({
|
||||||
..._params,
|
url: get_base_url() + '/trastudy/trasoket/open?summary=' + getToken(),
|
||||||
success(res){
|
header:{
|
||||||
console.log(res)
|
'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)
|
console.log(err)
|
||||||
|
},
|
||||||
|
complete:function(res){
|
||||||
|
console.log(res)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log(WS)
|
|
||||||
WS.onOpen = () =>{
|
WS.onOpen = () =>{
|
||||||
console.log('建立链接')
|
console.log('建立链接')
|
||||||
step.value = 2
|
step.value = 2
|
||||||
}
|
}
|
||||||
// WS.onmessage = (event) => {
|
|
||||||
// console.log(event)
|
|
||||||
// }
|
|
||||||
// WS.onerror = (event) => {
|
// WS.onerror = (event) => {
|
||||||
// console.log(event)
|
// console.log(event)
|
||||||
// }
|
// }
|
||||||
@@ -159,7 +173,6 @@ const initWS = async () => {
|
|||||||
onLoad((params) => {
|
onLoad((params) => {
|
||||||
crsId.value = params.crsId||'';
|
crsId.value = params.crsId||'';
|
||||||
crsNum.value = params.crsNum||'';
|
crsNum.value = params.crsNum||'';
|
||||||
getData();
|
|
||||||
});
|
});
|
||||||
const showTalkingModel = ref(false)
|
const showTalkingModel = ref(false)
|
||||||
// 录音
|
// 录音
|
||||||
@@ -179,13 +192,27 @@ const startRecord = () => {
|
|||||||
const stopRecord = () => {
|
const stopRecord = () => {
|
||||||
unref(recordObj).stop()
|
unref(recordObj).stop()
|
||||||
}
|
}
|
||||||
onMounted(()=>{
|
// onMounted(()=>{
|
||||||
initRecord()
|
// initRecord()
|
||||||
})
|
// })
|
||||||
// #endif
|
// #endif
|
||||||
//#ifndef APP-PLUS
|
//#ifndef APP-PLUS
|
||||||
const recordObj = {}
|
const recordObj = {}
|
||||||
|
const initRecord = () => {}
|
||||||
// #endif
|
// #endif
|
||||||
|
onMounted(()=>{
|
||||||
|
getData();
|
||||||
|
initRecord?.()
|
||||||
|
})
|
||||||
|
onShow(()=>{
|
||||||
|
getData();
|
||||||
|
})
|
||||||
|
onHide(()=>{
|
||||||
|
WS.close?.()
|
||||||
|
})
|
||||||
|
onUnmounted(()=>{
|
||||||
|
WS.close?.()
|
||||||
|
})
|
||||||
const playRecord = () => {
|
const playRecord = () => {
|
||||||
audioObj.src = audioPath.value
|
audioObj.src = audioPath.value
|
||||||
unref(audioObj).play()
|
unref(audioObj).play()
|
||||||
@@ -346,10 +373,15 @@ const handleMove = (obj) => {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.right-desc{
|
.right-desc{
|
||||||
|
width: 380rpx;
|
||||||
line-height: 38rpx;
|
line-height: 38rpx;
|
||||||
font-size: 25rpx;
|
font-size: 25rpx;
|
||||||
color: #999;
|
color: #999;
|
||||||
margin-bottom: 12rpx;
|
margin-bottom: 12rpx;
|
||||||
|
word-break: break-all;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.audio-box{
|
.audio-box{
|
||||||
width: 90%;
|
width: 90%;
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Reference in New Issue
Block a user