From 76940c5454474bcc2d6ab1954b48bd261425ccb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Wed, 8 Nov 2023 00:23:53 +0800 Subject: [PATCH] chore: optimize error message (#2992) * Revert "chore: optimize error message (#2985)" This reverts commit 3802ca38f8ed89282735fa012834b2730c3f9363. * chore: optimize error message --- .../antd/form-item/hooks/useParseDefaultValue.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/form-item/hooks/useParseDefaultValue.ts b/packages/core/client/src/schema-component/antd/form-item/hooks/useParseDefaultValue.ts index 07d3be3c7..6e446324d 100644 --- a/packages/core/client/src/schema-component/antd/form-item/hooks/useParseDefaultValue.ts +++ b/packages/core/client/src/schema-component/antd/form-item/hooks/useParseDefaultValue.ts @@ -16,8 +16,6 @@ import { transformVariableValue } from '../../../../variables/utils/transformVar import { isSubMode } from '../../association-field/util'; import { isFromDatabase, useSpecialCase } from './useSpecialCase'; -const formilyVariable = ['record']; - /** * 用于解析并设置 FormItem 的默认值 */ @@ -49,7 +47,6 @@ const useParseDefaultValue = () => { useEffect(() => { if ( - (isVariable(fieldSchema.default) && formilyVariable.includes(getVariableName(fieldSchema.default))) || fieldSchema.default == null || isInSetDefaultValueDialog || isInFormDataTemplate || @@ -73,7 +70,7 @@ const useParseDefaultValue = () => { if (process.env.NODE_ENV !== 'production') { if (!collectionField) { - throw new Error(`useParseDefaultValue: can not find field ${fieldSchema.name}`); + console.error(`useParseDefaultValue: can not find field ${fieldSchema.name}`); } } @@ -107,17 +104,17 @@ const useParseDefaultValue = () => { // 使用防抖,提高性能和用户体验 const run = _.debounce(_run, DEBOUNCE_WAIT); - _run(); - if (isVariable(fieldSchema.default)) { const variableName = getVariableName(fieldSchema.default); const variable = findVariable(variableName); if (process.env.NODE_ENV !== 'production' && !variable) { - throw new Error(`useParseDefaultValue: can not find variable ${variableName}`); + console.error(`useParseDefaultValue: can not find variable ${variableName}`); } if (variable) { + _run(); + // 实现联动的效果,当依赖的变量变化时(如 `$nForm` 变量),重新解析默认值 const dispose = reaction(() => { const obj = { [variableName]: variable?.ctx || {} };