From 79442a6a6ca5c4e57fd92640e3b3f441d6ef846e Mon Sep 17 00:00:00 2001 From: jialin Date: Fri, 21 Nov 2025 20:40:18 +0800 Subject: [PATCH] fix: apikey form value diff --- .../components/add-apikey-modal/allow-models.tsx | 6 ++++++ .../components/add-apikey-modal/index.tsx | 15 ++++++++++++--- .../components/access-control-modal/index.tsx | 13 +++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/pages/api-keys/components/add-apikey-modal/allow-models.tsx b/src/pages/api-keys/components/add-apikey-modal/allow-models.tsx index 5869f2c6..3323c574 100644 --- a/src/pages/api-keys/components/add-apikey-modal/allow-models.tsx +++ b/src/pages/api-keys/components/add-apikey-modal/allow-models.tsx @@ -54,6 +54,11 @@ const AllowModelsForm: React.FC<{ } catch (error) {} }; + const handleAllowTypeChange = (e: any) => { + const value = e.target.value; + onValuesChange?.({ allowed_type: value }, form.getFieldsValue()); + }; + useEffect(() => { getModelList(); }, [action, currentData]); @@ -68,6 +73,7 @@ const AllowModelsForm: React.FC<{ style={{ marginBottom: 8 }} > = ({ setShowKey(false); }; + const customEqual = (objValue: any, othValue: any) => { + if (_.isArray(objValue) && _.isArray(othValue)) { + return _.isEmpty(_.xor(objValue, othValue)); + } + return undefined; + }; + const handleOnValuesChange = async (changedValues: any, allValues: any) => { const initialValues = cacheFormRef.current; await new Promise((resolve) => { setTimeout(resolve, 100); }); - console.log('initialValues', initialValues, allValues); if ( - _.isEqual(initialValues, _.pick(allValues, Object.keys(initialValues))) + _.isEqualWith( + initialValues, + _.pick(allValues, Object.keys(initialValues)), + customEqual + ) ) { setIsChanged(false); } else { @@ -259,7 +269,6 @@ const AddModal: React.FC = ({ name="addAPIKey" form={form} onFinish={handleOnOk} - onValuesChange={handleOnValuesChange} preserve={false} > {!showKey && ( diff --git a/src/pages/llmodels/components/access-control-modal/index.tsx b/src/pages/llmodels/components/access-control-modal/index.tsx index 8b7ba2ac..66a9abb8 100644 --- a/src/pages/llmodels/components/access-control-modal/index.tsx +++ b/src/pages/llmodels/components/access-control-modal/index.tsx @@ -40,10 +40,18 @@ const AccessControlModal: React.FC< } }; + const customEqual = (objValue: any, othValue: any) => { + if (_.isArray(objValue) && _.isArray(othValue)) { + const objIds = objValue.map((item: any) => item.id).sort(); + const othIds = othValue.map((item: any) => item.id).sort(); + return _.isEqual(objIds, othIds); + } + return undefined; + }; + const handleOnValuesChange = async (changedValues: any, allValues: any) => { - console.log('changedValues', changedValues, allValues); const initialValues = formCacheRef.current; - if (_.isEqual(initialValues, allValues)) { + if (_.isEqualWith(initialValues, allValues, customEqual)) { setIsChanged(false); } else { setIsChanged(true); @@ -77,6 +85,7 @@ const AccessControlModal: React.FC< maskClosable={false} keyboard={false} width={700} + height={660} footer={ <> {isChanged && (