fix: 修复前端没有input_field_list报错

This commit is contained in:
shaohuzhang1 2024-09-12 11:02:03 +08:00 committed by shaohuzhang1
parent 746f587698
commit 24291493d6

View File

@ -118,13 +118,11 @@
v-if="item.is_stop && !item.write_ed" v-if="item.is_stop && !item.write_ed"
@click="startChat(item)" @click="startChat(item)"
link link
>继续 >继续
</el-button </el-button>
>
<el-button type="primary" v-else-if="!item.write_ed" @click="stopChat(item)" link <el-button type="primary" v-else-if="!item.write_ed" @click="stopChat(item)" link
>停止回答 >停止回答
</el-button </el-button>
>
</div> </div>
</div> </div>
<div v-if="item.write_ed && props.appId && 500 != item.status" class="flex-between"> <div v-if="item.write_ed && props.appId && 500 != item.status" class="flex-between">
@ -137,7 +135,7 @@
/> />
</div> </div>
<!-- 语音播放 --> <!-- 语音播放 -->
<div style="float: right;" v-if="props.data.tts_model_enable"> <div style="float: right" v-if="props.data.tts_model_enable">
<el-button :disabled="!item.write_ed" @click="playAnswerText(item.answer_text)"> <el-button :disabled="!item.write_ed" @click="playAnswerText(item.answer_text)">
<el-icon> <el-icon>
<VideoPlay /> <VideoPlay />
@ -162,18 +160,12 @@
@keydown.enter="sendChatHandle($event)" @keydown.enter="sendChatHandle($event)"
/> />
<div class="operate" v-if="props.data.stt_model_enable"> <div class="operate" v-if="props.data.stt_model_enable">
<el-button <el-button v-if="mediaRecorderStatus" @click="startRecording">
v-if="mediaRecorderStatus"
@click="startRecording"
>
<el-icon> <el-icon>
<Microphone /> <Microphone />
</el-icon> </el-icon>
</el-button> </el-button>
<el-button <el-button v-else @click="stopRecording">
v-else
@click="stopRecording"
>
<el-icon> <el-icon>
<VideoPause /> <VideoPause />
</el-icon> </el-icon>
@ -231,8 +223,7 @@ const {
const props = defineProps({ const props = defineProps({
data: { data: {
type: Object, type: Object,
default: () => { default: () => {}
}
}, },
appId: String, // appId: String, //
log: Boolean, log: Boolean,
@ -289,15 +280,15 @@ const prologueList = computed(() => {
.reduce((pre_array: Array<any>, current: string, index: number) => { .reduce((pre_array: Array<any>, current: string, index: number) => {
const currentObj = isMdArray(current) const currentObj = isMdArray(current)
? { ? {
type: 'question', type: 'question',
str: current.replace(/^-\s+/, ''), str: current.replace(/^-\s+/, ''),
index: index index: index
} }
: { : {
type: 'md', type: 'md',
str: current, str: current,
index: index index: index
} }
if (pre_array.length > 0) { if (pre_array.length > 0) {
const pre = pre_array[pre_array.length - 1] const pre = pre_array[pre_array.length - 1]
if (!isMdArray(current) && pre.type == 'md') { if (!isMdArray(current) && pre.type == 'md') {
@ -328,38 +319,46 @@ watch(
) )
function handleInputFieldList() { function handleInputFieldList() {
props.data.work_flow?.nodes?.filter((v: any) => v.id === 'base-node') props.data.work_flow?.nodes
?.filter((v: any) => v.id === 'base-node')
.map((v: any) => { .map((v: any) => {
inputFieldList.value = v.properties.input_field_list.map((v: any) => { inputFieldList.value = v.properties.input_field_list
switch (v.type) { ? v.properties.input_field_list.map((v: any) => {
case 'input': switch (v.type) {
return { field: v.variable, input_type: 'TextInput', label: v.name, required: v.is_required } case 'input':
case 'select': return {
return { field: v.variable,
field: v.variable, input_type: 'TextInput',
input_type: 'SingleSelect', label: v.name,
label: v.name, required: v.is_required
required: v.is_required, }
option_list: v.optionList.map((o: any) => { case 'select':
return { key: o, value: o } return {
}) field: v.variable,
input_type: 'SingleSelect',
label: v.name,
required: v.is_required,
option_list: v.optionList.map((o: any) => {
return { key: o, value: o }
})
}
case 'date':
return {
field: v.variable,
input_type: 'DatePicker',
label: v.name,
required: v.is_required,
attrs: {
format: 'YYYY-MM-DD HH:mm:ss',
'value-format': 'YYYY-MM-DD HH:mm:ss',
type: 'datetime'
}
}
default:
break
} }
case 'date': })
return { : []
field: v.variable,
input_type: 'DatePicker',
label: v.name,
required: v.is_required,
attrs: {
'format': 'YYYY-MM-DD HH:mm:ss',
'value-format': 'YYYY-MM-DD HH:mm:ss',
'type': 'datetime'
}
}
default:
break
}
})
}) })
} }
@ -712,7 +711,6 @@ const mediaRecorder = ref<any>(null)
const audioPlayer = ref<HTMLAudioElement | null>(null) const audioPlayer = ref<HTMLAudioElement | null>(null)
const mediaRecorderStatus = ref(true) const mediaRecorderStatus = ref(true)
// //
const startRecording = async () => { const startRecording = async () => {
try { try {
@ -723,11 +721,14 @@ const startRecording = async () => {
sampleRate: 44100 sampleRate: 44100
}) })
mediaRecorder.value.open(() => { mediaRecorder.value.open(
mediaRecorder.value.start() () => {
}, (err: any) => { mediaRecorder.value.start()
console.error(err) },
}) (err: any) => {
console.error(err)
}
)
} catch (error) { } catch (error) {
console.error('无法获取音频权限:', error) console.error('无法获取音频权限:', error)
} }
@ -737,17 +738,20 @@ const startRecording = async () => {
const stopRecording = () => { const stopRecording = () => {
if (mediaRecorder.value) { if (mediaRecorder.value) {
mediaRecorderStatus.value = true mediaRecorderStatus.value = true
mediaRecorder.value.stop((blob: Blob, duration: number) => { mediaRecorder.value.stop(
// blob (blob: Blob, duration: number) => {
// const link = document.createElement('a') // blob
// link.href = window.URL.createObjectURL(blob) // const link = document.createElement('a')
// link.download = 'abc.mp3' // link.href = window.URL.createObjectURL(blob)
// link.click() // link.download = 'abc.mp3'
// link.click()
uploadRecording(blob) // uploadRecording(blob) //
}, (err: any) => { },
console.error('录音失败:', err) (err: any) => {
}) console.error('录音失败:', err)
}
)
} }
} }
@ -756,30 +760,32 @@ const uploadRecording = async (audioBlob: Blob) => {
try { try {
const formData = new FormData() const formData = new FormData()
formData.append('file', audioBlob, 'recording.mp3') formData.append('file', audioBlob, 'recording.mp3')
applicationApi.postSpeechToText(props.data.id as string, formData, loading) applicationApi.postSpeechToText(props.data.id as string, formData, loading).then((response) => {
.then((response) => { console.log('上传成功:', response.data)
console.log('上传成功:', response.data) inputValue.value = response.data
inputValue.value = response.data // chatMessage(null, res.data)
// chatMessage(null, res.data) })
})
} catch (error) { } catch (error) {
console.error('上传失败:', error) console.error('上传失败:', error)
} }
} }
const playAnswerText = (text: string) => { const playAnswerText = (text: string) => {
if (props.ttsModelOptions?.model_local_provider?.filter((v: any) => v.id === props.data.tts_model_id).length > 0) { if (
props.ttsModelOptions?.model_local_provider?.filter(
(v: any) => v.id === props.data.tts_model_id
).length > 0
) {
// SpeechSynthesisUtterance // SpeechSynthesisUtterance
const utterance = new SpeechSynthesisUtterance(text); const utterance = new SpeechSynthesisUtterance(text)
// //
window.speechSynthesis.speak(utterance); window.speechSynthesis.speak(utterance)
return return
} }
applicationApi.postTextToSpeech(props.data.id as string, { 'text': text }, loading) applicationApi
.postTextToSpeech(props.data.id as string, { text: text }, loading)
.then((res: any) => { .then((res: any) => {
// MP3 // MP3
// Blob // Blob
const blob = new Blob([res], { type: 'audio/mp3' }) const blob = new Blob([res], { type: 'audio/mp3' })