diff --git a/packages/core/client/src/variables/__tests__/useVariables.test.tsx b/packages/core/client/src/variables/__tests__/useVariables.test.tsx index 477b38ea8..0a2d24776 100644 --- a/packages/core/client/src/variables/__tests__/useVariables.test.tsx +++ b/packages/core/client/src/variables/__tests__/useVariables.test.tsx @@ -140,6 +140,33 @@ describe('useVariables', () => { await waitFor(async () => { expect(result.current.ctxRef.current).toMatchInlineSnapshot(` { + "$date": { + "last30Days": [Function], + "last7Days": [Function], + "last90Days": [Function], + "lastIsoWeek": [Function], + "lastMonth": [Function], + "lastQuarter": [Function], + "lastWeek": [Function], + "lastYear": [Function], + "next30Days": [Function], + "next7Days": [Function], + "next90Days": [Function], + "nextIsoWeek": [Function], + "nextMonth": [Function], + "nextQuarter": [Function], + "nextWeek": [Function], + "nextYear": [Function], + "now": [Function], + "thisIsoWeek": [Function], + "thisMonth": [Function], + "thisQuarter": [Function], + "thisWeek": [Function], + "thisYear": [Function], + "today": [Function], + "tomorrow": [Function], + "yesterday": [Function], + }, "$nDate": { "last30Days": [Function], "last7Days": [Function], @@ -323,6 +350,33 @@ describe('useVariables', () => { await waitFor(async () => { expect(result.current.ctxRef.current).toMatchInlineSnapshot(` { + "$date": { + "last30Days": [Function], + "last7Days": [Function], + "last90Days": [Function], + "lastIsoWeek": [Function], + "lastMonth": [Function], + "lastQuarter": [Function], + "lastWeek": [Function], + "lastYear": [Function], + "next30Days": [Function], + "next7Days": [Function], + "next90Days": [Function], + "nextIsoWeek": [Function], + "nextMonth": [Function], + "nextQuarter": [Function], + "nextWeek": [Function], + "nextYear": [Function], + "now": [Function], + "thisIsoWeek": [Function], + "thisMonth": [Function], + "thisQuarter": [Function], + "thisWeek": [Function], + "thisYear": [Function], + "today": [Function], + "tomorrow": [Function], + "yesterday": [Function], + }, "$nDate": { "last30Days": [Function], "last7Days": [Function], @@ -379,6 +433,33 @@ describe('useVariables', () => { await waitFor(async () => { expect(result.current.ctxRef.current).toMatchInlineSnapshot(` { + "$date": { + "last30Days": [Function], + "last7Days": [Function], + "last90Days": [Function], + "lastIsoWeek": [Function], + "lastMonth": [Function], + "lastQuarter": [Function], + "lastWeek": [Function], + "lastYear": [Function], + "next30Days": [Function], + "next7Days": [Function], + "next90Days": [Function], + "nextIsoWeek": [Function], + "nextMonth": [Function], + "nextQuarter": [Function], + "nextWeek": [Function], + "nextYear": [Function], + "now": [Function], + "thisIsoWeek": [Function], + "thisMonth": [Function], + "thisQuarter": [Function], + "thisWeek": [Function], + "thisYear": [Function], + "today": [Function], + "tomorrow": [Function], + "yesterday": [Function], + }, "$nDate": { "last30Days": [Function], "last7Days": [Function], diff --git a/packages/core/client/src/variables/hooks/useBuiltinVariables.ts b/packages/core/client/src/variables/hooks/useBuiltinVariables.ts index 18a4b3ebb..7c95ad75d 100644 --- a/packages/core/client/src/variables/hooks/useBuiltinVariables.ts +++ b/packages/core/client/src/variables/hooks/useBuiltinVariables.ts @@ -31,6 +31,14 @@ const useBuiltInVariables = () => { name: '$nDate', ctx: dateVars, }, + /** + * @deprecated + * 兼容旧版本的 `$date` 变量,新版本已弃用 + */ + { + name: '$date', + ctx: dateVars, + }, /** * @deprecated * 兼容旧版本的 `$system` 变量,新版本已弃用 diff --git a/packages/core/client/src/variables/hooks/useLocalVariables.tsx b/packages/core/client/src/variables/hooks/useLocalVariables.tsx index 471d824a9..5d67e25cc 100644 --- a/packages/core/client/src/variables/hooks/useLocalVariables.tsx +++ b/packages/core/client/src/variables/hooks/useLocalVariables.tsx @@ -4,6 +4,7 @@ import { useFormBlockContext } from '../../block-provider'; import { useCollection } from '../../collection-manager'; import { useRecord } from '../../record-provider'; import { useSubFormValue } from '../../schema-component/antd/association-field/hooks'; +import { getDateRanges } from '../../schema-component/antd/date-picker/util'; import { useBlockCollection } from '../../schema-settings/VariableInput/hooks/useBlockCollection'; import { VariableOption } from '../types'; @@ -31,6 +32,7 @@ const useLocalVariables = (props?: Props) => { } return useMemo(() => { + const dateVars = getDateRanges(); return ( [ /** @@ -75,6 +77,18 @@ const useLocalVariables = (props?: Props) => { ctx: form?.values, collectionName: name, }, + { + name: '$nDate', + ctx: dateVars, + }, + /** + * @deprecated + * 兼容旧版本的 `$date` 变量,新版本已弃用 + */ + { + name: '$date', + ctx: dateVars, + }, subFormValue && { name: '$iteration', ctx: subFormValue, collectionName: currentCollectionName }, ] as VariableOption[] ).filter(Boolean);