修复一些问题

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-input v-model="form.name" />
</el-form-item> </el-form-item>
<el-form-item label="提示词" v-if="item.ex3 == '1' ? false : true"> <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-item>
</el-form> </el-form>
</div> </div>

View File

@ -25,7 +25,7 @@
<i class="iconfont icon-jiahao"></i> <i class="iconfont icon-jiahao"></i>
{{ curTemplate.ex3 == 1 ? '复制并创建个人模板' : '添加提示词' }} {{ curTemplate.ex3 == 1 ? '复制并创建个人模板' : '添加提示词' }}
</el-button> </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>
</div> </div>
<!--List--> <!--List-->
@ -61,7 +61,7 @@
:text="item.answer" :text="item.answer"
:showTypewriter="item.showTypewriter" :showTypewriter="item.showTypewriter"
:speed="30" :speed="30"
:charsPerFrame="10" :charsPerFrame="15"
@scroll="handleScroll(index)" @scroll="handleScroll(index)"
@done="handleDone(index)" @done="handleDone(index)"
/> />
@ -107,7 +107,6 @@ import TypingEffect from '@/components/typing-effect/index.vue'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import emitter from '@/utils/mitt'; import emitter from '@/utils/mitt';
import { dataSetJson } from '@/utils/comm.js' import { dataSetJson } from '@/utils/comm.js'
import { cloneDeep } from 'lodash'
const props = defineProps(['type']) const props = defineProps(['type'])
const { user } = useUserStore() const { user } = useUserStore()
@ -180,7 +179,7 @@ const getTemplateList = () => {
} }
}) })
} }
const getChildTemplate = () => { const getChildTemplate = (val) => {
tempLoading.value = true tempLoading.value = true
modelList({ model: props.type, type: 2, parentId: curTemplate.id, ex1: curNode.edustage, ex2: curNode.edusubject }).then(res => { modelList({ model: props.type, type: 2, parentId: curTemplate.id, ex1: curNode.edustage, ex2: curNode.edusubject }).then(res => {
childTempList.value = res.rows childTempList.value = res.rows
@ -190,7 +189,11 @@ const getChildTemplate = () => {
item.showTypewriter = false item.showTypewriter = false
}) })
} }
getTempResult()
//
getTempResult(val)
}).finally(() => { }).finally(() => {
tempLoading.value = false tempLoading.value = false
}) })
@ -198,33 +201,45 @@ const getChildTemplate = () => {
// //
const getTempResult = () => { const getTempResult = (val) => {
tempResult({ mainModelId: curTemplate.id, pageNum: 1, pageSize: 10000, ex1: curNode.id }).then(res => { tempResult({ mainModelId: curTemplate.id, pageNum: 1, pageSize: 10000, ex1: curNode.id }).then(async res => {
let rows = res.rows let rows = res.rows
childTempList.value.forEach(item => { childTempList.value.forEach(item => {
rows.forEach(el => { rows.forEach(el => {
if (item.id == el.modelId) { if (item.id == el.modelId) {
item.answer = el.content item.answer = el.content
item.showTypewriter = false
item.resultId = el.id 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 prompt = ref('')
// //
const isAgain = ref(false) const isAgain = ref(false)
// //
const getModelResult = async (index, item) => { const getModelResult = async (index, item, isLast) => {
/**
*
* index: 当前项索引
* item: 当前项
* isLast: 是否最后一项 用于添加子模板后研读
*/
let str = prompt.value let str = prompt.value
// //
if(index && item){ if(index !== ''){
isAgain.value = true isAgain.value = true
// //
childTempList.value[index].answer = '' childTempList.value[index].answer = ''
@ -247,8 +262,13 @@ const getModelResult = async (index, item) => {
childTempList.value[index].loading = true childTempList.value[index].loading = true
const data = await requestModelData() const data = await requestModelData()
childTempList.value[index].answer = data.answer; childTempList.value[index].answer = data.answer;
if(isLast){
await onSaveTemp(childTempList.value[index])
}else{
// //
onEditResult(data.answer, index) onEditResult(data.answer, index)
}
} finally { } finally {
childTempList.value[index].loading = false childTempList.value[index].loading = false
} }
@ -269,23 +289,7 @@ const getModelResult = async (index, item) => {
}) })
processNext(0) 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() const data = await requestModelData()
item.answer = data.answer item.answer = data.answer
item.showTypewriter = true item.showTypewriter = true
childTempList.value[index].answer = data.answer
// //
await onSaveTemp(item) await onSaveTemp(item)
} finally { } finally {
childTempList.value[index].loading = false item.loading = false
} }
} }
// //
const handleDone = (index) =>{ const handleDone = (index) =>{
console.log(index)
if(isAgain.value){ if(isAgain.value){
isAgain.value = false isAgain.value = false
return
} }
else{ else{
if(index == childTempList.value.length - 1) return
outerContainer.value.scrollTo({
top: outerContainer.value.scrollHeight,
behavior: 'smooth',
});
processNext(index + 1) processNext(index + 1)
} }
} }
@ -354,9 +363,12 @@ const requestModelData = async () =>{
const messageElements = ref([]); // const messageElements = ref([]); //
// //
// const animationId = ref(null)
const animationIDs = ref([])
const outerContainer = ref() const outerContainer = ref()
let lastScrollTime = 0; let lastScrollTime = 0;
const scrollInterval = 100 const scrollInterval = 200
const handleScroll = (index) => { const handleScroll = (index) => {
const now = Date.now(); const now = Date.now();
if (now - lastScrollTime >= scrollInterval) { if (now - lastScrollTime >= scrollInterval) {
@ -375,12 +387,13 @@ const handleScroll = (index) => {
} }
else{ else{
// //
requestAnimationFrame(() => { const id = requestAnimationFrame(() => {
container.scrollTo({ container.scrollTo({
top: container.scrollHeight, top: container.scrollHeight,
behavior: 'smooth', behavior: 'smooth',
}); });
}); });
animationIDs.value.push(id)
} }
} }
} }
@ -392,12 +405,13 @@ const handleScroll = (index) => {
const scrollToTmp = (index) =>{ const scrollToTmp = (index) =>{
// //
if(index == childTempList.value.length - 1){ if(index == childTempList.value.length - 1){
requestAnimationFrame(() => { const id = requestAnimationFrame(() => {
outerContainer.value.scrollTo({ outerContainer.value.scrollTo({
top: outerContainer.value.scrollHeight, top: outerContainer.value.scrollHeight,
behavior: 'smooth', behavior: 'smooth',
}); });
}); });
animationIDs.value.push(id)
} }
else{ else{
const item = messageElements.value[index] const item = messageElements.value[index]
@ -476,8 +490,6 @@ const onEdit = (index, item) => {
isEdit.value = true isEdit.value = true
} }
// //
const onEditResult = async (answer, index) => { const onEditResult = async (answer, index) => {
@ -515,12 +527,12 @@ const onSaveTemp = async (item) => {
} }
// //
emitter.on('onGetChild', () => { emitter.on('onGetChild', () => {
getChildTemplate() getChildTemplate(true)
}) })
// //
emitter.on('onGetMain', () => { emitter.on('onGetMain====》', () => {
getTemplateList() getTemplateList()
}) })
@ -586,7 +598,11 @@ onUnmounted(() => {
emitter.off('onGetMain'); emitter.off('onGetMain');
emitter.off('onGetChild'); emitter.off('onGetChild');
emitter.off('onSaveAdjust'); emitter.off('onSaveAdjust');
//
animationIDs.value.forEach(id => cancelAnimationFrame(id))
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

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