This commit is contained in:
lyc 2025-02-21 00:15:20 +08:00
parent a708eb59b5
commit d954c88ec5
2 changed files with 63 additions and 27 deletions

View File

@ -63,7 +63,7 @@
:speed="30"
:charsPerFrame="10"
@scroll="handleScroll(index)"
@done="handleDone"
@done="handleDone(index)"
/>
</div>
</div>
@ -185,7 +185,10 @@ const getChildTemplate = () => {
modelList({ model: props.type, type: 2, parentId: curTemplate.id, ex1: curNode.edustage, ex2: curNode.edusubject }).then(res => {
childTempList.value = res.rows
if (childTempList.value.length) {
childTempList.value.forEach(item => item.answer = '')
childTempList.value.forEach(item => {
item.answer = '';
item.showTypewriter = false
})
}
getTempResult()
}).finally(() => {
@ -257,7 +260,6 @@ const getModelResult = async (index, item) => {
childTempList.value.forEach(item => {
if (item.answer) {
item.answer = ''
item.showTypewriter = true
}
})
//
@ -265,25 +267,61 @@ const getModelResult = async (index, item) => {
behavior: 'smooth',
block: 'start',
})
for (let item of childTempList.value) {
try {
item.loading = true
processNext(0)
// for (let item of childTempList.value) {
// try {
// item.loading = true
// str = str.replace('{}',item.name)
// str = str.replace('{}',item.prompt)
// params.prompt = str
// params.template = item.prompt
// //
// const data = await requestModelData()
// item.answer = data.answer
// await onSaveTemp(item)
// } finally {
// item.loading = false
// }
// }
}
}
//
const processNext = async (index) =>{
let str = prompt.value
//
const item = childTempList.value[index]
item.loading = true
str = str.replace('{模板标题}',item.name)
str = str.replace('{模板内容}',item.prompt)
params.prompt = str
params.template = item.prompt
//
try {
const data = await requestModelData()
item.answer = data.answer
item.showTypewriter = true
childTempList.value[index].answer = data.answer
//
await onSaveTemp(item)
} finally {
item.loading = false
}
}
childTempList.value[index].loading = false
}
}
//
const handleDone = (index) =>{
console.log(index)
if(isAgain.value){
isAgain.value = false
}
else{
processNext(index + 1)
}
}
// ms:
@ -369,12 +407,7 @@ const scrollToTmp = (index) =>{
}
}
//
const handleDone = () =>{
if(isAgain.value){
isAgain.value = false
}
}
//
const changeTemplate = (val) => {

View File

@ -32,12 +32,12 @@ const props = defineProps({
},
showTypewriter: {
type: Boolean,
default: true, //
default: false, //
},
});
// emits
const emit = defineEmits(['scroll']);
const emit = defineEmits(['scroll','done']);
//
const textContainer = ref(null); // DOM
@ -65,6 +65,7 @@ const typeText = () => {
});
} else {
isTyping.value = false;
emit('done')
}
};
@ -85,7 +86,9 @@ const startTypeWriter = () => {
watch(
() => props.text,
() => {
console.log(props.showTypewriter,3000)
if(props.showTypewriter){
startTypeWriter();
} else {
showFullText();