新增模型会话开关功能和Token映射字段

- 在模型模块中添加更新会话模型状态的API,支持会话模型的管理。
- 更新模型选择器,保存模型的表单数据和响应体,提升用户体验。
- 在编辑模块中新增Token映射字段,增强模型配置的灵活性。
- 优化会话模型开关的逻辑,确保状态切换后能正确更新列表数据。
This commit is contained in:
2026-05-11 21:06:35 +08:00
parent 29838b030f
commit c7152f5d92
4 changed files with 66 additions and 99 deletions

View File

@@ -145,6 +145,11 @@
</el-button>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
<el-form-item label="Token映射" prop="tokenMapping">
<el-input v-model="state.ruleForm.tokenMapping" placeholder="请输入Token映射" clearable></el-input>
</el-form-item>
</el-col>
</el-row>
</el-collapse-transition>
</el-form>
@@ -220,12 +225,7 @@
<el-input v-model="field.key" placeholder="请输入字段名 (Key)" style="width: 30%" clearable></el-input>
<span class="separator">=</span>
<el-input v-model="field.value" placeholder="请输入字段值 (Value)" style="width: 30%" clearable></el-input>
<el-button
:type="field.isMainBody ? 'success' : 'primary'"
:plain="!field.isMainBody"
@click="setMainBody(index)"
size="small"
>
<el-button :type="field.isMainBody ? 'success' : 'primary'" :plain="!field.isMainBody" @click="setMainBody(index)" size="small">
{{ field.isMainBody ? '✓ 返回主体' : '设置返回主体' }}
</el-button>
<el-button type="danger" link @click="removeResponseMappingField(index)">删除</el-button>
@@ -291,6 +291,7 @@ const state = reactive({
retryQueueMaxSeconds: 60,
autoCleanSeconds: 300,
remark: '',
tokenMapping: '',
},
rules: {
modelName: [{ required: true, message: '请输入模型名称', trigger: 'blur' }],
@@ -490,7 +491,7 @@ const ensureKeyValueRows = (rows: Array<{ key: string; value: string }>) => (row
const ensureResponseMappingRows = (rows: Array<{ key: string; value: string; isMainBody?: boolean }>) => {
if (!rows.length) return [{ key: '', value: '', isMainBody: false }];
return rows.map(row => ({ ...row, isMainBody: row.isMainBody || false }));
return rows.map((row) => ({ ...row, isMainBody: row.isMainBody || false }));
};
/** 从 getModel 返回的 data 中取出单条模型对象 */
@@ -539,18 +540,19 @@ const fillFormFromDetailRow = (row: Record<string, unknown>) => {
retryQueueMaxSeconds: Number(row.retryQueueMaxSeconds ?? 60),
autoCleanSeconds: Number(row.autoCleanSeconds ?? 300),
remark: String(row.remark || ''),
tokenMapping: String(row.tokenMapping || ''),
};
state.headers = ensureKeyValueRows(parseHeaders(String(row.headMsg || '')));
state.formFields = ensureKeyValueRows(parseFormFields(row.form));
// 解析请求映射和响应映射
state.requestMappingFields = ensureKeyValueRows(parseRequestMappingFields(row.requestMapping));
state.responseMappingFields = ensureResponseMappingRows(parseResponseMappingFields(row.responseMapping));
// 根据 responseBody 字段设置返回主体标记 (responseBody 是对象 {key: value})
if (row.responseBody && typeof row.responseBody === 'object') {
const responseBodyKey = Object.keys(row.responseBody)[0];
if (responseBodyKey) {
const mainBodyIndex = state.responseMappingFields.findIndex(f => f.key === responseBodyKey);
const mainBodyIndex = state.responseMappingFields.findIndex((f) => f.key === responseBodyKey);
if (mainBodyIndex !== -1) {
state.responseMappingFields[mainBodyIndex].isMainBody = true;
state.mainBodyIndex = mainBodyIndex;
@@ -615,6 +617,7 @@ const openDialog = async (type: string, row?: Record<string, unknown>) => {
retryQueueMaxSeconds: 60,
autoCleanSeconds: 300,
remark: '',
tokenMapping: '',
};
state.headers = [{ key: '', value: '' }];
state.formFields = [{ key: '', value: '' }];
@@ -648,7 +651,7 @@ const onSubmit = () => {
const requestMapping = fieldsToObject(state.requestMappingFields);
const responseMapping = fieldsToObject(state.responseMappingFields);
// 获取被设置为返回主体的字段 {key: value}
const responseBodyField = state.responseMappingFields.find(f => f.isMainBody);
const responseBodyField = state.responseMappingFields.find((f) => f.isMainBody);
const responseBody = responseBodyField ? { [responseBodyField.key.trim()]: responseBodyField.value } : {};
const submitData = {
modelName: state.ruleForm.modelName,
@@ -672,6 +675,7 @@ const onSubmit = () => {
retryQueueMaxSeconds: state.ruleForm.retryQueueMaxSeconds,
autoCleanSeconds: state.ruleForm.autoCleanSeconds,
remark: state.ruleForm.remark || '',
tokenMapping: state.ruleForm.tokenMapping || '',
};
if (state.dialog.type === 'edit') {
@@ -743,50 +747,3 @@ defineExpose({
color: #606266;
}
</style>