This commit is contained in:
许允枞 2025-03-12 18:08:19 +08:00
parent 07c0ee4030
commit 5614e9859b
2 changed files with 54 additions and 19 deletions

View File

@ -39,10 +39,10 @@
<text>{{ item.query }}</text> <text>{{ item.query }}</text>
</view> </view>
</view> </view>
<view class="message" v-if="item.inputs.type == 'image'"> <view class="message" v-if="item.inputs.type == 'image'" @click="previewImage(item.query)">
<image :src="'data:image/png;base64,'+item.query" class="msg-img" mode="widthFix"></image> <image :src="'data:image/png;base64,'+item.query" class="msg-img" mode="widthFix"></image>
</view> </view>
<view class="message" v-if="item.inputs.type == 'voice'" @tap="playVoice(item.filePath)"> <view class="message" v-if="item.inputs.type == 'voice'" @tap="playVoice(item.url)">
<!-- 音频 --> <!-- 音频 -->
<view class="msg-text voice" :style="{width:item.time*4+'rpx'}"> <view class="msg-text voice" :style="{width:item.time*4+'rpx'}">
<image src="/static/chat/sy.png" class="voice-img"></image> <image src="/static/chat/sy.png" class="voice-img"></image>
@ -62,7 +62,7 @@
<view class="po_i" v-if="!item.showImage&&clickIdx==index"> <view class="po_i" v-if="!item.showImage&&clickIdx==index">
<view class="size_" @click="showImageFunction (item)">image</view> <view class="size_" @click="showImageFunction (item)">image</view>
</view> </view>
<image :src="'data:image/png;base64,'+item.answer" v-if="item.showImage" class="msg-img" <image :src="'data:image/png;base64,'+item.answer" @click="previewImage(item.answer)" v-if="item.showImage" class="msg-img"
mode="widthFix"></image> mode="widthFix"></image>
<text v-else>{{ item.imageText }}</text> <text v-else>{{ item.imageText }}</text>
</view> </view>
@ -103,6 +103,7 @@ import {
import requestChat from '../../utils/requestChat' import requestChat from '../../utils/requestChat'
import permision from "@/js_sdk/wa-permission/permission.js" import permision from "@/js_sdk/wa-permission/permission.js"
import request from '../../utils/request' import request from '../../utils/request'
import {base64ToPath} from "image-tools";
// //
const innerAudioContext = uni.createInnerAudioContext(); const innerAudioContext = uni.createInnerAudioContext();
// //
@ -250,6 +251,7 @@ export default {
this.userId = infoData.userId this.userId = infoData.userId
this.userAvatar = infoData.userAvatar this.userAvatar = infoData.userAvatar
this.getMessageByStore() this.getMessageByStore()
this.goBottom()
} }
this.getRecordsToken() this.getRecordsToken()
@ -259,7 +261,6 @@ export default {
}, },
methods: { methods: {
async voiceTxt(item) { async voiceTxt(item) {
console.log('执行了')
let res = await request({ let res = await request({
url: 'youDaoApi/tts', url: 'youDaoApi/tts',
method: 'post', method: 'post',
@ -269,10 +270,28 @@ export default {
language: item.lang language: item.lang
} }
}) })
console.log('语音合成', res)
this.playBase64Mp3(res.data) this.playBase64Mp3(res.data)
this.show = false this.show = false
},
//
previewImage(photoImg) {
console.log('预览图片')
photoImg = 'data:image/jpeg;base64,' + photoImg;
base64ToPath(photoImg).then((resInfo)=>{
uni.getImageInfo({
src: resInfo,
success: function(res){
uni.previewImage({
urls:[res.path]
});
},
fail: function(err){
console.log(err)
}
})
}).catch((err)=>{
console.log(err)
})
}, },
showTxt(item) { showTxt(item) {
item.showImage = false item.showImage = false
@ -363,8 +382,6 @@ export default {
strStatus = "被永久拒绝权限" strStatus = "被永久拒绝权限"
} }
}, },
startSocket() { startSocket() {
this.socketId = this.userId + "_" + Date.now() this.socketId = this.userId + "_" + Date.now()
@ -538,12 +555,19 @@ export default {
// //
playVoice(e) { playVoice(e) {
let innerAudioContext1 = uni.createInnerAudioContext(); console.log('地址',e)
innerAudioContext1.autoplay = true; // let innerAudioContext1 = uni.createInnerAudioContext();
innerAudioContext1.src = 'data:audio/mp3;base64,'+e.replace(/[\r\n]/g, ""); // innerAudioContext1.autoplay = true;
innerAudioContext1.onPlay(() => { // innerAudioContext1.playbackRate = 0.5;
console.log('开始播放'); innerAudioContext.src = this.imagesUrl + e;
}); console.log(innerAudioContext.src)
innerAudioContext.play()
// innerAudioContext.onPlay(() => {
// console.log('');
// });
// innerAudioContext.onError((err) => {
// console.log(':', err);
// });
// console.log('') // console.log('')
// innerAudioContext.src = `data:audio/mp3;base64,${e}`; // innerAudioContext.src = `data:audio/mp3;base64,${e}`;
@ -614,6 +638,7 @@ export default {
'filePath': inputData.filePath, 'filePath': inputData.filePath,
"lang": this.lang, "lang": this.lang,
'isTrans':true, 'isTrans':true,
'url': inputData.url
}; };
if (this.info.conversation == 'Translator') { if (this.info.conversation == 'Translator') {
msgItem.response_mode = 'blocking' msgItem.response_mode = 'blocking'
@ -685,6 +710,7 @@ export default {
}, },
// //
goBottom() { goBottom() {
// this.scrollToBottom()
this.scrollToView = ''; this.scrollToView = '';
this.$nextTick(() => { this.$nextTick(() => {
@ -692,7 +718,15 @@ export default {
this.scrollToView = this.scrollId; this.scrollToView = this.scrollId;
this.$forceUpdate() this.$forceUpdate()
}) })
} },
//
scrollToBottom() {
this.$nextTick(() => {
setTimeout(() => {
this.scrollTop = 999999; //
}, 50); // DOM
});
},
} }
} }
</script> </script>

View File

@ -237,7 +237,7 @@ export default {
base64: res1.base64 base64: res1.base64
} }
}).then(res2 => { }).then(res2 => {
that.send(json.id, 1, res1.base64) that.send(json.id, 1, res1.base64,null,res1.url)
}) })
}) })
// that.send(json.id, 1, res.data) // that.send(json.id, 1, res.data)
@ -347,7 +347,7 @@ export default {
type: 2 type: 2
} }
}).then(ress => { }).then(ress => {
that.send(ress.data, 2, res.base64, that.vlength, res.base64) that.send(ress.data, 2, res.base64, that.vlength, res.url)
this.vlength = 0; this.vlength = 0;
}) })
}).catch(error => { }).catch(error => {
@ -375,13 +375,14 @@ export default {
}); });
}, },
// //
send(msg, type, base64, time) { send(msg, type, base64, time,url) {
let date = { let date = {
message: msg, message: msg,
type: type, type: type,
base64: base64, base64: base64,
time: time, time: time,
filePath: base64 filePath: base64,
url:url
} }
this.$emit('inputs', date); this.$emit('inputs', date);
setTimeout(() => { setTimeout(() => {