Merge pull request #742 from xinnan-tech/web-vue-modify

fix:修复“模型配置编辑”功能
This commit is contained in:
hrz
2025-04-12 17:33:28 +08:00
committed by GitHub
@@ -95,23 +95,11 @@
import Api from '@/apis/api'; import Api from '@/apis/api';
const DEFAULT_CONFIG_JSON = { const DEFAULT_CONFIG_JSON = {
type: "", type: "",
base_url: "", base_url: "",
model_name: "", model_name: "",
api_key: "", api_key: "",
raw: {}, empty: false
config: {
keyComparator: {},
ignoreError: false,
ignoreCase: false,
dateFormat: "",
ignoreNullValue: false,
transientSupport: false,
stripTrailingZeros: false,
checkDuplicate: false,
order: false
},
empty: false
}; };
export default { export default {
@@ -185,60 +173,54 @@ export default {
}, },
methods: { methods: {
resetForm() { resetForm() {
this.form = { this.form = {
id: "", id: "",
modelType: "", modelType: "",
modelCode: "", modelCode: "",
modelName: "", modelName: "",
isDefault: false, isDefault: false,
isEnabled: false, isEnabled: false,
docLink: "", docLink: "",
remark: "", remark: "",
sort: "", sort: 0,
configJson: JSON.parse(JSON.stringify(DEFAULT_CONFIG_JSON)) configJson: JSON.parse(JSON.stringify(DEFAULT_CONFIG_JSON))
}; };
}, },
resetProviders() { resetProviders() {
this.providers = []; this.providers = [];
this.providersLoaded = false; this.providersLoaded = false;
}, },
loadModelData() { loadModelData() {
if (this.modelData.id) { if (this.modelData.id) {
Api.model.getModelConfig(this.modelData.id, ({ data }) => { Api.model.getModelConfig(this.modelData.id, ({ data }) => {
if (data.code === 0 && data.data) { if (data.code === 0 && data.data) {
const model = data.data; const model = data.data;
this.pendingProviderType = model.configJson.type; this.pendingProviderType = model.configJson.type;
this.pendingModelData = model; this.pendingModelData = model;
if (this.providersLoaded) { if (this.providersLoaded) {
this.loadProviderFields(model.configJson.type); this.loadProviderFields(model.configJson.type);
} else { } else {
this.loadProviders(); this.loadProviders();
} }
} }
}); });
} }
}, },
handleSave() { handleSave() {
const provideCode = this.form.configJson.type; const provideCode = this.form.configJson.type;
const { provider, ...restConfigJson } = this.form.configJson; const formData = {
const formData = { id: this.modelData.id,
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, isEnabled: this.form.isEnabled ? 1 : 0,
isEnabled: this.form.isEnabled ? 1 : 0, docLink: this.form.docLink,
docLink: this.form.docLink, remark: this.form.remark,
remark: this.form.remark, sort: this.form.sort || 0,
sort: this.form.sort || 0, configJson: {
configJson: { ...this.form.configJson,
...restConfigJson,
config: {
...restConfigJson.config,
ignoreError: !!restConfigJson.config?.ignoreError,
ignoreCase: !!restConfigJson.config?.ignoreCase,
} }
}
}; };
this.$emit("save", { provideCode, formData }); this.$emit("save", { provideCode, formData });
this.dialogVisible = false; this.dialogVisible = false;
@@ -249,7 +231,7 @@ export default {
Api.model.getModelProviders(this.modelType, (data) => { Api.model.getModelProviders(this.modelType, (data) => {
this.providers = data.map(item => ({ this.providers = data.map(item => ({
label: item.name, label: item.name,
value: item.providerCode value: String(item.providerCode)
})); }));
this.providersLoaded = true; this.providersLoaded = true;
@@ -288,26 +270,21 @@ export default {
}); });
this.form = { this.form = {
id: model.id || "", id: model.id,
modelType: model.modelType || "", modelType: model.modelType,
modelCode: model.modelCode || "", modelCode: model.modelCode,
modelName: model.modelName || "", modelName: model.modelName,
isDefault: model.isDefault || 0, isDefault: model.isDefault,
isEnabled: model.isEnabled || 0, isEnabled: model.isEnabled,
docLink: model.docLink || "", docLink: model.docLink,
remark: model.remark || "", remark: model.remark,
sort: Number(model.sort) || 0, sort: Number(model.sort) || 0,
configJson: { configJson: {
...JSON.parse(JSON.stringify(DEFAULT_CONFIG_JSON)), ...DEFAULT_CONFIG_JSON,
...configJson, ...configJson
config: {
...DEFAULT_CONFIG_JSON.config,
...(configJson.config || {})
}
} }
}; };
} }
} }
}; };
</script> </script>