From 90dcda1475ded63a3f0a779f42bb8aea09aaf968 Mon Sep 17 00:00:00 2001
From: Ruochen <1051989940@qq.com>
Date: Wed, 18 Jun 2025 23:41:07 +0800
Subject: [PATCH 1/2] =?UTF-8?q?feat:=E5=9C=A8=E7=94=A8=E6=88=B7=E6=9C=AA?=
=?UTF-8?q?=E4=B8=BA=E6=9C=8D=E5=8A=A1=E5=95=86=E9=85=8D=E7=BD=AEkey?=
=?UTF-8?q?=E6=97=B6=E6=B7=BB=E5=8A=A0=E4=BA=8C=E6=AC=A1=E8=AD=A6=E5=91=8A?=
=?UTF-8?q?=E7=A1=AE=E8=AE=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dashboard/src/views/ProviderPage.vue | 89 ++++++++++++++++++++--------
1 file changed, 65 insertions(+), 24 deletions(-)
diff --git a/dashboard/src/views/ProviderPage.vue b/dashboard/src/views/ProviderPage.vue
index e807af287..abae10aef 100644
--- a/dashboard/src/views/ProviderPage.vue
+++ b/dashboard/src/views/ProviderPage.vue
@@ -306,6 +306,24 @@
+
+
+
+
+
+ mdi-alert-circle-outline
+ 确认保存
+
+
+ 您没有填写 API Key,确定要保存吗?这可能会导致该服务提供商无法正常工作。
+
+
+
+ 取消
+ 确定
+
+
+
@@ -336,6 +354,10 @@ export default {
sessionSeparationEnabled: false,
sessionSettingLoading: false,
+ // Key确认对话框
+ showKeyConfirm: false,
+ keyConfirmResolve: null,
+
newSelectedProviderName: '',
newSelectedProviderConfig: {},
updatingMode: false,
@@ -563,32 +585,37 @@ export default {
this.updatingMode = true;
},
- newProvider() {
+ async newProvider() {
+ // 检查 key 是否为空
+ if (
+ 'key' in this.newSelectedProviderConfig &&
+ (!this.newSelectedProviderConfig.key || this.newSelectedProviderConfig.key.length === 0)
+ ) {
+ const confirmed = await this.confirmEmptyKey();
+ if (!confirmed) {
+ return; // 如果用户取消,则中止保存
+ }
+ }
+
this.loading = true;
- if (this.updatingMode) {
- axios.post('/api/config/provider/update', {
- id: this.newSelectedProviderName,
- config: this.newSelectedProviderConfig
- }).then((res) => {
- this.loading = false;
- this.showProviderCfg = false;
- this.getConfig();
+ try {
+ if (this.updatingMode) {
+ const res = await axios.post('/api/config/provider/update', {
+ id: this.newSelectedProviderName,
+ config: this.newSelectedProviderConfig
+ });
this.showSuccess(res.data.message || "更新成功!");
- }).catch((err) => {
- this.loading = false;
- this.showError(err.response?.data?.message || err.message);
- });
- this.updatingMode = false;
- } else {
- axios.post('/api/config/provider/new', this.newSelectedProviderConfig).then((res) => {
- this.loading = false;
- this.showProviderCfg = false;
- this.getConfig();
+ this.updatingMode = false;
+ } else {
+ const res = await axios.post('/api/config/provider/new', this.newSelectedProviderConfig);
this.showSuccess(res.data.message || "添加成功!");
- }).catch((err) => {
- this.loading = false;
- this.showError(err.response?.data?.message || err.message);
- });
+ }
+ this.showProviderCfg = false;
+ this.getConfig();
+ } catch (err) {
+ this.showError(err.response?.data?.message || err.message);
+ } finally {
+ this.loading = false;
}
},
@@ -670,7 +697,21 @@ export default {
this.loadingStatus = false;
this.showError(err.response?.data?.message || err.message);
});
- }
+ },
+
+ confirmEmptyKey() {
+ this.showKeyConfirm = true;
+ return new Promise((resolve) => {
+ this.keyConfirmResolve = resolve;
+ });
+ },
+
+ handleKeyConfirm(confirmed) {
+ if (this.keyConfirmResolve) {
+ this.keyConfirmResolve(confirmed);
+ }
+ this.showKeyConfirm = false;
+ },
}
}
From 65428aa49fadcbdacf6f4b784fbf57e4893893c7 Mon Sep 17 00:00:00 2001
From: Ruochen <1051989940@qq.com>
Date: Wed, 18 Jun 2025 23:58:09 +0800
Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=9C=8D?=
=?UTF-8?q?=E5=8A=A1=E5=95=86=E4=BF=9D=E5=AD=98=E6=B5=81=E7=A8=8B=EF=BC=8C?=
=?UTF-8?q?=E5=B9=B6=E4=BF=AE=E5=A4=8DUI=E7=8A=B6=E6=80=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dashboard/src/views/ProviderPage.vue | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/dashboard/src/views/ProviderPage.vue b/dashboard/src/views/ProviderPage.vue
index abae10aef..683085eb8 100644
--- a/dashboard/src/views/ProviderPage.vue
+++ b/dashboard/src/views/ProviderPage.vue
@@ -405,6 +405,16 @@ export default {
}
},
+ watch: {
+ showKeyConfirm(newValue) {
+ // 当对话框关闭时,如果 Promise 还在等待,则拒绝它以防止内存泄漏
+ if (!newValue && this.keyConfirmResolve) {
+ this.keyConfirmResolve(false);
+ this.keyConfirmResolve = null;
+ }
+ }
+ },
+
computed: {
// 根据选择的标签过滤提供商列表
filteredProviders() {
@@ -598,14 +608,14 @@ export default {
}
this.loading = true;
+ const wasUpdating = this.updatingMode;
try {
- if (this.updatingMode) {
+ if (wasUpdating) {
const res = await axios.post('/api/config/provider/update', {
id: this.newSelectedProviderName,
config: this.newSelectedProviderConfig
});
this.showSuccess(res.data.message || "更新成功!");
- this.updatingMode = false;
} else {
const res = await axios.post('/api/config/provider/new', this.newSelectedProviderConfig);
this.showSuccess(res.data.message || "添加成功!");
@@ -616,6 +626,9 @@ export default {
this.showError(err.response?.data?.message || err.message);
} finally {
this.loading = false;
+ if (wasUpdating) {
+ this.updatingMode = false;
+ }
}
},