ai问答完成
This commit is contained in:
@@ -5,10 +5,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// import {Marked} from 'marked';
|
||||
import MarkdownIt from 'markdown-it';
|
||||
// import markdownItAttrs from 'markdown-it-attrs'
|
||||
// import markdownItHighlight from 'markdown-it-highlightjs'
|
||||
export default {
|
||||
name:"markdown-preview",
|
||||
props: {
|
||||
@@ -49,10 +46,7 @@
|
||||
linkify: true,
|
||||
typographer: true
|
||||
})
|
||||
// this.mdObj.use(markdownItAttrs)
|
||||
// this.mdObj.use(markdownItHighlight)
|
||||
this.contentHtml = this.parseContent(this.mdString)
|
||||
console.log(this.contentHtml)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -15,9 +15,17 @@
|
||||
<view class="btns-cont">
|
||||
<view class="play-btn">
|
||||
<image class="icon"
|
||||
v-show="!isPlaying"
|
||||
@click="playVoice"
|
||||
src="@/static/images/course/play-blue.png"
|
||||
style="width: 100%;height: 100%;"
|
||||
></image>
|
||||
<image class="icon"
|
||||
v-show="isPlaying"
|
||||
@click.stop="pauseVoice"
|
||||
src="@/static/images/course/stop-blue.png"
|
||||
style="width: 100%;height: 100%;"
|
||||
></image>
|
||||
<!-- <view class="icon text-btn" v-if="type === 1" @click.stop="translateVoice(dataInfo)">文</view> -->
|
||||
</view>
|
||||
</view>
|
||||
@@ -29,17 +37,16 @@
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="talking-info talking-info-text" v-else>
|
||||
<view class="talking-cont">
|
||||
<view class="talking-text translate-text" v-if="translateLoading">
|
||||
<CommonLoading color="#fff"/>
|
||||
</view>
|
||||
<view class="talking-info talking-info-loading" v-else>
|
||||
<view :class="['talking-gif']">
|
||||
<CommonLoading color="#fff"/>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, toRefs, watch } from "vue"
|
||||
import { computed, unref, ref, toRefs, watch, onMounted } from "vue"
|
||||
import { onUnload } from '@dcloudio/uni-app';
|
||||
const props = defineProps({
|
||||
dataInfo: {
|
||||
default: () => ({}),
|
||||
@@ -51,14 +58,75 @@
|
||||
},
|
||||
})
|
||||
const { activeVoiceId, dataInfo } = toRefs(props)
|
||||
const emit = defineEmits(['changePlay'])
|
||||
watch(() => props.dataInfo, () => {},{deep: true,immediate: true})
|
||||
// 声音播放初始化
|
||||
const talkVoiceObj = ref(null)
|
||||
|
||||
const voiceLoading = ref(false)
|
||||
const translateLoading = ref(false)
|
||||
|
||||
const voiceTime = ref('')
|
||||
const itemVoice = ref('')
|
||||
const showContent = computed(()=>{
|
||||
return dataInfo.value.talkingText || ''
|
||||
})
|
||||
onMounted(()=>{
|
||||
initVoice()
|
||||
})
|
||||
onUnload(()=>{
|
||||
pauseVoice()
|
||||
})
|
||||
const pauseVoice = () => {
|
||||
if(!talkVoiceObj.value) return
|
||||
talkVoiceObj.value.pause()
|
||||
emit('changePlay', '')
|
||||
}
|
||||
const playVoice = () =>{
|
||||
emit('changePlay', unref(dataInfo)?.id)
|
||||
if(talkVoiceObj.value.src && talkVoiceObj.value.src === itemVoice.value) {
|
||||
talkVoiceObj.value.play()
|
||||
return
|
||||
}
|
||||
talkVoiceObj.value.src = ''
|
||||
if(itemVoice.value){
|
||||
setTimeout(()=>{
|
||||
talkVoiceObj.value.src = itemVoice.value
|
||||
talkVoiceObj.value.play()
|
||||
},100)
|
||||
}
|
||||
}
|
||||
const initVoice = () => {
|
||||
if(unref(dataInfo).talkingVoice){
|
||||
talkVoiceObj.value = uni.createInnerAudioContext()
|
||||
talkVoiceObj.value.onEnded(()=>{
|
||||
emit('changePlay', '')
|
||||
talkVoiceObj.value.src = ''
|
||||
})
|
||||
talkVoiceObj.value.onError(()=>{
|
||||
talkVoiceObj.value.src = ''
|
||||
})
|
||||
itemVoice.value = unref(dataInfo).talkingVoice
|
||||
talkVoiceObj.value.src = itemVoice.value
|
||||
setTimeout(()=>{
|
||||
setVoiceTime(0)
|
||||
},100)
|
||||
}
|
||||
}
|
||||
const setVoiceTime = (sum) => {
|
||||
sum += 1
|
||||
if(talkVoiceObj.value.duration){
|
||||
voiceTime.value = ( Math.ceil(talkVoiceObj.value.duration) || 0 ) + 's'
|
||||
}else{
|
||||
if(sum === 10) {
|
||||
voiceTime.value = 0 + 's'
|
||||
return
|
||||
}
|
||||
setTimeout(()=>{
|
||||
setVoiceTime(sum)
|
||||
},200)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<template>
|
||||
<view class="talking-item">
|
||||
<questionVue v-if="talkingType === 'question'" :dataInfo="talkingInfo"></questionVue>
|
||||
<questionVue
|
||||
v-if="talkingType === 'question'"
|
||||
@changePlay="changePlay"
|
||||
:dataInfo="talkingInfo"
|
||||
></questionVue>
|
||||
<answerVue
|
||||
v-else-if="talkingType === 'answer'"
|
||||
:dataInfo="props.talkingInfo"
|
||||
@@ -31,6 +35,9 @@
|
||||
const handleEvents = (type) => {
|
||||
emit('handleEvents', type, props.talkingInfo)
|
||||
}
|
||||
const changePlay = (id) => {
|
||||
emit('handleEvents', 'changePlay', props.talkingInfo, id)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style >
|
||||
|
||||
@@ -166,6 +166,7 @@ import {
|
||||
})
|
||||
unref(SocketObj).on('message', (res)=>{
|
||||
const { rtnCode, body, commond } = JSON.parse(res.data)
|
||||
let _id = new Date().getTime() + 'id'
|
||||
if(rtnCode === '0000'){
|
||||
if(commond === 'ASK-OPEN'){
|
||||
// console.log('链接成功!')
|
||||
@@ -185,12 +186,17 @@ import {
|
||||
}
|
||||
if(commond === 'ASK'){
|
||||
console.log('发送问题成功!')
|
||||
if((talkingList.value.length > 0) && talkingList.value[talkingList.value.length-1].isLoading){
|
||||
talkingList.value.pop()
|
||||
}
|
||||
seqNo.value = body.seqNo
|
||||
touchBtnCallBack.value && touchBtnCallBack.value()
|
||||
touchBtnCallBack.value = null
|
||||
talkingList.value.push({
|
||||
type: 'question',
|
||||
talkingText: body.intrctContent,
|
||||
isLoading: false,
|
||||
id: _id,
|
||||
...body
|
||||
})
|
||||
return
|
||||
@@ -204,19 +210,22 @@ import {
|
||||
return
|
||||
}
|
||||
if(commond === 'ASK-ANSWER'){
|
||||
console.log('开始回答!')
|
||||
if(body.event === 'start'){
|
||||
console.log('开始回答!')
|
||||
answerIsOver.value = false
|
||||
answerText.value = ''
|
||||
talkingList.value.push({
|
||||
type: 'answer',
|
||||
talkingText: answerText.value,
|
||||
isLoading: false,
|
||||
id: _id,
|
||||
...body
|
||||
})
|
||||
}else if(body.event === 'token'){
|
||||
answerIsOver.value = false
|
||||
answerText.value += body.data
|
||||
}else if(body.event === 'end'){
|
||||
console.log('完成回答!')
|
||||
answerIsOver.value = true
|
||||
}
|
||||
return
|
||||
@@ -236,7 +245,7 @@ import {
|
||||
}
|
||||
|
||||
if(commond === 'ASK-ERR'){
|
||||
console.log('操作异常!')
|
||||
console.log('提问失败,系统异常!')
|
||||
return
|
||||
}
|
||||
}else{
|
||||
@@ -270,7 +279,7 @@ import {
|
||||
}
|
||||
|
||||
const stopAnswerCallBack = ref(null)
|
||||
const talkItemEvents = (type, data) => {
|
||||
const talkItemEvents = (type, data, id = '') => {
|
||||
switch (type){
|
||||
case 'reAnswer':
|
||||
console.log('重新获取数据')
|
||||
@@ -302,6 +311,9 @@ import {
|
||||
}
|
||||
})
|
||||
break;
|
||||
case 'changePlay':
|
||||
console.log('播放/暂停')
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -333,7 +345,8 @@ import {
|
||||
//#ifdef APP-PLUS
|
||||
talkingList.value.push({
|
||||
type: 'question',
|
||||
talkingText: ''
|
||||
talkingText: '',
|
||||
isLoading: true
|
||||
})
|
||||
scrollToBottomNow()
|
||||
commonUploadVoiceFile(voicePath, '/traask/traAskchat/voiceTrans', {}).then(res=>{
|
||||
@@ -345,7 +358,7 @@ import {
|
||||
intrctContent: _res.body.transContent,
|
||||
bucketKey: _res.body.fileId,
|
||||
ossFileAddr: _res.body.ossFileAddr,
|
||||
voicePath: voicePath
|
||||
talkingVoice: voicePath
|
||||
}
|
||||
sendMessage({
|
||||
"commond" : 'ASK',
|
||||
@@ -401,9 +414,10 @@ import {
|
||||
})
|
||||
onShow(()=>{
|
||||
if(watchFlag.value === 1) return
|
||||
socketStore?.createSocket()
|
||||
socketStore?.createSocket?.()
|
||||
})
|
||||
onUnload(()=>{
|
||||
watchFlag.value = 1
|
||||
socketStore?.closeSocket()
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user