This commit is contained in:
lyc 2024-11-21 10:56:35 +08:00
parent 0ccdbfe37a
commit 5567e94235
4 changed files with 144 additions and 86 deletions

View File

@ -59,7 +59,7 @@ export function editChildTemp(data) {
// 删除子模板
export function removeChildTemp(id) {
return request({
url: '/education/llmModel/' + id,
url: '/education/llmModel/home/' + id,
method: 'delete'
})
}
@ -100,10 +100,3 @@ export function tempResult(params) {
})
}
// 删除模板结果
export function tempResultRemove(id) {
return request({
url: `/education/result/${id}`,
method: 'get',
})
}

View File

@ -32,7 +32,7 @@
</div>
</div>
<!--添加提示词-->
<keywordDialog v-model="wordDialog" :modeType="type" :isAdd="wordDialog" :item="curTemplate"/>
<keywordDialog v-model="wordDialog" :modeType="type" :isAdd="wordDialog" :item="curTemplate" />
<Dialog v-model="showDialog" :modeType="type" />
</template>
@ -43,6 +43,8 @@ import { ElMessageBox } from 'element-plus'
import { modelList } from '@/api/mode/index'
import Dialog from './dialog.vue'
import keywordDialog from './keyword-dialog.vue'
import emitter from '@/utils/mitt';
const wordDialog = ref(false)
const props = defineProps({
@ -53,7 +55,7 @@ const props = defineProps({
})
watch(() => props.type, (newValue) => {
console.log(newValue, 'newValue2');
}, { immediate: true });
}, { immediate: true });
const emit = defineEmits(['changeTemp', 'onRead'])
@ -70,7 +72,7 @@ const curTemplate = reactive({ name: '', id: '' })
const templateList = ref([])
//
const getTemplateList = () => {
modelList({ model: props.type, type: 1 }).then(res => {
modelList({ model: props.type, type: 1, pageNum: 1, pageSize: 10000 }).then(res => {
templateList.value = res.rows
Object.assign(curTemplate, res.rows[0]);
emit('changeTemp', res.rows[0].id)
@ -94,11 +96,18 @@ const changeTemplate = (val) => {
})
}
const onAdd = () =>{
wordDialog.value = true
emitter.on('onGetMain', () =>{
getTemplateList()
})
const onAdd = () => {
wordDialog.value = true
}
onUnmounted(() => {
emitter.off('onGetMain')
})
onMounted(() => {
getTemplateList()
})
@ -129,5 +138,4 @@ onMounted(() => {
font-weight: bold;
}
}
</style>

View File

@ -2,18 +2,18 @@
<el-dialog v-model="mode" :show-close="false" width="600" destroy-on-close>
<template #header>
<div class="custom-header flex">
<span>{{ isAdd ? item && item.ex3 == '1' ? '请输入新的模板名称' : '添加提示词' : '编辑提示词' }}</span>
<span>{{ item.ex3 == '1' ? '请输入新的模板名称' : 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>
<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="isAdd ? !(item && item.ex3 == '1') : true">
<el-form-item label="提示词" v-if="item.ex3 == '1' ? false : true">
<el-input v-model="form.prompt" type="textarea" />
</el-form-item>
</el-form>
@ -33,10 +33,9 @@
<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: {
@ -48,20 +47,25 @@ const props = defineProps({
default: true
},
item: { //
type: Object
type: Object,
default: () => {
return { ex3: '' }
}
},
tempId: {
type: [String, Number],
default: ''
},
temp: { //
Object
}
})
const form = reactive({
name: '',
prompt: '',
})
watch(() => props.isAdd, (newVal) => {
console.log(newVal)
if (!newVal) {
form.name = props.item?.name
form.prompt = props.item?.prompt
@ -71,47 +75,66 @@ watch(() => props.isAdd, (newVal) => {
const loading = ref(false)
const saveAdd = async () => {
loading.value = true
if (props.isAdd) {
try {
var msg = null
//
if (props.item.ex3 == '1') {
var { msg } = await addKeyWords({ name: form.name, id: props.item.id })
if (props.item.ex3 == '1') {
if (props.isAdd) {
try {
// copy
const { msg } = await addKeyWords({ name: form.name, id: props.item.id })
emitter.emit('onGetChild')
ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
}
else {
//
let obj = {
name: form.name,
type: 2, // 2
sortNum: 1,
parentId: props.item.id,
lmType: 1,
model: props.modeType,
prompt: form.prompt,
ex1: props.item.ex1, //
ex2: props.item.ex2, //
ex3: '', //
}
var { msg } = await addChildTemp(obj)
}
ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
}
else{
onAddChildTemp(props.item.parentId)
}
} else {
//
try {
let data = JSON.parse(JSON.stringify(props.item))
data.name = form.name;
data.prompt = form.prompt
const { msg } = await editChildTemp(data)
ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
if (props.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')
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
}
}
@ -128,7 +151,8 @@ const saveAdd = async () => {
font-weight: bold;
}
}
.small-tip{
.small-tip {
text-align: left;
font-size: 12px;
margin-bottom: 15px;

View File

@ -10,7 +10,7 @@
<div>
<span class="blue">#</span>{{ item.name }}
</div>
<el-popover placement="bottom-end" trigger="hover" popper-class="template-custom-popover" >
<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>
@ -55,13 +55,13 @@
<!--AI 对话调整-->
<AdjustDialog v-model="isAdjust" :modeType="modeType" :item="editItem" @saveAdjust="saveAdjust" />
<!--编辑提示词-->
<keywordDialog v-model="isEditKeyWord" :isAdd="!isEditKeyWord" :item="keywordItem"/>
<keywordDialog v-model="isEditKeyWord" :isAdd="isAdd" :item="keywordItem" :tempId="tempId" />
</div>
</template>
<script setup>
import { ref, reactive, onMounted, watch } from 'vue';
import { ElMessage } from 'element-plus'
import { ref, reactive, onMounted, watch, onUnmounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus'
import EditDialog from './edit-dialog.vue'
import AdjustDialog from './adjust-dialog.vue'
import keywordDialog from './keyword-dialog.vue';
@ -69,6 +69,7 @@ import { sessionStore } from '@/utils/store'
import useUserStore from '@/store/modules/user'
import { tempSave, completion, modelList, removeChildTemp, tempResult } from '@/api/mode/index'
import { dataSetJson } from '@/utils/comm.js'
import emitter from '@/utils/mitt';
const userStore = useUserStore()
@ -83,10 +84,15 @@ const props = defineProps({
}
})
emitter.on('onGetChild', () =>{
getChildTemplate()
})
//
const tempLoading = ref(false)
const childTempList = ref([])
const getChildTemplate = () => {
tempLoading.value = true
modelList({ model: props.modeType, type: 2, parentId: props.tempId }).then(res => {
childTempList.value = res.rows
@ -96,13 +102,12 @@ const getChildTemplate = () => {
})
}
//
const getTempResult = () =>{
tempResult({mainModelId: props.tempId}).then(res =>{
console.log(res,1000)
const getTempResult = () => {
tempResult({ mainModelId: props.tempId }).then(res => {
let rows = res.rows
childTempList.value.forEach(item =>{
rows.forEach(el =>{
if(item.id == el.modelId){
childTempList.value.forEach(item => {
rows.forEach(el => {
if (item.id == el.modelId) {
item.answer = el.content
item.reultId = el.id
}
@ -111,8 +116,6 @@ const getTempResult = () =>{
})
}
const isEdit = ref(false)
watch(() => props.tempId, (newVal) => {
if (newVal) {
@ -133,7 +136,6 @@ const params = reactive(
const curNode = reactive({})
const getConversation = () => {
getCompletion()
}
//
@ -154,14 +156,14 @@ const getCompletion = async () => {
}
//
const onSaveTemp = (item) =>{
const onSaveTemp = (item) => {
const data = {
mainModelId: props.tempId,
modelId: item.id,
examDocld: '',
content: item.oldAnswer
}
tempSave(data).then(res =>{
tempSave(data).then(res => {
console.log(res)
})
}
@ -224,30 +226,59 @@ const saveAdjust = (item) => {
//
const keywordItem = reactive({})
const isEditKeyWord = ref(false)
const editKeyWord = (item) =>{
const isAdd = ref(true)
const editKeyWord = (item) => {
console.log(item)
isAdd.value = false
isEditKeyWord.value = true
Object.assign(keywordItem, item)
}
//
const removeItem = async(item) =>{
const { msg } = await removeChildTemp(item.id)
ElMessage.success(msg)
getChildTemplate()
const removeItem = async (item) => {
if (item.ex3 != '1') {
ElMessageBox.confirm(
'确认是否移除?',
'提示',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
).then(() => {
console.log(item)
removeChildTemp(item.id).then(res => {
ElMessage.success('操作成功')
getChildTemplate()
})
})
}
else{
isAdd.value = false
Object.assign(keywordItem, item)
isEditKeyWord.value = true
}
// const { msg } = await removeChildTemp(item.id)
// ElMessage.success(msg)
// getChildTemplate()
}
onMounted(() => {
let data = sessionStore.get('subject.curNode')
Object.assign(curNode, data);
let text = props.modeType == 1 ? '课标': props.modeType == 2 ? '教材' : '考试'
let text = props.modeType == 1 ? '课标' : props.modeType == 2 ? '教材' : '考试'
let jsonKey = `${text}-${data.edustage}-${data.edusubject}`
params.dataset_id = dataSetJson[jsonKey]
})
//
onUnmounted(() => {
emitter.off('onGetChild')
})
defineExpose({
getConversation
@ -451,18 +482,20 @@ defineExpose({
}
}
.icon-shenglvehao{
.icon-shenglvehao {
font-weight: bold;
font-size: 22px;
}
:deep(.el-popover) {
min-width: 50px;
width: 50px !important;
}
.pl-25 {
padding-left: 25px;
}
</style>
<style>
.template-custom-popover {