Merge pull request 'lyc-dev' (#135) from lyc-dev into main

This commit is contained in:
lyc 2024-12-16 09:50:59 +08:00
commit 2a11173874
7 changed files with 352 additions and 71 deletions

View File

@ -40,7 +40,7 @@ const props = defineProps({
type: Number, type: Number,
default: 1 default: 1
}, },
item: { // item: { //
type: Object, type: Object,
default: () => { default: () => {
return { ex3: '' } return { ex3: '' }
@ -73,23 +73,25 @@ const loading = ref(false)
const saveAdd = async () => { const saveAdd = async () => {
loading.value = true loading.value = true
if (props.item.ex3 == '1') { if (props.item.ex3 == '1') {
let id; // id id
if (props.item.isAdd) { if (props.item.isAdd) {
id = props.item.id
}
else{
// item item.parentId
id = props.item.parentId
}
try { try {
// copy // copy
const { msg } = await addKeyWords({ name: form.name, id: props.item.id }) const { msg } = await addKeyWords({ name: form.name, id })
emitter.emit('onGetMain') emitter.emit('onGetMain')
ElMessage.success(msg) ElMessage.success(msg)
mode.value = false mode.value = false
} finally { } finally {
loading.value = false loading.value = false
} }
}
else{
onAddChildTemp(props.item.parentId)
}
} else {
} else {
if (props.item.isAdd) { if (props.item.isAdd) {
onAddChildTemp(props.item.id) onAddChildTemp(props.item.id)
} }

View File

@ -16,12 +16,12 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted, nextTick } from 'vue' import { ref, onMounted, nextTick, reactive } from 'vue'
import { sessionStore } from '@/utils/store' import { sessionStore } from '@/utils/store'
import PDF from '@/components/PdfJs/index.vue' import PDF from '@/components/PdfJs/index.vue'
import LeftDialog from './left-dialog.vue' import LeftDialog from './left-dialog.vue'
const props = defineProps(['curNode', 'type']) const props = defineProps(['type'])
const showDialog = ref(false) const showDialog = ref(false)
const onClick = () => { const onClick = () => {
@ -31,8 +31,13 @@ const onClick = () => {
// PDF // PDF
const pdfUrl = ref('') const pdfUrl = ref('')
const curNode = reactive({})
onMounted(async () => { onMounted(async () => {
await nextTick() await nextTick()
//
let nodeData = sessionStore.get('subject.curNode')
Object.assign(curNode, nodeData);
let data = sessionStore.get('subject.curBook') let data = sessionStore.get('subject.curBook')
let fileurl = data.fileurl let fileurl = data.fileurl
if(props.type == 1){ if(props.type == 1){

View File

@ -83,7 +83,7 @@
</template> </template>
<script setup> <script setup>
import { ref, reactive, onMounted, watch, onUnmounted, nextTick } from 'vue' import { ref, reactive, onMounted, onUnmounted, nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { tempSave, completion, modelList, removeChildTemp, tempResult, editTempResult } from '@/api/mode/index' import { tempSave, completion, modelList, removeChildTemp, tempResult, editTempResult } from '@/api/mode/index'
import { sessionStore } from '@/utils/store' import { sessionStore } from '@/utils/store'
@ -95,7 +95,7 @@ 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'
const props = defineProps(['curNode', 'type']) const props = defineProps(['type'])
const { user } = useUserStore() const { user } = useUserStore()
/*****************提示词相关****************/ /*****************提示词相关****************/
@ -270,21 +270,6 @@ const onEdit = (index, item) => {
isEdit.value = true isEdit.value = true
} }
const modeType = ref('课标')
watch(() => props.type, (newVal) => {
if (newVal == 1) {
modeType.value = '课标'
}
if (newVal == 2) {
modeType.value = '教材'
}
if (newVal == 3) {
modeType.value = '考试'
}
}, { immediate: false })
// //
const params = reactive( const params = reactive(
{ {
@ -402,11 +387,14 @@ emitter.on('onGetMain', () => {
const curNode = reactive({}) const curNode = reactive({})
const modeType = ref('')
onMounted(() => { onMounted(() => {
let data = sessionStore.get('subject.curNode') let data = sessionStore.get('subject.curNode')
Object.assign(curNode, data); Object.assign(curNode, data);
modeType.value = props.type == 1 ? '课标' : props.type == 2 ? '教材' : '考试'
getTemplateList() getTemplateList()
let jsonKey = `${modeType.value}-${data.edustage}-${data.edusubject}` let jsonKey = `${modeType.value}-${data.edustage}-${data.edusubject}`
params.dataset_id = dataSetJson[jsonKey] params.dataset_id = dataSetJson[jsonKey]
}) })

View File

@ -2,18 +2,16 @@
<div class="page-template flex"> <div class="page-template flex">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<Left :curNode="curNode" :type="type" /> <Left :type="type" />
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<Right :curNode="curNode" :type="type" /> <Right :type="type" />
</el-col> </el-col>
</el-row> </el-row>
</div> </div>
</template> </template>
<script setup> <script setup>
import { reactive, onMounted } from 'vue'
import { sessionStore } from '@/utils/store'
import Left from './container/left.vue' import Left from './container/left.vue'
import Right from './container/right.vue' import Right from './container/right.vue'
@ -23,13 +21,6 @@ const props = defineProps({
default: 1 default: 1
}, },
}) })
const curNode = reactive({})
onMounted(() =>{
let data = sessionStore.get('subject.curNode')
Object.assign(curNode, data);
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -0,0 +1,159 @@
<template>
<el-dialog v-model="mode" :show-close="false" width="600" append-to-body destroy-on-close>
<template #header>
<div class="custom-header flex">
<span>{{ item.ex3 == '1' ? '请输入新的模板名称' : item.isAdd ? '添加提示词' : '编辑提示词' }}</span>
<i class="iconfont icon-guanbi" @click="mode = false"></i>
</div>
</template>
<div class="dialog-content" v-loading="loading">
<p class="small-tip" v-if="item && item.ex3 == '1'">*当前模板为系统预设不支持直接操作需要复制一份为自己的然后再操作</p>
<el-form :model="form" label-width="auto">
<el-form-item label="名称">
<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-form-item>
</el-form>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="mode = false">取消</el-button>
<el-button type="primary" @click="saveAdd">
确定
</el-button>
</div>
</template>
</el-dialog>
</template>
<script setup>
import { ref, reactive, watch } from 'vue'
import { ElMessage } from 'element-plus'
import emitter from '@/utils/mitt';
import { addKeyWords, addChildTemp, editChildTemp } from '@/api/mode/index'
const mode = defineModel()
const props = defineProps({
modeType: {
type: Number,
default: 1
},
item: { //
type: Object,
default: () => {
return { ex3: '' }
}
},
})
const form = reactive({
name: '',
prompt: '',
})
watch(() => mode.value, (newVal) => {
if(newVal){
if (props.item.isAdd) {
form.name = ''
form.prompt = ''
}
else{
form.name = props.item?.name
form.prompt = props.item?.prompt
}
}
},{ deep: true})
const loading = ref(false)
const saveAdd = async () => {
loading.value = true
if (props.item.ex3 == '1') {
let id; // id id
if (props.item.isAdd) {
id = props.item.id
}
else{
// item item.parentId
id = props.item.parentId
}
try {
// copy
const { msg } = await addKeyWords({ name: form.name, id })
emitter.emit('onGetMain')
ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
}
} else {
if (props.item.isAdd) {
onAddChildTemp(props.item.id)
}
else {
try {
let data = JSON.parse(JSON.stringify(props.item))
data.name = form.name;
data.prompt = form.prompt
const { msg } = await editChildTemp(data)
emitter.emit('onGetChild', data )
ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
}
}
}
}
//
const onAddChildTemp = async (parentId) => {
//
let obj = {
name: form.name,
type: 2, // 2
sortNum: 1,
parentId,
lmType: 1,
model: props.modeType,
prompt: form.prompt,
ex1: props.item.ex1, //
ex2: props.item.ex2, //
ex3: '', //
}
try {
var { msg } = await addChildTemp(obj)
emitter.emit('onGetChild')
ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
}
}
</script>
<style lang="scss" scoped>
.custom-header {
justify-content: space-between;
align-items: center;
.icon-guanbi {
cursor: pointer;
font-weight: bold;
}
}
.small-tip {
text-align: left;
font-size: 12px;
margin-bottom: 15px;
color: #F56C6C;
}
</style>

View File

@ -2,6 +2,7 @@
<div class="container-left flex"> <div class="container-left flex">
<div class="left-header flex">教学模式</div> <div class="left-header flex">教学模式</div>
<div class="left-con" v-loading="loading"> <div class="left-con" v-loading="loading">
<el-empty v-if="!(tempList.length)" description="暂无数据" />
<div class="con-item" v-for="item in tempList" :key="item.id"> <div class="con-item" v-for="item in tempList" :key="item.id">
<div class="item-header flex"> <div class="item-header flex">
<span>{{ item.name }}</span> <span>{{ item.name }}</span>
@ -29,27 +30,33 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted } from 'vue'; import { ref, reactive, onMounted, onUnmounted } from 'vue';
import emitter from '@/utils/mitt'; import emitter from '@/utils/mitt';
import { modelList } from '@/api/mode/index' import { modelList } from '@/api/mode/index'
import useUserStore from '@/store/modules/user'
import { sessionStore } from '@/utils/store'
const { user } = useUserStore()
// //
let list = [] let list = ref([])
const getTemplate = () => { const getTemplate = async (id) => {
modelList({ model: 1, type: 1, ex3: 1 }).then(res => { const { rows } = await modelList({ createUser: user.userId, model: 4, type: 1, pageNum: 1, pageSize: 10000})
list = res.rows list.value = rows
getChildTemp() if(list.value.length){
}) getChildTemp(id)
}
} }
// //
const loading = ref(false) const loading = ref(false)
const tempList = ref([]) const tempList = ref([])
const getChildTemp = async () => { const getChildTemp = async (parentId) => {
tempList.value.length = 0
loading.value = true loading.value = true
for (let item of list) { for (let item of list.value) {
try { try {
const { rows } = await modelList({ model: 1, type: 2, parentId: item.id }) const { rows } = await modelList({ model: 4, type: 2, parentId: item.id })
tempList.value.push({ tempList.value.push({
id: item.id, id: item.id,
name: item.name, name: item.name,
@ -57,20 +64,52 @@ const getChildTemp = async () => {
}) })
} finally { } finally {
loading.value = false loading.value = false
}
}
if(parentId){
const item = tempList.value.find(item => item.id == parentId)
emitter.emit('changeMode', item)
}
else{
emitter.emit('changeMode', tempList.value[0]) emitter.emit('changeMode', tempList.value[0])
} }
}
} }
//
emitter.on('onGetChild', async (data) => {
await getTemplate(data.parentId)
})
//
emitter.on('onGetMain', (item) => {
getTemplate(item.parentId)
})
// //
const emit = defineEmits(['']) const emit = defineEmits([''])
const onSelect = (item) =>{ const onSelect = (item) =>{
emitter.emit('changeMode', item) emitter.emit('changeMode', item)
} }
const curNode = reactive({})
onMounted(() => { onMounted(() => {
let data = sessionStore.get('subject.curNode')
Object.assign(curNode, data);
getTemplate() getTemplate()
}) })
//
onUnmounted(() => {
emitter.off('onGetMain');
emitter.off('onGetChild');
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -96,7 +135,7 @@ onMounted(() => {
padding: 15px; padding: 15px;
box-sizing: border-box; box-sizing: border-box;
font-size: 14px; font-size: 14px;
overflow: auto;
.item-header { .item-header {
justify-content: space-between; justify-content: space-between;
margin-bottom: 5px; margin-bottom: 5px;

View File

@ -10,17 +10,29 @@
</el-button> </el-button>
</div> </div>
<div class="header-right"> <div class="header-right">
<el-button type="primary" :disabled="!(resultList.length)" @click="getCompletion">一键研读</el-button>
<el-button type="primary">生成大纲</el-button> <el-button type="primary">生成大纲</el-button>
<el-button type="danger" @click="pptDialog = true">生成PPT</el-button> <el-button type="danger" @click="pptDialog = true">生成PPT</el-button>
</div> </div>
</div> </div>
<div class="right-con flex"> <div class="right-con flex">
<el-empty v-if="!(resultList.length)" description="暂无数据" />
<div class="con-item flex" v-for="(item, index) in resultList" :key="item.id" v-loading="item.loading"> <div class="con-item flex" v-for="(item, index) in resultList" :key="item.id" v-loading="item.loading">
<div class="item-top flex"> <div class="item-top flex">
<span>{{ item.name }}</span> <span>{{ item.name }}</span>
<el-button type="info" link> <el-popover placement="bottom-end" trigger="hover" popper-class="template-custom-popover">
<template #reference>
<el-button link type="primary">
<i class="iconfont icon-shenglvehao"></i></el-button>
</template>
<template #default>
<el-button type="primary" link @click="editKeyWord(item, false)">编辑</el-button>
<el-button type="primary" link @click="removeItem(item, true)">移除</el-button>
</template>
</el-popover>
<!-- <el-button type="info" link>
<i class="iconfont icon-xiazai9"></i> <i class="iconfont icon-xiazai9"></i>
</el-button> </el-button> -->
</div> </div>
<div class="item-bom"> <div class="item-bom">
<div class="item-prompt">{{ item.prompt }}</div> <div class="item-prompt">{{ item.prompt }}</div>
@ -51,19 +63,23 @@
<AdjustDialog v-model="isAdjust" :item="curItem" /> <AdjustDialog v-model="isAdjust" :item="curItem" />
<PptDialog @add-success="addAiPPT" :dataList="resultList" v-model="pptDialog"/> <PptDialog @add-success="addAiPPT" :dataList="resultList" v-model="pptDialog"/>
<progress-dialog v-model:visible="pgDialog.visible" v-bind="pgDialog" /> <progress-dialog v-model:visible="pgDialog.visible" v-bind="pgDialog" />
<!--添加编辑提示词-->
<keywordDialog v-model="isWordDialog" :item="curItem" />
</template> </template>
<script setup> <script setup>
import { ref, onMounted, onUnmounted, reactive } from 'vue' import { ref, onMounted, onUnmounted, reactive } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { sessionStore } from '@/utils/store' import { sessionStore } from '@/utils/store'
import emitter from '@/utils/mitt' import emitter from '@/utils/mitt'
import EditDialog from './edit-dialog.vue' import EditDialog from './edit-dialog.vue'
import AdjustDialog from './adjust-dialog.vue' import AdjustDialog from './adjust-dialog.vue'
import progressDialog from './progress-dialog.vue' import progressDialog from './progress-dialog.vue'
import { completion, tempResult } from '@/api/mode/index.js' import { completion, tempResult, tempSave, removeChildTemp } from '@/api/mode/index.js'
// import { dataSetJson } from '@/utils/comm.js' // import { dataSetJson } from '@/utils/comm.js'
import * as commUtils from '@/utils/comm.js' import * as commUtils from '@/utils/comm.js'
import PptDialog from '@/views/prepare/container/pptist-dialog.vue' import PptDialog from '@/views/prepare/container/pptist-dialog.vue'
import keywordDialog from './keyword-dialog.vue'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import {PPTXFileToJson} from '@/AixPPTist/src/hooks/useImport' // pptjson import {PPTXFileToJson} from '@/AixPPTist/src/hooks/useImport' // pptjson
@ -97,11 +113,87 @@ const pgDialog = reactive({ // 弹窗-进度条
}) })
emitter.on('changeMode', (item) => { emitter.on('changeMode', (item) => {
resultList.value = item.child resultList.value = item.child
// conversation()
getTempResult(item.id) getTempResult(item.id)
}) })
//
const getCompletion = async () => {
for (let item of resultList.value) {
console.log(item)
try {
item.loading = true
params.prompt = `按照${item.prompt}的要求,针对${curNode.edustage}${curNode.edusubject}${curNode.itemtitle}进行教学分析`
const { data } = await completion(params)
item.answer = getResult(data.answer)
onSaveTemp(item)
} finally {
item.loading = false
}
}
}
//
const onSaveTemp = (item) => {
if (item.answer == '') return
const data = {
mainModelId: item.parentId,
modelId: item.id,
examDocld: '',
content: item.answer,
ex1: curNode.id
}
tempSave(data).then(res => { })
}
const isWordDialog = ref(false)
const editKeyWord = (item, val) => {
/**
* isAdd: 子模板中的移除 为编辑false 头部删除 添加提示词为新增 true
*/
Object.assign(curItem, item)
curItem.isAdd = val
isWordDialog.value = true
}
//
const removeItem = async (item, isChild) => {
/**
* item: 当前操作的模板
* isChild: 子模板中的移除为 true
*/
if (item.ex3 != '1') {
ElMessageBox.confirm(
'确认是否移除?',
'提示',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
).then(() => {
removeChildTemp(item.id).then(res => {
ElMessage.success('操作成功')
if (isChild) {
//
emitter.emit('onGetChild', item)
}
else {
//
// getTemplateList()
}
})
})
}
else {
// editKeyWord(item, !isChild)
}
}
// //
const getTempResult = (id) => { const getTempResult = (id) => {
tempResult({ mainModelId: id }).then(res => { tempResult({ mainModelId: id }).then(res => {
@ -119,6 +211,11 @@ const getTempResult = (id) => {
}) })
} }
// ### **
let getResult = (str) => {
let newStr = str.replace(/#+|(\*\*)/g, '');
return newStr
}
const params = reactive( const params = reactive(
{ {
@ -176,18 +273,7 @@ const addAiPPT = async(res) => {
} }
}) })
} }
const conversation = async () => {
for (let item of resultList.value) {
item.loading = true
try {
params.prompt = `按照${item.prompt}的要求,针对${curNode.edustage}${curNode.edusubject}课标对${curNode.itemtitle}进行教学分析`
const { data } = await completion(params)
item.answer = data.answer
} finally {
item.loading = false
}
}
}
const isEdit = ref(false) const isEdit = ref(false)
// //
@ -368,8 +454,10 @@ onUnmounted(() => {
emitter.off('changeMode') emitter.off('changeMode')
emitter.off('changeResult') emitter.off('changeResult')
emitter.off('changeAdjust') emitter.off('changeAdjust')
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -402,6 +490,9 @@ onUnmounted(() => {
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
margin-bottom: 5px; margin-bottom: 5px;
.icon-shenglvehao{
font-weight: bold
}
} }
.item-bom { .item-bom {
@ -446,3 +537,9 @@ onUnmounted(() => {
} }
} }
</style> </style>
<style>
.template-custom-popover {
width: 110px !important;
min-width: 110px !important;
}
</style>