重构流式配置弹窗,新增流式参数表单和验证逻辑,移除无用的模型类型组件

This commit is contained in:
2026-06-06 13:46:31 +08:00
parent 4a8bc3cb7a
commit fc54bcd3d6
2 changed files with 375 additions and 133 deletions

View File

@@ -241,14 +241,53 @@
</el-dialog> </el-dialog>
<!-- 流式配置弹窗 --> <!-- 流式配置弹窗 -->
<el-dialog v-model="showStreamConfigDialog" title="配置流式参数" width="600px" :close-on-click-modal="false"> <el-dialog v-model="showStreamConfigDialog" title="配置流式参数" width="760px" :close-on-click-modal="false">
<div class="stream-config-placeholder"> <el-form ref="streamConfigDialogFormRef" :model="streamConfigForm" :rules="streamConfigRules" label-width="0" class="stream-dialog-form">
流式配置表单内容待确定当前将按空对象提交 <div class="stream-dialog-panel">
<div class="stream-dialog-panel__row stream-dialog-panel__row--single">
<div class="stream-dialog-panel__label required">内容路径</div>
<el-form-item prop="targetContentPath" class="stream-dialog-panel__item stream-dialog-panel__item--full">
<el-input v-model="streamConfigForm.targetContentPath" placeholder="如 messages.0.content" clearable></el-input>
</el-form-item>
</div> </div>
</div>
<div class="stream-config-container">
<div v-for="templateKey in streamAttachmentTemplateKeys" :key="templateKey" class="stream-template-card">
<div class="stream-template-card__header">
<span class="stream-template-card__title">{{ templateKey }} 附件模板</span>
</div>
<div class="stream-template-grid">
<div class="stream-template-grid__label required">type</div>
<el-form-item
:prop="`${templateKey}Type`"
class="stream-template-grid__item stream-template-grid__item--full"
>
<el-input
v-model="streamConfigForm.attachmentTemplates[templateKey].type"
placeholder="请输入 type"
clearable
></el-input>
</el-form-item>
<div class="stream-template-grid__label required stream-template-grid__label--top">body</div>
<div class="stream-template-grid__item stream-template-grid__item--full">
<div class="stream-body-list">
<div v-for="(field, index) in streamConfigForm.attachmentTemplates[templateKey].bodyFields" :key="index" class="stream-body-row">
<el-input v-model="field.key" placeholder="请输入 body key" clearable class="stream-body-row__input"></el-input>
<span class="stream-body-row__separator">=</span>
<el-input v-model="field.value" placeholder="请输入 body value" clearable class="stream-body-row__input"></el-input>
<el-button type="danger" link class="stream-body-row__delete" @click="removeStreamBodyField(templateKey, index)">删除</el-button>
</div>
<el-button type="primary" link class="stream-body-list__add" @click="addStreamBodyField(templateKey)">+ 添加 body 字段</el-button>
</div>
</div>
</div>
</div>
</div>
</el-form>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="showStreamConfigDialog = false" size="default"> </el-button> <el-button @click="showStreamConfigDialog = false" size="default"> </el-button>
<el-button type="primary" @click="showStreamConfigDialog = false" size="default"> </el-button> <el-button type="primary" @click="validateAndConfirmStreamConfig" size="default"> </el-button>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
@@ -554,6 +593,20 @@ export interface ResponseMappingField extends KeyValueField {
isTokenField?: boolean; isTokenField?: boolean;
} }
export interface StreamAttachmentTemplateForm {
type: string;
bodyFields: KeyValueField[];
}
export interface StreamConfigForm {
targetContentPath: string;
attachmentTemplates: {
audio: StreamAttachmentTemplateForm;
image: StreamAttachmentTemplateForm;
video: StreamAttachmentTemplateForm;
};
}
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
modelTypes?: ModelTypeOption[]; modelTypes?: ModelTypeOption[];
@@ -587,6 +640,7 @@ const typeOptionValue = (id: number | string): number | string => {
}; };
const editModuleFormRef = ref(); const editModuleFormRef = ref();
const streamConfigDialogFormRef = ref();
const emit = defineEmits(['refresh']); const emit = defineEmits(['refresh']);
const showHeaderDialog = ref(false); const showHeaderDialog = ref(false);
const showAsyncQueryConfigDialog = ref(false); const showAsyncQueryConfigDialog = ref(false);
@@ -606,6 +660,29 @@ const asyncQueryConfigForm = reactive({
statusValueFields: [{ key: '', value: '' }] as Array<{ key: string; value: string }>, statusValueFields: [{ key: '', value: '' }] as Array<{ key: string; value: string }>,
}); });
const createEmptyStreamAttachmentTemplate = (): StreamAttachmentTemplateForm => ({
type: '',
bodyFields: [{ key: '', value: '' }],
});
const createEmptyStreamConfigForm = (): StreamConfigForm => ({
targetContentPath: '',
attachmentTemplates: {
audio: createEmptyStreamAttachmentTemplate(),
image: createEmptyStreamAttachmentTemplate(),
video: createEmptyStreamAttachmentTemplate(),
},
});
const streamConfigForm = reactive<StreamConfigForm>(createEmptyStreamConfigForm());
const streamConfigRules = {
targetContentPath: [{ required: true, message: '请输入内容路径', trigger: 'blur' }],
audioType: [{ required: true, message: '请输入 Audio 附件模板 type', trigger: 'blur' }],
imageType: [{ required: true, message: '请输入 Image 附件模板 type', trigger: 'blur' }],
videoType: [{ required: true, message: '请输入 Video 附件模板 type', trigger: 'blur' }],
};
const streamAttachmentTemplateKeys: Array<keyof StreamConfigForm['attachmentTemplates']> = ['audio', 'image', 'video'];
const state = reactive({ const state = reactive({
ruleForm: { ruleForm: {
id: '', id: '',
@@ -703,6 +780,50 @@ const state = reactive({
trigger: 'change', trigger: 'change',
}, },
], ],
streamConfig: [
{
validator: (_rule: unknown, _value: unknown, callback: (e?: Error) => void) => {
if (Number(state.ruleForm.callMode) !== 2) {
callback();
return;
}
if (!String(streamConfigForm.targetContentPath || '').trim()) {
callback(new Error('流式执行时,请填写内容路径'));
return;
}
const missingTemplateType = Object.entries(streamConfigForm.attachmentTemplates).some(
([, template]) => !String(template.type || '').trim()
);
if (missingTemplateType) {
callback(new Error('流式执行时,请完整填写所有附件模板 type'));
return;
}
const hasEmptyBodyTemplate = Object.entries(streamConfigForm.attachmentTemplates).some(([, template]) => {
const validRows = template.bodyFields.filter(
(item) => String(item.key || '').trim() !== '' && String(item.value || '').trim() !== ''
);
return validRows.length === 0;
});
if (hasEmptyBodyTemplate) {
callback(new Error('流式执行时,每个附件模板至少需要一个 body 字段'));
return;
}
const hasInvalidBodyField = Object.entries(streamConfigForm.attachmentTemplates).some(([, template]) =>
template.bodyFields.some(
(item) =>
(String(item.key || '').trim() === '' && String(item.value || '').trim() !== '') ||
(String(item.key || '').trim() !== '' && String(item.value || '').trim() === '')
)
);
if (hasInvalidBodyField) {
callback(new Error('附件模板 body 的键和值都必须完整填写'));
return;
}
callback();
},
trigger: 'change',
},
],
operatorName: [ operatorName: [
{ {
validator: (_rule: unknown, value: unknown, callback: (e?: Error) => void) => { validator: (_rule: unknown, value: unknown, callback: (e?: Error) => void) => {
@@ -1027,14 +1148,90 @@ const addAsyncQueryStatusValueField = () => {
asyncQueryConfigForm.statusValueFields.push({ key: '', value: '' }); asyncQueryConfigForm.statusValueFields.push({ key: '', value: '' });
}; };
const addStreamBodyField = (templateKey: keyof StreamConfigForm['attachmentTemplates']) => {
streamConfigForm.attachmentTemplates[templateKey].bodyFields.push({ key: '', value: '' });
};
const removeStreamBodyField = (templateKey: keyof StreamConfigForm['attachmentTemplates'], index: number) => {
const template = streamConfigForm.attachmentTemplates[templateKey];
if (template.bodyFields.length <= 1) {
template.bodyFields[0] = { key: '', value: '' };
return;
}
template.bodyFields.splice(index, 1);
};
const removeAsyncQueryStatusValueField = (index: number) => { const removeAsyncQueryStatusValueField = (index: number) => {
asyncQueryConfigForm.statusValueFields.splice(index, 1); asyncQueryConfigForm.statusValueFields.splice(index, 1);
}; };
const validateAndConfirmStreamConfig = async () => {
await streamConfigDialogFormRef.value?.validate?.();
await editModuleFormRef.value?.validateField?.('streamConfig');
showStreamConfigDialog.value = false;
};
const objectToFields = (obj: Record<string, unknown>) => { const objectToFields = (obj: Record<string, unknown>) => {
return Object.entries(obj).map(([key, value]) => ({ key, value: String(value ?? '') })); return Object.entries(obj).map(([key, value]) => ({ key, value: String(value ?? '') }));
}; };
const resetStreamConfigForm = () => {
const next = createEmptyStreamConfigForm();
streamConfigForm.targetContentPath = next.targetContentPath;
streamConfigForm.attachmentTemplates.audio.type = next.attachmentTemplates.audio.type;
streamConfigForm.attachmentTemplates.audio.bodyFields = next.attachmentTemplates.audio.bodyFields;
streamConfigForm.attachmentTemplates.image.type = next.attachmentTemplates.image.type;
streamConfigForm.attachmentTemplates.image.bodyFields = next.attachmentTemplates.image.bodyFields;
streamConfigForm.attachmentTemplates.video.type = next.attachmentTemplates.video.type;
streamConfigForm.attachmentTemplates.video.bodyFields = next.attachmentTemplates.video.bodyFields;
};
const applyStreamAttachmentTemplate = (template: StreamAttachmentTemplateForm, raw: unknown) => {
template.type = '';
template.bodyFields = [{ key: '', value: '' }];
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
return;
}
const rawTemplate = raw as Record<string, unknown>;
template.type = String(rawTemplate.type || '');
template.bodyFields = ensureKeyValueRows(parseFieldsUnified(rawTemplate.body), () => ({ key: '', value: '' }));
};
const applyStreamConfig = (raw: unknown) => {
resetStreamConfigForm();
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
return;
}
const streamConfig = raw as Record<string, unknown>;
streamConfigForm.targetContentPath = String(streamConfig.target_content_path || '');
const attachmentTemplates =
streamConfig.attachment_templates && typeof streamConfig.attachment_templates === 'object' && !Array.isArray(streamConfig.attachment_templates)
? (streamConfig.attachment_templates as Record<string, unknown>)
: {};
applyStreamAttachmentTemplate(streamConfigForm.attachmentTemplates.audio, attachmentTemplates.audio);
applyStreamAttachmentTemplate(streamConfigForm.attachmentTemplates.image, attachmentTemplates.image);
applyStreamAttachmentTemplate(streamConfigForm.attachmentTemplates.video, attachmentTemplates.video);
};
const buildStreamAttachmentTemplate = (template: StreamAttachmentTemplateForm) => ({
type: String(template.type || '').trim(),
body: fieldsToUnknownObject(template.bodyFields.filter((item) => String(item.key || '').trim() !== '')),
});
const buildStreamConfig = () => {
if (Number(state.ruleForm.callMode) !== 2) {
return undefined;
}
return {
target_content_path: String(streamConfigForm.targetContentPath || '').trim(),
attachment_templates: {
audio: buildStreamAttachmentTemplate(streamConfigForm.attachmentTemplates.audio),
image: buildStreamAttachmentTemplate(streamConfigForm.attachmentTemplates.image),
video: buildStreamAttachmentTemplate(streamConfigForm.attachmentTemplates.video),
},
};
};
const buildQueryConfig = () => { const buildQueryConfig = () => {
if (Number(state.ruleForm.callMode) === 1) { if (Number(state.ruleForm.callMode) === 1) {
return buildAsyncQueryConfig(); return buildAsyncQueryConfig();
@@ -1371,6 +1568,8 @@ const fillFormFromDetailRow = (row: Record<string, unknown>) => {
asyncQueryConfigForm.intervalSeconds = 2; asyncQueryConfigForm.intervalSeconds = 2;
asyncQueryConfigForm.statusValueFields = [{ key: '', value: '' }]; asyncQueryConfigForm.statusValueFields = [{ key: '', value: '' }];
} }
applyStreamConfig(row.streamConfig);
}; };
// 打开弹窗(编辑时会请求 /model/getModel 详情) // 打开弹窗(编辑时会请求 /model/getModel 详情)
const openDialog = async (type: string, row?: Record<string, unknown>) => { const openDialog = async (type: string, row?: Record<string, unknown>) => {
@@ -1451,6 +1650,7 @@ const openDialog = async (type: string, row?: Record<string, unknown>) => {
asyncQueryConfigForm.statusPath = ''; asyncQueryConfigForm.statusPath = '';
asyncQueryConfigForm.intervalSeconds = 2; asyncQueryConfigForm.intervalSeconds = 2;
asyncQueryConfigForm.statusValueFields = [{ key: '', value: '' }]; asyncQueryConfigForm.statusValueFields = [{ key: '', value: '' }];
resetStreamConfigForm();
state.dialog.title = '新增模型配置'; state.dialog.title = '新增模型配置';
state.dialog.submitTxt = '新 增'; state.dialog.submitTxt = '新 增';
} }
@@ -1479,6 +1679,9 @@ const onSubmit = () => {
if (Number(state.ruleForm.callMode) === 1) { if (Number(state.ruleForm.callMode) === 1) {
await editModuleFormRef.value?.validateField?.('asyncQueryConfig'); await editModuleFormRef.value?.validateField?.('asyncQueryConfig');
} }
if (Number(state.ruleForm.callMode) === 2) {
await editModuleFormRef.value?.validateField?.('streamConfig');
}
// 验证响应映射(如果有配置) // 验证响应映射(如果有配置)
const validResponseFields = state.responseMappingFields.filter((x) => String(x.key || '').trim() !== ''); const validResponseFields = state.responseMappingFields.filter((x) => String(x.key || '').trim() !== '');
@@ -1572,7 +1775,7 @@ const onSubmit = () => {
responseTokenField, responseTokenField,
tokenConfig: fieldsToUnknownObject(state.tokenConfigFields.filter((f) => String(f.key || '').trim() !== '')), tokenConfig: fieldsToUnknownObject(state.tokenConfigFields.filter((f) => String(f.key || '').trim() !== '')),
queryConfig: buildQueryConfig(), queryConfig: buildQueryConfig(),
streamConfig: Number(state.ruleForm.callMode) === 2 ? {} : undefined, streamConfig: buildStreamConfig(),
}; };
if (state.dialog.type === 'edit') { if (state.dialog.type === 'edit') {
@@ -1718,6 +1921,172 @@ onMounted(() => {
} }
} }
.stream-dialog-form {
padding-top: 4px;
}
.stream-dialog-panel {
padding: 14px 16px;
border: 1px solid #ebeef5;
border-radius: 8px;
background: #fcfcfd;
margin-bottom: 14px;
&__row {
display: grid;
grid-template-columns: 96px minmax(0, 1fr);
align-items: start;
column-gap: 12px;
row-gap: 6px;
}
&__label {
height: 32px;
line-height: 32px;
font-size: 13px;
color: #606266;
padding-top: 1px;
&.required::before {
content: '*';
color: #f56c6c;
margin-right: 4px;
}
}
&__item {
margin-bottom: 2px;
:deep(.el-form-item__content) {
line-height: 32px;
}
}
&__item--full {
width: 100%;
}
}
.stream-config-container {
display: flex;
flex-direction: column;
gap: 12px;
}
.stream-template-card {
padding: 14px 16px;
border: 1px solid #ebeef5;
border-radius: 8px;
background: #fcfcfd;
&__header {
margin-bottom: 10px;
}
&__title {
font-size: 14px;
font-weight: 600;
color: #303133;
text-transform: capitalize;
}
}
.stream-template-grid {
display: grid;
grid-template-columns: 96px minmax(0, 1fr);
column-gap: 12px;
row-gap: 10px;
align-items: start;
&__label {
height: 32px;
line-height: 32px;
font-size: 13px;
color: #606266;
padding-top: 1px;
&.required::before {
content: '*';
color: #f56c6c;
margin-right: 4px;
}
}
&__label--top {
padding-top: 2px;
height: auto;
line-height: 20px;
}
&__item {
margin-bottom: 2px;
:deep(.el-form-item__content) {
line-height: 32px;
}
}
&__item--full {
width: 100%;
}
}
.stream-body-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.stream-body-row {
display: grid;
grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr) 44px;
column-gap: 8px;
align-items: center;
&__input {
width: 100%;
}
&__separator {
text-align: center;
font-weight: 600;
color: #606266;
}
&__delete {
justify-self: end;
padding: 0;
}
}
.stream-body-list__add {
align-self: flex-start;
padding: 0;
}
:deep(.stream-dialog-form .el-input__wrapper) {
min-height: 32px;
}
:deep(.stream-dialog-form .el-input__inner) {
height: 32px;
}
:deep(.stream-dialog-form .el-form-item) {
margin-bottom: 0;
}
:deep(.stream-dialog-form .el-form-item__content) {
display: block;
}
:deep(.stream-dialog-form .el-form-item__error) {
position: static;
padding-top: 4px;
line-height: 1.2;
white-space: normal;
}
.ml5 { .ml5 {
margin-left: 5px; margin-left: 5px;
} }

View File

@@ -1,127 +0,0 @@
<template>
<div class="system-model-type-container layout-padding">
<el-card shadow="hover" class="layout-padding-auto">
<div class="system-model-type-search mb15">
<el-input v-model="state.tableData.param.keyword" size="default" placeholder="请输入模型类型名称" style="max-width: 180px" clearable> </el-input>
<el-button size="default" type="primary" class="ml10" @click="getTableData">
<el-icon>
<ele-Search />
</el-icon>
查询
</el-button>
<el-button size="default" type="success" class="ml10" @click="onOpenAddType('add')">
<el-icon>
<ele-FolderAdd />
</el-icon>
新增模型类型
</el-button>
</div>
<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
<el-table-column type="index" label="序号" width="60" />
<el-table-column prop="typeName" label="类型名称" show-overflow-tooltip></el-table-column>
<el-table-column prop="typeCode" label="类型编码" show-overflow-tooltip></el-table-column>
<el-table-column prop="description" label="描述" show-overflow-tooltip></el-table-column>
<el-table-column prop="status" label="状态" width="100">
<template #default="scope">
<el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">{{ scope.row.status === 1 ? '启用' : '禁用' }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建时间" show-overflow-tooltip></el-table-column>
<el-table-column label="操作" width="200">
<template #default="scope">
<el-button size="small" text type="primary" @click="onOpenEditType('edit', scope.row)">修改</el-button>
<el-button size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="onHandleSizeChange"
@current-change="onHandleCurrentChange"
class="mt15"
:pager-count="5"
:page-sizes="[10, 20, 30]"
v-model:current-page="state.tableData.param.pageNum"
background
v-model:page-size="state.tableData.param.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="state.tableData.total"
>
</el-pagination>
</el-card>
</div>
</template>
<script setup lang="ts" name="digitalHumanModelType">
import { reactive, onMounted } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
const state = reactive({
tableData: {
data: [],
total: 0,
loading: false,
param: {
pageNum: 1,
pageSize: 10,
keyword: '',
},
},
});
// 初始化表格数据
const getTableData = () => {
state.tableData.loading = true;
// TODO: 调用API获取数据
setTimeout(() => {
state.tableData.data = [];
state.tableData.total = 0;
state.tableData.loading = false;
}, 500);
};
// 打开新增模型类型弹窗
const onOpenAddType = (type: string) => {
ElMessage.info('功能开发中...');
};
// 打开修改模型类型弹窗
const onOpenEditType = (type: string, row: any) => {
ElMessage.info('功能开发中...');
};
// 删除模型类型
const onRowDel = (row: any) => {
ElMessage.info('功能开发中...');
};
// 分页改变
const onHandleSizeChange = (val: number) => {
state.tableData.param.pageSize = val;
getTableData();
};
// 分页改变
const onHandleCurrentChange = (val: number) => {
state.tableData.param.pageNum = val;
getTableData();
};
// 页面加载时
onMounted(() => {
getTableData();
});
</script>
<style scoped lang="scss">
.system-model-type-container {
:deep(.el-card__body) {
display: flex;
flex-direction: column;
flex: 1;
overflow: auto;
.el-table {
flex: 1;
}
}
}
</style>