diff --git a/src/renderer/src/components/template-study/container/keyword-dialog.vue b/src/renderer/src/components/template-study/container/keyword-dialog.vue
index bdd6c29..348c8a7 100644
--- a/src/renderer/src/components/template-study/container/keyword-dialog.vue
+++ b/src/renderer/src/components/template-study/container/keyword-dialog.vue
@@ -13,7 +13,7 @@
-
+
diff --git a/src/renderer/src/components/template-study/container/right.vue b/src/renderer/src/components/template-study/container/right.vue
index ab53408..ebefbc6 100644
--- a/src/renderer/src/components/template-study/container/right.vue
+++ b/src/renderer/src/components/template-study/container/right.vue
@@ -25,7 +25,7 @@
{{ curTemplate.ex3 == 1 ? '复制并创建个人模板' : '添加提示词' }}
- 一键研读
+ 一键研读
@@ -61,7 +61,7 @@
:text="item.answer"
:showTypewriter="item.showTypewriter"
:speed="30"
- :charsPerFrame="10"
+ :charsPerFrame="15"
@scroll="handleScroll(index)"
@done="handleDone(index)"
/>
@@ -107,7 +107,6 @@ import TypingEffect from '@/components/typing-effect/index.vue'
import useUserStore from '@/store/modules/user'
import emitter from '@/utils/mitt';
import { dataSetJson } from '@/utils/comm.js'
-import { cloneDeep } from 'lodash'
const props = defineProps(['type'])
const { user } = useUserStore()
@@ -180,7 +179,7 @@ const getTemplateList = () => {
}
})
}
-const getChildTemplate = () => {
+const getChildTemplate = (val) => {
tempLoading.value = true
modelList({ model: props.type, type: 2, parentId: curTemplate.id, ex1: curNode.edustage, ex2: curNode.edusubject }).then(res => {
childTempList.value = res.rows
@@ -190,7 +189,11 @@ const getChildTemplate = () => {
item.showTypewriter = false
})
}
- getTempResult()
+
+ // 获取研读结果
+ getTempResult(val)
+
+
}).finally(() => {
tempLoading.value = false
})
@@ -198,33 +201,45 @@ const getChildTemplate = () => {
// 查询模板结果
-const getTempResult = () => {
- tempResult({ mainModelId: curTemplate.id, pageNum: 1, pageSize: 10000, ex1: curNode.id }).then(res => {
+const getTempResult = (val) => {
+ tempResult({ mainModelId: curTemplate.id, pageNum: 1, pageSize: 10000, ex1: curNode.id }).then(async res => {
let rows = res.rows
childTempList.value.forEach(item => {
rows.forEach(el => {
if (item.id == el.modelId) {
item.answer = el.content
- item.showTypewriter = false
item.resultId = el.id
}
})
})
+ // val : true 新增的子模板 然后研读
+ if(val){
+ // 添加了一个子模板 要等dom 更新完成 不然滚动无效
+ await nextTick()
+
+ // 研读最后一个
+ let lastIndex = childTempList.value.length - 1
+ getModelResult(lastIndex, childTempList.value[lastIndex], true)
+ }
})
}
-
const prompt = ref('')
// 是否重新研读
const isAgain = ref(false)
// 研读
-const getModelResult = async (index, item) => {
-
+const getModelResult = async (index, item, isLast) => {
+ /**
+ *
+ * index: 当前项索引
+ * item: 当前项
+ * isLast: 是否最后一项 用于添加子模板后研读
+ */
let str = prompt.value
// 重新研读
- if(index && item){
+ if(index !== ''){
isAgain.value = true
// 清空研读结果
childTempList.value[index].answer = ''
@@ -247,8 +262,13 @@ const getModelResult = async (index, item) => {
childTempList.value[index].loading = true
const data = await requestModelData()
childTempList.value[index].answer = data.answer;
- // 保存重新研读后的结果
- onEditResult(data.answer, index)
+ if(isLast){
+ await onSaveTemp(childTempList.value[index])
+ }else{
+ // 保存重新研读后的结果
+ onEditResult(data.answer, index)
+ }
+
} finally {
childTempList.value[index].loading = false
}
@@ -269,23 +289,7 @@ const getModelResult = async (index, item) => {
})
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
- // }
- // }
}
}
@@ -304,22 +308,27 @@ const processNext = async (index) =>{
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
+ item.loading = false
}
}
// 打字机完成后触发
const handleDone = (index) =>{
- console.log(index)
if(isAgain.value){
isAgain.value = false
+ return
}
else{
+ if(index == childTempList.value.length - 1) return
+ outerContainer.value.scrollTo({
+ top: outerContainer.value.scrollHeight,
+ behavior: 'smooth',
+ });
processNext(index + 1)
}
}
@@ -354,9 +363,12 @@ const requestModelData = async () =>{
const messageElements = ref([]); // 存储所有消息元素的引用
// 处理页面滚动
+// const animationId = ref(null)
+const animationIDs = ref([])
+
const outerContainer = ref()
let lastScrollTime = 0;
-const scrollInterval = 100
+const scrollInterval = 200
const handleScroll = (index) => {
const now = Date.now();
if (now - lastScrollTime >= scrollInterval) {
@@ -375,12 +387,13 @@ const handleScroll = (index) => {
}
else{
// 平滑滚动到底部
- requestAnimationFrame(() => {
+ const id = requestAnimationFrame(() => {
container.scrollTo({
top: container.scrollHeight,
behavior: 'smooth',
});
});
+ animationIDs.value.push(id)
}
}
}
@@ -392,12 +405,13 @@ const handleScroll = (index) => {
const scrollToTmp = (index) =>{
// 最后一个 滚到底部
if(index == childTempList.value.length - 1){
- requestAnimationFrame(() => {
+ const id = requestAnimationFrame(() => {
outerContainer.value.scrollTo({
top: outerContainer.value.scrollHeight,
behavior: 'smooth',
});
});
+ animationIDs.value.push(id)
}
else{
const item = messageElements.value[index]
@@ -476,8 +490,6 @@ const onEdit = (index, item) => {
isEdit.value = true
}
-
-
// 保存编辑后的研读内容
const onEditResult = async (answer, index) => {
@@ -515,12 +527,12 @@ const onSaveTemp = async (item) => {
}
-// 操作之后获取字模板
+// 操作之后获取子模板
emitter.on('onGetChild', () => {
- getChildTemplate()
+ getChildTemplate(true)
})
// 操作之后获取主模板
-emitter.on('onGetMain', () => {
+emitter.on('onGetMain====》', () => {
getTemplateList()
})
@@ -586,7 +598,11 @@ onUnmounted(() => {
emitter.off('onGetMain');
emitter.off('onGetChild');
emitter.off('onSaveAdjust');
+ // 组件卸载时取消动画帧
+ animationIDs.value.forEach(id => cancelAnimationFrame(id))
})
+
+