完成“编辑模型配置”功能开发

This commit is contained in:
CGD
2025-04-08 10:53:59 +08:00
parent 024468adbd
commit 710b338e6d
4 changed files with 47 additions and 12 deletions
+19 -1
View File
@@ -159,5 +159,23 @@ export default {
}) })
}).send() }).send()
}, },
// 更新模型配置
updateModel(params, callback) {
const { modelType, provideCode, id, formData } = params;
RequestService.sendRequest()
.url(`${getServiceUrl()}/models/${modelType}/${provideCode}/${id}`)
.method('PUT')
.data(formData)
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.fail((err) => {
console.error('更新模型失败:', err);
this.$message.error(err.msg || '更新模型失败');
RequestService.reAjaxFun(() => {
this.updateModel(params, callback);
});
}).send();
},
} }
@@ -94,7 +94,6 @@
import Api from '@/apis/api'; import Api from '@/apis/api';
const DEFAULT_CONFIG_JSON = { const DEFAULT_CONFIG_JSON = {
provider: "",
type: "", type: "",
base_url: "", base_url: "",
model_name: "", model_name: "",
@@ -102,8 +101,8 @@ const DEFAULT_CONFIG_JSON = {
raw: {}, raw: {},
config: { config: {
keyComparator: {}, keyComparator: {},
ignoreError: 0, ignoreError: false,
ignoreCase: 0, ignoreCase: false,
dateFormat: "", dateFormat: "",
ignoreNullValue: false, ignoreNullValue: false,
transientSupport: false, transientSupport: false,
@@ -267,7 +266,10 @@ export default {
} }
}, },
handleSave() { handleSave() {
const provideCode = this.form.configJson.type;
const { provider, ...restConfigJson } = this.form.configJson;
const formData = { const formData = {
id: this.form.id,
modelCode: this.form.modelCode, modelCode: this.form.modelCode,
modelName: this.form.modelName, modelName: this.form.modelName,
isDefault: this.form.isDefault ? 1 : 0, isDefault: this.form.isDefault ? 1 : 0,
@@ -276,12 +278,15 @@ export default {
remark: this.form.remark, remark: this.form.remark,
sort: this.form.sort || 0, sort: this.form.sort || 0,
configJson: { configJson: {
...this.form.configJson, ...restConfigJson,
type: this.form.configJson.type || this.modelType config: {
...restConfigJson.config,
ignoreError: !!restConfigJson.config?.ignoreError,
ignoreCase: !!restConfigJson.config?.ignoreCase,
}
} }
}; };
this.$emit("save", { provideCode, formData });
this.$emit("save", formData);
this.dialogVisible = false; this.dialogVisible = false;
}, },
loadProviders() { loadProviders() {
+15 -3
View File
@@ -301,9 +301,21 @@ export default {
// TODO: 导出配置 // TODO: 导出配置
console.log('导出配置'); console.log('导出配置');
}, },
handleModelSave(formData) { handleModelSave({ provideCode, formData }) {
// TODO: 保存模型数据 const modelType = this.activeTab;
console.log('保存的模型数据:', formData); const id = formData.id;
Api.model.updateModel(
{ modelType, provideCode, id, formData },
({ data }) => {
if (data.code === 0) {
this.$message.success('保存成功');
this.loadData();
this.editDialogVisible = false;
} else {
this.$message.error(data.msg || '保存失败');
}
}
);
}, },
selectAll() { selectAll() {
if (this.isAllSelected) { if (this.isAllSelected) {