mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 23:19:26 +08:00
feat: enhance date handling in render variables and variable filters
This commit is contained in:
parent
5cb7bc0d8f
commit
d36027f2cf
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { createJSONTemplateParser } from '@nocobase/json-template-parser';
|
import { createJSONTemplateParser } from '@nocobase/json-template-parser';
|
||||||
import { getDateVars, isDate } from '@nocobase/utils';
|
import { getDateVars, isDate, parseDate } from '@nocobase/utils';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
|
|
||||||
function getUser(ctx) {
|
function getUser(ctx) {
|
||||||
@ -53,12 +53,18 @@ const dateValueWrapper = (value: any, timezone?: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
if (value.length === 2) {
|
const valueString = value.map((v) => {
|
||||||
value.push('[]', timezone);
|
if (isDate(v)) {
|
||||||
|
return v.toISOString();
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
});
|
||||||
|
if (valueString.length === 2) {
|
||||||
|
valueString.push('[]', timezone);
|
||||||
} else if (value.length === 3) {
|
} else if (value.length === 3) {
|
||||||
value.push(timezone);
|
valueString.push(timezone);
|
||||||
}
|
}
|
||||||
return value;
|
return valueString;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
@ -75,11 +81,15 @@ const dateValueWrapper = (value: any, timezone?: string) => {
|
|||||||
|
|
||||||
const $date = ({ fields, data, context }) => {
|
const $date = ({ fields, data, context }) => {
|
||||||
const timezone = context.timezone;
|
const timezone = context.timezone;
|
||||||
|
const now = new Date().toISOString();
|
||||||
const dateVars = getDateVars();
|
const dateVars = getDateVars();
|
||||||
|
|
||||||
const getValue = ({ field, keys }) => {
|
const getValue = ({ field, keys }) => {
|
||||||
const value = get(dateVars, field);
|
const val = get(dateVars, field);
|
||||||
return value;
|
const operator = keys[keys.length - 1];
|
||||||
|
const value = typeof val === 'function' ? val?.({ field, operator, timezone, now }) : val;
|
||||||
|
const parsedValue = parseDate(value, { timezone });
|
||||||
|
return parsedValue;
|
||||||
};
|
};
|
||||||
const afterApplyHelpers = ({ field, value, keys }) => {
|
const afterApplyHelpers = ({ field, value, keys }) => {
|
||||||
const operator = keys[keys.length - 1];
|
const operator = keys[keys.length - 1];
|
||||||
|
@ -64,11 +64,9 @@ export function dateSubtract(initialValue: any, number: number, unit: any) {
|
|||||||
};
|
};
|
||||||
if (Array.isArray(initialValue)) {
|
if (Array.isArray(initialValue)) {
|
||||||
const results = initialValue.map(handler);
|
const results = initialValue.map(handler);
|
||||||
console.log(results[0].toISOString());
|
|
||||||
return results;
|
return results;
|
||||||
} else {
|
} else {
|
||||||
const result = handler(initialValue);
|
const result = handler(initialValue);
|
||||||
console.log(result.toISOString());
|
|
||||||
return handler(initialValue);
|
return handler(initialValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user