From d954c88ec57cb41b5398dd254493a10b04c9d24f Mon Sep 17 00:00:00 2001 From: lyc Date: Fri, 21 Feb 2025 00:15:20 +0800 Subject: [PATCH] edit --- .../template-study/container/right.vue | 83 +++++++++++++------ .../src/components/typing-effect/index.vue | 7 +- 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/renderer/src/components/template-study/container/right.vue b/src/renderer/src/components/template-study/container/right.vue index 6330ddb..ab53408 100644 --- a/src/renderer/src/components/template-study/container/right.vue +++ b/src/renderer/src/components/template-study/container/right.vue @@ -63,7 +63,7 @@ :speed="30" :charsPerFrame="10" @scroll="handleScroll(index)" - @done="handleDone" + @done="handleDone(index)" /> @@ -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 - str = str.replace('{模板标题}',item.name) - str = str.replace('{模板内容}',item.prompt) - params.prompt = str - params.template = item.prompt - // 请求数据 - const data = await requestModelData() + processNext(0) + // for (let item of childTempList.value) { + // try { + // item.loading = true - item.answer = data.answer - await onSaveTemp(item) - } finally { - item.loading = false - } - } + // 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 { + 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) => { diff --git a/src/renderer/src/components/typing-effect/index.vue b/src/renderer/src/components/typing-effect/index.vue index e2e479d..c4c44db 100644 --- a/src/renderer/src/components/typing-effect/index.vue +++ b/src/renderer/src/components/typing-effect/index.vue @@ -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();