UnisKB/ui/src/components/ai-chat/LogOperationButton.vue

140 lines
4.2 KiB
Vue
Raw Normal View History

2023-12-07 11:28:38 +00:00
<template>
2023-12-12 09:07:34 +00:00
<div>
<el-text type="info">
<span class="ml-4">{{ datetimeFormat(data.create_time) }}</span>
</el-text>
</div>
2023-12-07 11:28:38 +00:00
<div>
2024-09-13 07:47:05 +00:00
<!-- 语音播放 -->
<span v-if="tts">
<el-tooltip effect="dark" content="语音播放" placement="top">
<el-button text @click="playAnswerText(data?.answer_text)">
<AppIcon iconName="app-video-play"></AppIcon>
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
</span>
2023-12-14 03:33:35 +00:00
<el-tooltip effect="dark" content="复制" placement="top">
<el-button text @click="copyClick(data?.answer_text)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
2023-12-14 10:00:01 +00:00
<el-tooltip
v-if="data.improve_paragraph_id_list.length === 0"
effect="dark"
content="修改内容"
placement="top"
>
2023-12-07 11:28:38 +00:00
<el-button text @click="editContent(data)">
<el-icon><EditPen /></el-icon>
</el-button>
</el-tooltip>
2023-12-14 08:24:10 +00:00
2023-12-14 10:00:01 +00:00
<el-tooltip v-else effect="dark" content="修改标注" placement="top">
2023-12-15 03:04:10 +00:00
<el-button text @click="editMark(data)">
2023-12-14 10:00:01 +00:00
<AppIcon iconName="app-document-active" class="primary"></AppIcon>
</el-button>
</el-tooltip>
2023-12-07 11:28:38 +00:00
<el-divider direction="vertical" v-if="buttonData?.vote_status !== '-1'" />
2023-12-14 10:00:01 +00:00
<el-button text disabled v-if="buttonData?.vote_status === '0'">
2023-12-14 08:24:10 +00:00
<AppIcon iconName="app-like-color"></AppIcon>
2023-12-07 11:28:38 +00:00
</el-button>
<el-button text disabled v-if="buttonData?.vote_status === '1'">
<AppIcon iconName="app-oppose-color"></AppIcon>
</el-button>
2023-12-27 07:31:20 +00:00
<EditContentDialog ref="EditContentDialogRef" @refresh="refreshContent" />
<EditMarkDialog ref="EditMarkDialogRef" @refresh="refreshMark" />
2024-09-13 07:47:05 +00:00
<!-- 先渲染不然不能播放 -->
<audio ref="audioPlayer" controls hidden="hidden"></audio>
2023-12-07 11:28:38 +00:00
</div>
</template>
<script setup lang="ts">
2024-05-20 09:50:14 +00:00
import { ref } from 'vue'
2023-12-07 11:28:38 +00:00
import { copyClick } from '@/utils/clipboard'
import EditContentDialog from '@/views/log/component/EditContentDialog.vue'
2023-12-15 03:04:10 +00:00
import EditMarkDialog from '@/views/log/component/EditMarkDialog.vue'
2023-12-12 09:07:34 +00:00
import { datetimeFormat } from '@/utils/time'
2024-09-13 07:47:05 +00:00
import applicationApi from '@/api/application'
2023-12-07 11:28:38 +00:00
const props = defineProps({
data: {
type: Object,
default: () => {}
},
applicationId: {
type: String,
default: ''
},
2024-09-13 07:47:05 +00:00
tts: Boolean
2023-12-07 11:28:38 +00:00
})
const emit = defineEmits(['update:data'])
2024-09-13 07:47:05 +00:00
const audioPlayer = ref<HTMLAudioElement | null>(null)
2023-12-07 11:28:38 +00:00
const EditContentDialogRef = ref()
2023-12-15 03:04:10 +00:00
const EditMarkDialogRef = ref()
2023-12-07 11:28:38 +00:00
const buttonData = ref(props.data)
2024-09-13 07:47:05 +00:00
const loading = ref(false)
2023-12-07 11:28:38 +00:00
function editContent(data: any) {
EditContentDialogRef.value.open(data)
}
2023-12-15 03:04:10 +00:00
function editMark(data: any) {
EditMarkDialogRef.value.open(data)
}
2024-09-13 07:47:05 +00:00
const playAnswerText = (text: string) => {
if (props.data.tts_type === 'BROWSER') {
// 创建一个新的 SpeechSynthesisUtterance 实例
const utterance = new SpeechSynthesisUtterance(text)
// 调用浏览器的朗读功能
window.speechSynthesis.speak(utterance)
}
if (props.data.tts_type === 'TTS') {
applicationApi
.postTextToSpeech(props.data.id as string, { text: text }, loading)
.then((res: any) => {
// 假设我们有一个 MP3 文件的字节数组
// 创建 Blob 对象
const blob = new Blob([res], { type: 'audio/mp3' })
// 创建对象 URL
const url = URL.createObjectURL(blob)
// 测试blob是否能正常播放
// const link = document.createElement('a')
// link.href = window.URL.createObjectURL(blob)
// link.download = "abc.mp3"
// link.click()
// 检查 audioPlayer 是否已经引用了 DOM 元素
if (audioPlayer.value instanceof HTMLAudioElement) {
audioPlayer.value.src = url
audioPlayer.value.play() // 自动播放音频
} else {
console.error('audioPlayer.value is not an instance of HTMLAudioElement')
}
})
.catch((err) => {
console.log('err: ', err)
})
}
}
2023-12-27 07:31:20 +00:00
function refreshMark() {
2023-12-15 03:04:10 +00:00
buttonData.value.improve_paragraph_id_list = []
emit('update:data', buttonData.value)
}
2023-12-27 07:31:20 +00:00
function refreshContent(data: any) {
buttonData.value = data
emit('update:data', buttonData.value)
}
2023-12-07 11:28:38 +00:00
</script>
<style lang="scss" scoped></style>