修复一些问题

This commit is contained in:
lyc 2025-02-21 16:38:41 +08:00
parent d954c88ec5
commit c812eaee5f
3 changed files with 60 additions and 47 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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();