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

View File

@ -43,6 +43,8 @@ import { ElMessageBox } from 'element-plus'
import { modelList } from '@/api/mode/index' import { modelList } from '@/api/mode/index'
import Dialog from './dialog.vue' import Dialog from './dialog.vue'
import keywordDialog from './keyword-dialog.vue' import keywordDialog from './keyword-dialog.vue'
import emitter from '@/utils/mitt';
const wordDialog = ref(false) const wordDialog = ref(false)
const props = defineProps({ const props = defineProps({
@ -70,7 +72,7 @@ const curTemplate = reactive({ name: '', id: '' })
const templateList = ref([]) const templateList = ref([])
// //
const getTemplateList = () => { 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 templateList.value = res.rows
Object.assign(curTemplate, res.rows[0]); Object.assign(curTemplate, res.rows[0]);
emit('changeTemp', res.rows[0].id) emit('changeTemp', res.rows[0].id)
@ -94,11 +96,18 @@ const changeTemplate = (val) => {
}) })
} }
emitter.on('onGetMain', () =>{
getTemplateList()
})
const onAdd = () => { const onAdd = () => {
wordDialog.value = true wordDialog.value = true
} }
onUnmounted(() => {
emitter.off('onGetMain')
})
onMounted(() => { onMounted(() => {
getTemplateList() getTemplateList()
}) })
@ -129,5 +138,4 @@ onMounted(() => {
font-weight: bold; font-weight: bold;
} }
} }
</style> </style>

View File

@ -2,18 +2,18 @@
<el-dialog v-model="mode" :show-close="false" width="600" destroy-on-close> <el-dialog v-model="mode" :show-close="false" width="600" destroy-on-close>
<template #header> <template #header>
<div class="custom-header flex"> <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> <i class="iconfont icon-guanbi" @click="mode = false"></i>
</div> </div>
</template> </template>
<div class="dialog-content" v-loading="loading"> <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 :model="form" label-width="auto">
<el-form-item label="名称"> <el-form-item label="名称">
<el-input v-model="form.name" /> <el-input v-model="form.name" />
</el-form-item> </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-input v-model="form.prompt" type="textarea" />
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -33,10 +33,9 @@
<script setup> <script setup>
import { ref, reactive, watch } from 'vue' import { ref, reactive, watch } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import emitter from '@/utils/mitt';
import { addKeyWords, addChildTemp, editChildTemp } from '@/api/mode/index' import { addKeyWords, addChildTemp, editChildTemp } from '@/api/mode/index'
const mode = defineModel() const mode = defineModel()
const props = defineProps({ const props = defineProps({
modeType: { modeType: {
@ -48,20 +47,25 @@ const props = defineProps({
default: true default: true
}, },
item: { // item: { //
type: Object type: Object,
}, default: () => {
temp: { // return { ex3: '' }
Object
} }
},
tempId: {
type: [String, Number],
default: ''
},
}) })
const form = reactive({ const form = reactive({
name: '', name: '',
prompt: '', prompt: '',
}) })
watch(() => props.isAdd, (newVal) => { watch(() => props.isAdd, (newVal) => {
console.log(newVal)
if (!newVal) { if (!newVal) {
form.name = props.item?.name form.name = props.item?.name
form.prompt = props.item?.prompt form.prompt = props.item?.prompt
@ -71,21 +75,52 @@ watch(() => props.isAdd, (newVal) => {
const loading = ref(false) const loading = ref(false)
const saveAdd = async () => { const saveAdd = async () => {
loading.value = true loading.value = true
if (props.item.ex3 == '1') {
if (props.isAdd) { if (props.isAdd) {
try { try {
var msg = null // copy
// const { msg } = await addKeyWords({ name: form.name, id: props.item.id })
if (props.item.ex3 == '1') { emitter.emit('onGetChild')
var { msg } = await addKeyWords({ name: form.name, id: props.item.id }) ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
}
} }
else{ else{
onAddChildTemp(props.item.parentId)
}
} else {
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 = { let obj = {
name: form.name, name: form.name,
type: 2, // 2 type: 2, // 2
sortNum: 1, sortNum: 1,
parentId: props.item.id, parentId,
lmType: 1, lmType: 1,
model: props.modeType, model: props.modeType,
prompt: form.prompt, prompt: form.prompt,
@ -93,27 +128,15 @@ const saveAdd = async () => {
ex2: props.item.ex2, // ex2: props.item.ex2, //
ex3: '', // ex3: '', //
} }
var { msg } = await addChildTemp(obj)
}
ElMessage.success(msg)
mode.value = false
} finally {
loading.value = false
}
} else {
//
try { try {
let data = JSON.parse(JSON.stringify(props.item)) var { msg } = await addChildTemp(obj)
data.name = form.name; emitter.emit('onGetChild')
data.prompt = form.prompt
const { msg } = await editChildTemp(data)
ElMessage.success(msg) ElMessage.success(msg)
mode.value = false mode.value = false
} finally { } finally {
loading.value = false loading.value = false
} }
} }
}
</script> </script>
@ -128,6 +151,7 @@ const saveAdd = async () => {
font-weight: bold; font-weight: bold;
} }
} }
.small-tip { .small-tip {
text-align: left; text-align: left;
font-size: 12px; font-size: 12px;

View File

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