From 595a338de73affa67cbaef80f1ed0ce9794482fe Mon Sep 17 00:00:00 2001 From: Sakura-RanChen <1908198662@qq.com> Date: Tue, 20 May 2025 16:57:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0fastgpt=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E6=90=9C=E7=B4=A2=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E4=B8=8B=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-web/src/components/HeaderBar.vue | 6 ++ .../src/components/ModelEditDialog.vue | 58 +++++++++++++++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/main/manager-web/src/components/HeaderBar.vue b/main/manager-web/src/components/HeaderBar.vue index 842441ce..b7b859dc 100644 --- a/main/manager-web/src/components/HeaderBar.vue +++ b/main/manager-web/src/components/HeaderBar.vue @@ -322,6 +322,12 @@ export default { line-height: 30px; } +.custom-search-input::v-deep .el-input__suffix-inner { + display: flex; + align-items: center; + height: 100%; +} + .avatar-img { width: 21px; height: 21px; diff --git a/main/manager-web/src/components/ModelEditDialog.vue b/main/manager-web/src/components/ModelEditDialog.vue index 8eebd8d0..35307d42 100644 --- a/main/manager-web/src/components/ModelEditDialog.vue +++ b/main/manager-web/src/components/ModelEditDialog.vue @@ -66,8 +66,12 @@
- + + + +
@@ -112,6 +116,7 @@ export default { pendingProviderType: null, pendingModelData: null, dynamicCallInfoFields: [], + variablesJson: '', form: { id: "", modelType: "", @@ -173,7 +178,8 @@ export default { docLink: "", remark: "", sort: 0, - configJson: {} + configJson: {}, + variablesJson: {}, }; this.dynamicCallInfoFields.forEach(field => { this.$set(this.form.configJson, field.prop, ''); @@ -203,6 +209,16 @@ export default { handleSave() { this.saving = true; // 开始保存加载 + // 确保 variables 是字典 + if (typeof this.form.configJson.variables === 'string') { + const parsed = this.validateVariablesJson(this.form.configJson.variables); + if (parsed === null) { + this.saving = false; + return; + } + this.form.configJson.variables = parsed; + } + const provideCode = this.form.configJson.type; const formData = { id: this.modelData.id, @@ -255,7 +271,7 @@ export default { this.dynamicCallInfoFields = JSON.parse(provider.fields || '[]').map(f => ({ label: f.label, prop: f.key, - type: f.type === 'password' ? 'password' : 'text', + type: f.key === 'variables' ? 'json-textarea' : (f.type === 'password' ? 'password' : 'text'), placeholder: `请输入${f.label}` })); @@ -272,7 +288,7 @@ export default { this.dynamicCallInfoFields.forEach(field => { if (!configJson.hasOwnProperty(field.prop)) { configJson[field.prop] = ''; - } else if (typeof configJson[field.prop] !== 'string') { + } else if (field.prop !== 'variables' && typeof configJson[field.prop] !== 'string') { configJson[field.prop] = String(configJson[field.prop]); } }); @@ -291,6 +307,38 @@ export default { ...configJson } }; + // 读出时的JSON转换 + if (this.form.configJson.variables) { + this.variablesJson = JSON.stringify(this.form.configJson.variables, null, 2) + } + }, + + // 输入监听 + handleVariablesChange(value) { + const parsed = this.validateVariablesJson(value); + if (parsed !== null) this.form.configJson.variables = parsed; + }, + + // 数据校验 + validateVariablesJson(value) { + try { + const parsed = JSON.parse(value); + // 校验是否为非空字典 + if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) { + return parsed; + } + this.$message.error({ + message: '必须输入字典格式(如 {"key":"value"}),保存则保留原数据', + showClose: true + }); + return null; + } catch (e) { + this.$message.error({ + message: 'JSON格式错误(如 {"key":"value"}),保存则保留原数据', + showClose: true + }); + return null; + } } } };