diff --git a/src/api/common.js b/src/api/common.js
index 61154a68..7b3a4a92 100644
--- a/src/api/common.js
+++ b/src/api/common.js
@@ -157,6 +157,38 @@ export function downloadVoiceFile(url) {
});
});
}
+
+
+export function getAudioByText(data) {
+ 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();
+
+ return new Promise((resolve, reject) => {
+ uni.request({
+ url: `${baseUrl}/trastudy/traStdyInfo/readContent`,
+ header,
+ method:"POST",
+ data,
+ responseType: "arraybuffer",
+ success(result) {
+ if(result.statusCode === 200){
+ resolve(result.data)
+ }else{
+ reject(new Error(result))
+ }
+ },
+ fail(error) {
+ reject(new Error(error));
+ }
+ });
+ });
+}
+
// 对象存储预览 /traoss/tras3/show/{文件ID}
export function previewFile(id, responseType = 'arraybuffer') {
const token = getToken();
diff --git a/src/api/socket.js b/src/api/socket.js
index 454df64a..40957666 100644
--- a/src/api/socket.js
+++ b/src/api/socket.js
@@ -155,6 +155,9 @@ export default class WebSocketUtil {
} else {
console.error('WebSocket连接未打开,无法发送消息');
this.triggerEvent('error', new Error('WebSocket连接未打开'));
+ setTimeout(()=>{
+ this.send(message)
+ },500)
}
return this;
}
diff --git a/src/pages/course/components/chartFour.vue b/src/pages/course/components/chartFour.vue
index 2c930ba6..17d70295 100644
--- a/src/pages/course/components/chartFour.vue
+++ b/src/pages/course/components/chartFour.vue
@@ -14,7 +14,7 @@
{{props.score}}分
-
+
{{ item.gradeDimensName }}
diff --git a/src/pages/course/components/chartThree.vue b/src/pages/course/components/chartThree.vue
index d5889b59..44e0160a 100644
--- a/src/pages/course/components/chartThree.vue
+++ b/src/pages/course/components/chartThree.vue
@@ -17,7 +17,7 @@
{{props.score}}分
-
+
{{ item.gradeDimensName }}
diff --git a/src/pages/course/components/talkingItem.vue b/src/pages/course/components/talkingItem.vue
index b2d61564..edc1b881 100644
--- a/src/pages/course/components/talkingItem.vue
+++ b/src/pages/course/components/talkingItem.vue
@@ -185,7 +185,7 @@
import { watch, unref, ref, toRefs, computed, nextTick,onMounted } from 'vue'
import ImagePreview from '@/components/image-preview/image-preview.vue'
import VideoPreview from '@/components/image-preview/video-preview.vue'
-import { downloadVoiceFile, uploadVoiceFile, } from "@/api/common.js"
+import { downloadVoiceFile, uploadVoiceFile, getAudioByText } from "@/api/common.js"
import { studyParagraphOverApi, getAskAboutRawApi } from "@/api/study.js"
import ChartFour from "./chartFour.vue"
import ChartThree from "./chartThree.vue"
@@ -373,6 +373,8 @@ const audioCacheObj = computed(() => storageStore.audioObj)
teachNo: unref(teacherInfo)?.teacherNo, // 必填
content: _content
}
+
+
let _url = '/trastudy/traStdyInfo/readContent?' + Object.keys(_params).map(t=>{
return encodeURIComponent(t) + '=' + encodeURIComponent(_params[t])
}).join('&')
@@ -384,6 +386,19 @@ const audioCacheObj = computed(() => storageStore.audioObj)
talkVoiceObj.value.src = url
talkVoiceObj.value.play()
}else{
+ // getAudioByText(_params).then(res=>{
+ // // uni.env.USER_DATA_PATH ||
+ // let filePath = `${'/'}/${dataInfo.value.id}.mp3`
+ // saveFile(res, filePath, () => {
+ // voiceLoading.value = false
+ // itemVoice.value = filePath
+ // talkVoiceObj.value.src = filePath
+ // talkVoiceObj.value.play()
+ // storageStore.setStorage('audio', _url + _params.teachNo, itemVoice.value)
+ // })
+ // }).catch(err=>{
+ // console.log(err)
+ // })
downloadVoiceFile(_url).then(res=>{
if(res?.data){
common.msg(res.data.message)
@@ -401,6 +416,19 @@ const audioCacheObj = computed(() => storageStore.audioObj)
})
}
}
+ const saveFile = (buffer,filePath, cb = ()=>{}) => {
+ let fileManager = uni.getFileSystemManager()
+ fileManager.writeFile({
+ filePath: filePath,
+ data: buffer,
+ encoding: 'binary',
+ success: cb,
+ file: ()=>{
+ voiceLoading.value = false
+ console.log('文件保存失败!')
+ }
+ })
+ }
const initVoice = (readType = 'qns', item, isplay=false) => {
if(unref(dataInfo).talkingVoice){
itemVoice.value = unref(dataInfo).talkingVoice
diff --git a/src/pages/course/study.vue b/src/pages/course/study.vue
index 7ae7e1d7..dfe9dd51 100644
--- a/src/pages/course/study.vue
+++ b/src/pages/course/study.vue
@@ -176,13 +176,8 @@ const flagVal = ref('1')
const isUploadingVoice = ref(false)
// 初始化数据
const getData = async (flag) => {
- // if(flag === flagVal.value){
- // flagVal.value = '2'
- // }else{
- // return
- // }
try{
- await initsocketTask()
+ initsocketTask()
const { body } = await getCourseStudyInfoApi({crsId: crsId.value})
teacherList.value = body.teacheList.map(t=>({
...t,
@@ -192,8 +187,8 @@ const getData = async (flag) => {
if(body.stdyProgressFlag === 'N'){
step.value = 1
}else{
+ choiceTeacher.value = body.choiceTeacher
if(startPgrphId.value){
- choiceTeacher.value = body.choiceTeacher
sendMessage({
"commond" : 'STDY',
"body" : {
@@ -201,7 +196,6 @@ const getData = async (flag) => {
teacherNo: choiceTeacher.value
}
})
- step.value = 2
return
}
common.show('提示', '系统检测到您已存在学习记录,要继续学习吗?',true, '重新学习','继续学习').then((res) => {
@@ -209,7 +203,6 @@ const getData = async (flag) => {
// 继续学习 , 获取学习历史接口
// 滚动到最下面
scrollToBottomNow()
- choiceTeacher.value = body.choiceTeacher
sendMessage({
"commond" : 'STDY',
"body" : {
@@ -374,7 +367,6 @@ const getGraphInfoUnStudy = (flag = 0) => {
if(!_body.chatBody) {
return
}
- console.log('prgh', _body)
if(Number(_body.bodyTyp) === 7){
common.show('恭喜你已学完全部知识点', '有什么心得跟我们分享吗?',true, '取消','去评论').then((res) => {
if(res) {
@@ -587,8 +579,20 @@ const stdyId = ref('')
const stdyBatch = ref('')
const logId = ref('')
// ws 初始化逻辑
-const initsocketTask = async () => {
- await socketStore.creatSocket()
+const initsocketTask = () => {
+ socketStore.creatSocket()
+ unref(SocketObj).on('open', (res)=>{
+ if(startPgrphId.value){
+ sendMessage({
+ "commond" : 'STDY',
+ "body" : {
+ crsId: crsId.value,
+ teacherNo: choiceTeacher.value
+ }
+ })
+ step.value = 2
+ }
+ })
unref(SocketObj).on('message', (res)=>{
const { rtnCode, body, commond } = JSON.parse(res.data)
if(rtnCode === '0000'){
@@ -597,6 +601,7 @@ const initsocketTask = async () => {
stdyBatch.value = body.stdyBatch || ''
logId.value = body.logId || ''
getGraphInfoUnStudy(1)
+ step.value = 2
}
}else{
// if(['0005', 'QQ0005'].includes(res.rtnCode)) {
@@ -622,13 +627,14 @@ onLoad((params) => {
crsNum.value = params.crsNum||'';
imageId.value = params.imgId || ''
startPgrphId.value = params.pgrphId||'';
- getData('1');
+ console.log('onLoad')
});
const showTalkingModel = ref(false)
// 录音
-// onMounted(()=>{
-// getData('1');
-// })
+onMounted(()=>{
+ getData('1');
+ console.log('onMounted')
+})
onHide(()=>{
if(watchFlag.value === 1) return
changePlayItemId('')
@@ -638,8 +644,9 @@ onHide(()=>{
}).finally(() => {})
})
onShow(()=>{
+ console.log('onShow')
if(watchFlag.value === 1) return
- socketStore.createSocket()
+ getData('1');
})
const watchFlag = ref(1)
onUnload(()=>{
diff --git a/src/pages/index/dialog.vue b/src/pages/index/dialog.vue
index f1562bdd..a1f5b782 100644
--- a/src/pages/index/dialog.vue
+++ b/src/pages/index/dialog.vue
@@ -415,6 +415,13 @@ import {
onShow(()=>{
if(watchFlag.value === 1) return
socketStore?.createSocket?.()
+ sendMessage({
+ "commond" : 'ASK-START',
+ "body" : {
+ mascotId: mascotId.value,
+ deviceImei: ''
+ }
+ })
})
onUnload(()=>{
watchFlag.value = 1