lyc-dev #81

Merged
lyc merged 2 commits from lyc-dev into main 2024-12-04 15:14:23 +08:00
5 changed files with 254 additions and 182 deletions

View File

@ -142,13 +142,19 @@ const handleNodeClick = (data) => {
//label label
nodeData.label = nodeData.itemtitle
// null
let parent = {
let parentNode
// children
if(nodeData.children){
//
parentNode = null
}
else{
parentNode = {
id: nodeData.parentid,
label: nodeData.parenttitle,
itemtitle: nodeData.parenttitle
}
const parentNode = nodeData.parentid ? parent : null
}
nodeData.parentNode = parentNode
let curData = {
textBook: {

View File

@ -26,7 +26,7 @@
</div>
</div>
<!--List-->
<div class="container-right-list">
<div class="container-right-list" ref="listRef">
<template v-for="(item, index) in childTempList">
<div class="template-item" v-loading="item.loading">
<div class="item-header">
@ -52,7 +52,7 @@
<i class="iconfont icon-ai"></i>
</div>
<div class="item-answer">
<TypingEffect :text="item.oldAnswer" :delay="10" :aiShow="item.aiShow" @complete="onSaveTemp(item)" />
<TypingEffect v-if="isStarted[index]" :text="item.answer" :delay="10" :aiShow="item.aiShow" @complete="handleCompleteText($event,index)" @updateScroll="scrollToBottom($event,index)" />
</div>
</div>
<div class="ai-btn" v-if="item.answer">
@ -83,7 +83,7 @@
</template>
<script setup>
import { ref, reactive, onMounted, watch, onUnmounted } from 'vue'
import { ref, reactive, onMounted, watch, onUnmounted, nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { tempSave, completion, modelList, removeChildTemp, tempResult, editTempResult } from '@/api/mode/index'
import { sessionStore } from '@/utils/store'
@ -146,14 +146,16 @@ const getChildTemplate = () => {
tempLoading.value = true
modelList({ model: props.type, type: 2, parentId: curTemplate.id }).then(res => {
childTempList.value = res.rows
if(childTempList.value.length){
childTempList.value.forEach(item => item.answer = '')
}
getTempResult()
}).finally(() => {
tempLoading.value = false
})
}
const isStarted = ref([]);
const listRef = ref()
//
const getTempResult = () => {
tempResult({ mainModelId: curTemplate.id, pageNum: 1, pageSize: 10000 }).then(res => {
@ -161,14 +163,40 @@ const getTempResult = () => {
childTempList.value.forEach(item => {
rows.forEach(el => {
if (item.id == el.modelId) {
item.answer = el.content
item.answer = getResult(el.content)
item.resultId = el.id
}
})
})
if(rows.length > 0){
isStarted.value = new Array(rows.length).fill(true)
}
})
}
const scrollToBottom = (height,index) =>{
if (listRef.value) {
let sum = 0
let listDom = listRef.value.children
if(index == 0){
// 220
let screenHeight = window.innerHeight - 220
if(height > screenHeight){
listRef.value.scrollTop = (height - screenHeight + 50)
}
}
else{
for(let i = 0; i < index; i++){
sum += listDom[i].clientHeight
}
listRef.value.scrollTop = sum + height
}
}
}
//
const changeTemplate = (val) => {
ElMessageBox.confirm(
@ -203,11 +231,11 @@ const removeItem = async (item, isChild) => {
).then(() => {
removeChildTemp(item.id).then(res => {
ElMessage.success('操作成功')
if(isChild){
if (isChild) {
//
getChildTemplate()
}
else{
else {
//
getTemplateList()
}
@ -215,7 +243,7 @@ const removeItem = async (item, isChild) => {
})
}
else {
editKeyWord(item,!isChild)
editKeyWord(item, !isChild)
}
}
@ -240,19 +268,18 @@ const onEdit = (index, item) => {
const modeType = ref('课标')
watch(() => props.type, (newVal) => {
if (newVal == 1){
if (newVal == 1) {
modeType.value = '课标'
}
if (newVal == 2){
if (newVal == 2) {
modeType.value = '教材'
}
if (newVal == 2){
if (newVal == 3) {
modeType.value = '考试'
}
}, { immediate: false })
//
const params = reactive(
{
@ -260,76 +287,102 @@ const params = reactive(
dataset_id: ''
}
)
//
const isAgain = ref(false)
const againResult = async (index, item) => {
isAgain.value = true
isStarted.value[index] = false
childTempList.value[index].answer = ''
if(index == 0){
listRef.value.scrollTop = 0
}else{
scrollToBottom(50, index)
}
try {
await nextTick()
childTempList.value[index].loading = true
item.aiShow = true
childTempList.value[index].oldAnswer = ''
params.prompt = `按照${item.name}的要求,针对${curNode.edustage}${curNode.edusubject}${modeType.value}${curNode.itemtitle}进行教学分析`
const { data } = await completion(params)
let answer = data.answer
childTempList.value[index].oldAnswer = answer
childTempList.value[index].answer = getResult(answer);
// onEditSave(item)
childTempList.value[index].answer = getResult(data.answer);
isStarted.value[index] = true
} finally {
childTempList.value[index].loading = false
}
}
//
const getCompletion = async () => {
isStarted.value = new Array(childTempList.length).fill(false)
isStarted.value[0] = true
childTempList.value.forEach(item =>{
if(item.answer){
item.answer = ''
}
})
for (let item of childTempList.value) {
try {
item.loading = true
item.aiShow = true
params.prompt = `按照${item.name}的要求,针对${curNode.edustage}${curNode.edusubject}${modeType.value}${curNode.itemtitle}进行教学分析`
const { data } = await completion(params)
let answer = data.answer
item.oldAnswer = answer
item.answer = getResult(answer);
item.answer = getResult(data.answer)
onSaveTemp(item)
} finally {
item.loading = false
}
}
}
const handleCompleteText = async (answer, index) =>{
if (index < childTempList.value.length - 1) {
isStarted.value[index + 1] = true; //
}
if(isAgain.value){
try{
await editTempResult({ id: childTempList.value[index].resultId, content: answer })
}finally{
isAgain.value = false
}
}
}
//
emitter.on('onSaveAdjust', (item) => {
childTempList.value[curIndex.value].oldAnswer = item
let answer = getResult(item);
childTempList.value[curIndex.value].oldAnswer = item
childTempList.value[curIndex.value].answer = answer
childTempList.value[curIndex.value].answer = item
onEditSave(childTempList.value[curIndex.value])
})
//
const onEditSave = async (item) =>{
const { res } = await editTempResult({id: item.resultId, content: item.oldAnswer})
const onEditSave = async (item) => {
const { res } = await editTempResult({ id: item.resultId, content: item.answer })
ElMessage.success(res)
getChildTemplate()
}
//
const onSaveTemp = (item) => {
if(item.oldAnswer == '') return
if (item.answer == '') return
const data = {
mainModelId: curTemplate.id,
modelId: item.id,
examDocld: '',
content: item.oldAnswer
content: item.answer
}
tempSave(data).then(res => {})
tempSave(data).then(res => { })
}
//
let getResult = (text) => {
text = text.replace(/^\n\n(.*?)\n\n$/s, '<div>$1</div>');
text = text.replace(/^\n(.*?)\n$/s, '<p>$1</p>');
text = text.replace(/\*\*(.*?)\*\*/g, "<div class='text-tit'>$1</div>");
text = text.replace(/(\d+\..*?)\n/g, "<div class='text-num'>$1</div>\n");
return text
// ### **
let getResult = (str) => {
let newStr = str.replace(/#+|(\*\*)/g, '');
return newStr
}
//
@ -381,8 +434,6 @@ onUnmounted(() => {
padding: 5px 15px;
box-sizing: border-box;
.template-item {
background: #fff;
padding: 10px;

View File

@ -1,5 +1,5 @@
<template>
<div class="typing-effect">
<div class="typing-effect" ref="typingEffectRef">
<!-- <span v-html="displayedText"></span> -->
<el-input
v-model="displayedText"
@ -14,11 +14,11 @@
</template>
<script setup>
import { ref, onMounted, watch } from 'vue';
import { ref, onMounted, watch, nextTick } from 'vue';
const props = defineProps({
text: {
type: String,
type: [String, Object],
required: true
},
delay: {
@ -26,35 +26,48 @@ const props = defineProps({
default: 100 //
},
aiShow: {
type: [Boolean]
type: [Boolean] // true
}
});
const emit = defineEmits(['complete']);
const typingEffectRef = ref(null);
const emit = defineEmits(['complete', 'updateScroll']);
const displayedText = ref('');
const index = ref(0);
const type = () => {
if(!props.aiShow) return
const type = async () => {
await nextTick()
if(!props.aiShow) {
displayedText.value = props.text
return
}
if (index.value <= props.text.length) {
displayedText.value += props.text.charAt(index.value);
index.value++;
setTimeout(() => type(), props.delay);
setTimeout(() => {
type();
emit('updateScroll', typingEffectRef.value.clientHeight); //
}, props.delay);
} else {
// complete
emit('complete');
emit('complete',displayedText.value);
}
};
onMounted(() => {
type();
resetAndType();
});
// props 便 text delay
watch([() => props.text, () => props.delay], () => {
const resetAndType = () =>{
displayedText.value = '';
index.value = 0;
type();
});
}
// props 便 text delay
watch([() => props.text, () => props.delay], resetAndType);
</script>
<style scoped>

View File

@ -194,7 +194,7 @@ onMounted(() =>{
margin-bottom: 10px;
.img {
width: 100px;
width: 100%;
height: 130px;
border: solid #ccc 1px;
margin-bottom: 10px;

View File

@ -5,7 +5,7 @@
<div class="info">
<div class="info-name">{{ state.user.nickName }}</div>
<div class="infomation">
<selectClass/>
<selectClass v-if="!isSubject"/>
</div>
</div>
</div>
@ -46,8 +46,10 @@ const state = reactive({
postGroup: {}
})
const isSubject = ref(false)
async function getUser() {
getUserProfile().then((response) => {
isSubject.value = response.roleGroup.indexOf('场馆管理员') != -1
// response.data.avatar = import.meta.env.VITE_APP_BASE_API + response.data.avatar
Object.assign(state.user,response.data)
state.roleGroup = response.roleGroup