From ccf9f5be2e2eb93a0758860cbfe706a55294260e Mon Sep 17 00:00:00 2001 From: Theresa <63280168+sd0ric4@users.noreply.github.com> Date: Thu, 27 Mar 2025 18:30:21 +0800 Subject: [PATCH] feat: Add support for independent loading states to optimize user experience during model testing (#4366) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 添加独立的loading状态支持,优化模型测试过程中的用户体验 * fix: typo * refactor: 修改loading状态字段名称,提升代码可读性 * feat: optimize model testing functionality, integrate loading state management, improve user experience --- .../account/model/Channel/ModelTest.tsx | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/projects/app/src/pageComponents/account/model/Channel/ModelTest.tsx b/projects/app/src/pageComponents/account/model/Channel/ModelTest.tsx index 15e5cb30a..cafca4a0b 100644 --- a/projects/app/src/pageComponents/account/model/Channel/ModelTest.tsx +++ b/projects/app/src/pageComponents/account/model/Channel/ModelTest.tsx @@ -33,6 +33,7 @@ type ModelTestItem = { status: 'waiting' | 'running' | 'success' | 'error'; message?: string; duration?: number; + loading?: boolean; // 单个模型的loading状态 }; const ModelTest = ({ @@ -85,7 +86,8 @@ const ModelTest = ({ ), model: modelData.model, - status: 'waiting' + status: 'waiting', + loading: false }; }) .filter(Boolean) as ModelTestItem[]; @@ -93,14 +95,16 @@ const ModelTest = ({ } }); - const { runAsync: onStartTest, loading: isTesting } = useRequest2( + const { runAsync: onStartTest, loading: isAnyModelLoading } = useRequest2( async () => { - { + try { let errorNum = 0; const testModel = async (model: string) => { setTestModelList((prev) => prev.map((item) => - item.model === model ? { ...item, status: 'running', message: '' } : item + item.model === model + ? { ...item, status: 'running', message: '', loading: true } + : item ) ); const start = Date.now(); @@ -110,7 +114,7 @@ const ModelTest = ({ setTestModelList((prev) => prev.map((item) => item.model === model - ? { ...item, status: 'success', duration: duration / 1000 } + ? { ...item, status: 'success', duration: duration / 1000, loading: false } : item ) ); @@ -118,7 +122,7 @@ const ModelTest = ({ setTestModelList((prev) => prev.map((item) => item.model === model - ? { ...item, status: 'error', message: getErrText(error) } + ? { ...item, status: 'error', message: getErrText(error), loading: false } : item ) ); @@ -138,19 +142,22 @@ const ModelTest = ({ title: t('account_model:test_failed', { num: errorNum }) }); } + } catch (error) { + console.error('Error during model testing:', error); } }, { refreshDeps: [testModelList] } ); + const { runAsync: onTestOneModel, loading: testingOneModel } = useRequest2( async (model: string) => { const start = Date.now(); setTestModelList((prev) => prev.map((item) => - item.model === model ? { ...item, status: 'running', message: '' } : item + item.model === model ? { ...item, status: 'running', message: '', loading: true } : item ) ); @@ -160,13 +167,17 @@ const ModelTest = ({ setTestModelList((prev) => prev.map((item) => - item.model === model ? { ...item, status: 'success', duration: duration / 1000 } : item + item.model === model + ? { ...item, status: 'success', duration: duration / 1000, loading: false } + : item ) ); } catch (error) { setTestModelList((prev) => prev.map((item) => - item.model === model ? { ...item, status: 'error', message: getErrText(error) } : item + item.model === model + ? { ...item, status: 'error', message: getErrText(error), loading: false } + : item ) ); } @@ -176,8 +187,6 @@ const ModelTest = ({ } ); - const isTestLoading = testingOneModel || isTesting; - return ( { - onTestOneModel(item.model); - }} + onClick={() => onTestOneModel(item.model)} /> @@ -241,7 +248,11 @@ const ModelTest = ({ -