修复一些问题
This commit is contained in:
parent
d954c88ec5
commit
c812eaee5f
|
@ -13,7 +13,7 @@
|
|||
<el-input v-model="form.name" />
|
||||
</el-form-item>
|
||||
<el-form-item label="提示词" v-if="item.ex3 == '1' ? false : true">
|
||||
<el-input v-model="form.prompt" type="textarea" />
|
||||
<el-input v-model="form.prompt" type="textarea" autosize :rows="2" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<i class="iconfont icon-jiahao"></i>
|
||||
{{ curTemplate.ex3 == 1 ? '复制并创建个人模板' : '添加提示词' }}
|
||||
</el-button>
|
||||
<el-button type="primary" :disabled="!(childTempList.length)" @click="getModelResult">一键研读</el-button>
|
||||
<el-button type="primary" :disabled="!(childTempList.length)" @click="getModelResult('')">一键研读</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<!--List-->
|
||||
|
@ -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))
|
||||
})
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
@ -32,7 +32,7 @@ const props = defineProps({
|
|||
},
|
||||
showTypewriter: {
|
||||
type: Boolean,
|
||||
default: false, // 是否展示打字机效果
|
||||
default: true, // 是否展示打字机效果
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -40,7 +40,6 @@ const props = defineProps({
|
|||
const emit = defineEmits(['scroll','done']);
|
||||
|
||||
// 数据
|
||||
const textContainer = ref(null); // 用于绑定 DOM 元素
|
||||
const currentText = ref(''); // 当前展示的文本
|
||||
const currentCharIndex = ref(0); // 当前展示到的字符索引
|
||||
const isTyping = ref(false); // 是否正在展示
|
||||
|
@ -86,9 +85,7 @@ const startTypeWriter = () => {
|
|||
watch(
|
||||
() => props.text,
|
||||
() => {
|
||||
console.log(props.showTypewriter,3000)
|
||||
if(props.showTypewriter){
|
||||
|
||||
if(props.showTypewriter && props.text){
|
||||
startTypeWriter();
|
||||
} else {
|
||||
showFullText();
|
||||
|
|
Loading…
Reference in New Issue