diff --git a/packages/core/client/src/schema-component/antd/action/Action.tsx b/packages/core/client/src/schema-component/antd/action/Action.tsx index deec37c7d2..17b7375955 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.tsx @@ -83,13 +83,12 @@ export const Action: ComposedAction = observer( operator: h.operator, field, condition: v.condition, - values: record, variables, localVariables, }); }); }); - }, [JSON.stringify(linkageRules), record, designable, field]); + }, [JSON.stringify(linkageRules), designable, field]); const handleButtonClick = useCallback( (e: React.MouseEvent) => { diff --git a/packages/core/client/src/schema-component/antd/action/utils.ts b/packages/core/client/src/schema-component/antd/action/utils.ts index 3947fd2f73..3f68021267 100644 --- a/packages/core/client/src/schema-component/antd/action/utils.ts +++ b/packages/core/client/src/schema-component/antd/action/utils.ts @@ -75,14 +75,12 @@ export const linkageAction = async ({ operator, field, condition, - values, variables, localVariables, }: { operator; field; condition; - values; variables: VariablesContextType; localVariables: VariableOption[]; }) => { @@ -91,7 +89,7 @@ export const linkageAction = async ({ switch (operator) { case ActionType.Visible: - if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) { + if (await conditionAnalyses({ rules: condition, variables, localVariables })) { displayResult.push(operator); field.data = field.data || {}; field.data.hidden = false; @@ -103,7 +101,7 @@ export const linkageAction = async ({ field.display = last(displayResult); break; case ActionType.Hidden: - if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) { + if (await conditionAnalyses({ rules: condition, variables, localVariables })) { field.data = field.data || {}; field.data.hidden = true; } else { @@ -112,7 +110,7 @@ export const linkageAction = async ({ } break; case ActionType.Disabled: - if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) { + if (await conditionAnalyses({ rules: condition, variables, localVariables })) { disableResult.push(true); } field.linkageProperty = { @@ -123,7 +121,7 @@ export const linkageAction = async ({ field.componentProps['disabled'] = last(disableResult); break; case ActionType.Active: - if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) { + if (await conditionAnalyses({ rules: condition, variables, localVariables })) { disableResult.push(false); } else { disableResult.push(true); diff --git a/packages/core/client/src/schema-component/antd/date-picker/util.ts b/packages/core/client/src/schema-component/antd/date-picker/util.ts index d03140a6a1..a5fbbfe073 100644 --- a/packages/core/client/src/schema-component/antd/date-picker/util.ts +++ b/packages/core/client/src/schema-component/antd/date-picker/util.ts @@ -138,7 +138,7 @@ const getEnd = (offset: any, unit: any) => { export const getDateRanges = () => { return { - now: () => dayjs(), + now: () => dayjs().toISOString(), today: () => [getStart(0, 'day'), getEnd(0, 'day')], yesterday: () => [getStart(-1, 'day'), getEnd(-1, 'day')], tomorrow: () => [getStart(1, 'day'), getEnd(1, 'day')], diff --git a/packages/core/client/src/schema-component/antd/form-v2/Form.tsx b/packages/core/client/src/schema-component/antd/form-v2/Form.tsx index d0d02d1cff..392feee73e 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/Form.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/Form.tsx @@ -2,7 +2,7 @@ import { css } from '@emotion/css'; import { FormLayout } from '@formily/antd-v5'; import { createForm, Field, Form as FormilyForm, onFieldChange, onFieldInit, onFormInputChange } from '@formily/core'; import { FieldContext, FormContext, observer, RecursionField, useField, useFieldSchema } from '@formily/react'; -import { autorun } from '@formily/reactive'; +import { autorun, raw } from '@formily/reactive'; import { uid } from '@formily/shared'; import { ConfigProvider, Spin } from 'antd'; import React, { useEffect, useMemo } from 'react'; @@ -134,7 +134,7 @@ const WithForm = (props: WithFormProps) => { value: h.value, field, condition: v.condition, - values: form?.values, + values: raw(form?.values), variables, localVariables, }); diff --git a/packages/core/client/src/schema-component/antd/form-v2/utils.tsx b/packages/core/client/src/schema-component/antd/form-v2/utils.tsx index b41c84ee43..d0e8278b8d 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/utils.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/utils.tsx @@ -1,7 +1,7 @@ import { Field } from '@formily/core'; import { evaluators } from '@nocobase/evaluators/client'; import { uid } from '@nocobase/utils'; -import _, { cloneDeep, last } from 'lodash'; +import _, { last } from 'lodash'; import { ActionType } from '../../../schema-settings/LinkageRules/type'; import { VariableOption, VariablesContextType } from '../../../variables/types'; import { REGEX_OF_VARIABLE } from '../../../variables/utils/isVariable'; @@ -36,7 +36,7 @@ export const linkageMergeAction = async ({ switch (operator) { case ActionType.Required: - if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) { + if (await conditionAnalyses({ rules: condition, variables, localVariables })) { requiredResult.push(true); } field.linkageProperty = { @@ -50,7 +50,7 @@ export const linkageMergeAction = async ({ resolve(void 0); }); case ActionType.InRequired: - if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) { + if (await conditionAnalyses({ rules: condition, variables, localVariables })) { requiredResult.push(false); } field.linkageProperty = { @@ -66,7 +66,7 @@ export const linkageMergeAction = async ({ case ActionType.Visible: case ActionType.None: case ActionType.Hidden: - if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) { + if (await conditionAnalyses({ rules: condition, variables, localVariables })) { displayResult.push(operator); } field.linkageProperty = { @@ -82,7 +82,7 @@ export const linkageMergeAction = async ({ case ActionType.Editable: case ActionType.ReadOnly: case ActionType.ReadPretty: - if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) { + if (await conditionAnalyses({ rules: condition, variables, localVariables })) { patternResult.push(operator); } field.linkageProperty = { @@ -96,17 +96,12 @@ export const linkageMergeAction = async ({ resolve(void 0); }); case ActionType.Value: - if ( - isConditionEmpty(condition) || - (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) - ) { + if (isConditionEmpty(condition) || (await conditionAnalyses({ rules: condition, variables, localVariables }))) { if (value?.mode === 'express') { if ((value.value || value.result) == null) { return; } - const scope = cloneDeep(values); - // 1. 解析如 `{{$user.name}}` 之类的变量 const { exp, scope: expScope } = await replaceVariables(value.value || value.result, { variables, @@ -115,7 +110,7 @@ export const linkageMergeAction = async ({ try { // 2. TODO: 需要把里面解析变量的逻辑删除,因为在上一步已经解析过了 - const result = evaluate(exp, { ...scope, now: () => new Date().toString(), ...expScope }); + const result = evaluate(exp, { ...values, now: () => new Date().toString(), ...expScope }); valueResult.push(result); } catch (error) { console.error(error); diff --git a/packages/core/client/src/schema-component/common/utils/uitls.tsx b/packages/core/client/src/schema-component/common/utils/uitls.tsx index 8a94f5a311..6607eb6dce 100644 --- a/packages/core/client/src/schema-component/common/utils/uitls.tsx +++ b/packages/core/client/src/schema-component/common/utils/uitls.tsx @@ -67,12 +67,10 @@ function getAllKeys(obj) { export const conditionAnalyses = async ({ rules, - formValues, variables, localVariables, }: { rules; - formValues; variables: VariablesContextType; localVariables: VariableOption[]; }) => { diff --git a/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx b/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx index 98aec70da9..070aaf2c90 100644 --- a/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx +++ b/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx @@ -106,13 +106,12 @@ export const CreateRecordAction = observer( operator: h.operator, field, condition: v.condition, - values, variables, localVariables, }); }); }); - }, [JSON.stringify(linkageRules), values]); + }, [JSON.stringify(linkageRules)]); return (
@@ -211,13 +210,12 @@ export const CreateAction = observer( operator: h.operator, field, condition: v.condition, - values, variables, localVariables, }); }); }); - }, [JSON.stringify(linkageRules), values]); + }, [JSON.stringify(linkageRules)]); return (
{ const currentUser = data?.data?.data; const dateVars = getDateRanges(); - // 使用函数方便测试断言 - dateVars.now = (() => dayjs().toISOString()) as any; const builtinVariables: VariableOption[] = useMemo(() => { return [ {