fix:修复了"模型配置"问题

This commit is contained in:
CGD
2025-04-12 22:53:41 +08:00
parent 5d69ba0796
commit e3928ffbcc
2 changed files with 25 additions and 26 deletions
+18 -15
View File
@@ -1,7 +1,6 @@
import { getServiceUrl } from '../api'; import { getServiceUrl } from '../api';
import RequestService from '../httpRequest'; import RequestService from '../httpRequest';
export default { export default {
// 获取模型配置列表 // 获取模型配置列表
getModelList(params, callback) { getModelList(params, callback) {
@@ -162,21 +161,25 @@ export default {
// 更新模型配置 // 更新模型配置
updateModel(params, callback) { updateModel(params, callback) {
const { modelType, provideCode, id, formData } = params; const { modelType, provideCode, id, formData } = params;
const payload = {
...formData,
configJson: formData.configJson
};
RequestService.sendRequest() RequestService.sendRequest()
.url(`${getServiceUrl()}/models/${modelType}/${provideCode}/${id}`) .url(`${getServiceUrl()}/models/${modelType}/${provideCode}/${id}`)
.method('PUT') .method('PUT')
.data(formData) .data(payload)
.success((res) => { .success((res) => {
RequestService.clearRequestTime(); RequestService.clearRequestTime();
callback(res); callback(res);
}) })
.fail((err) => { .fail((err) => {
console.error('更新模型失败:', err); console.error('更新模型失败:', err);
this.$message.error(err.msg || '更新模型失败'); this.$message.error(err.msg || '更新模型失败');
RequestService.reAjaxFun(() => { RequestService.reAjaxFun(() => {
this.updateModel(params, callback); this.updateModel(params, callback);
}); });
}).send(); }).send();
}, },
// 设置默认模型 // 设置默认模型
setDefaultModel(id, callback) { setDefaultModel(id, callback) {
@@ -94,14 +94,6 @@
<script> <script>
import Api from '@/apis/api'; import Api from '@/apis/api';
const DEFAULT_CONFIG_JSON = {
type: "",
base_url: "",
model_name: "",
api_key: "",
empty: false
};
export default { export default {
name: "ModelEditDialog", name: "ModelEditDialog",
props: { props: {
@@ -132,7 +124,7 @@ export default {
docLink: "", docLink: "",
remark: "", remark: "",
sort: 0, sort: 0,
configJson: JSON.parse(JSON.stringify(DEFAULT_CONFIG_JSON)) configJson: {}
} }
}; };
}, },
@@ -183,8 +175,11 @@ export default {
docLink: "", docLink: "",
remark: "", remark: "",
sort: 0, sort: 0,
configJson: JSON.parse(JSON.stringify(DEFAULT_CONFIG_JSON)) configJson: {}
}; };
this.dynamicCallInfoFields.forEach(field => {
this.$set(this.form.configJson, field.prop, '');
});
}, },
resetProviders() { resetProviders() {
this.providers = []; this.providers = [];
@@ -266,6 +261,8 @@ export default {
this.dynamicCallInfoFields.forEach(field => { this.dynamicCallInfoFields.forEach(field => {
if (!configJson.hasOwnProperty(field.prop)) { if (!configJson.hasOwnProperty(field.prop)) {
configJson[field.prop] = ''; configJson[field.prop] = '';
} else if (typeof configJson[field.prop] !== 'string') {
configJson[field.prop] = String(configJson[field.prop]);
} }
}); });
@@ -280,7 +277,6 @@ export default {
remark: model.remark, remark: model.remark,
sort: Number(model.sort) || 0, sort: Number(model.sort) || 0,
configJson: { configJson: {
...DEFAULT_CONFIG_JSON,
...configJson ...configJson
} }
}; };