修复一些问题
This commit is contained in:
parent
d954c88ec5
commit
c812eaee5f
|
@ -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>
|
||||||
|
|
|
@ -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){
|
||||||
onEditResult(data.answer, index)
|
await onSaveTemp(childTempList.value[index])
|
||||||
|
}else{
|
||||||
|
// 保存重新研读后的结果
|
||||||
|
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>
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue