mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
fix: date time field condition not working in linkage rules (#6728)
* fix: datetime field in linakge rule condiction * fix: bug * fix: bug
This commit is contained in:
parent
72c5fdd14b
commit
ffdd03b4bc
@ -167,7 +167,7 @@ export function getOperators() {
|
|||||||
const dateA = parseDate(a);
|
const dateA = parseDate(a);
|
||||||
const dateB = parseDate(b);
|
const dateB = parseDate(b);
|
||||||
if (!dateA || !dateB) {
|
if (!dateA || !dateB) {
|
||||||
throw new Error('Invalid date format');
|
return false;
|
||||||
}
|
}
|
||||||
return dateA < dateB;
|
return dateA < dateB;
|
||||||
},
|
},
|
||||||
@ -651,10 +651,11 @@ function parseYear(dateStr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseDate(targetDateStr) {
|
function parseDate(targetDateStr) {
|
||||||
let dateStr = Array.isArray(targetDateStr) ? targetDateStr[1] : targetDateStr;
|
let dateStr = Array.isArray(targetDateStr) ? targetDateStr[1] ?? targetDateStr[0] : targetDateStr;
|
||||||
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(dateStr)) {
|
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(dateStr)) {
|
||||||
// ISO 8601 格式:YYYY-MM-DDTHH:mm:ss.sssZ
|
return new Date(dateStr);
|
||||||
return new Date(dateStr); // 直接解析为 Date 对象
|
} else if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dateStr)) {
|
||||||
|
return new Date(dateStr.replace(' ', 'T'));
|
||||||
} else if (/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) {
|
} else if (/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) {
|
||||||
// YYYY-MM-DD 格式
|
// YYYY-MM-DD 格式
|
||||||
return parseFullDate(dateStr);
|
return parseFullDate(dateStr);
|
||||||
@ -668,5 +669,6 @@ function parseDate(targetDateStr) {
|
|||||||
// YYYY 格式
|
// YYYY 格式
|
||||||
return parseYear(dateStr);
|
return parseYear(dateStr);
|
||||||
}
|
}
|
||||||
return null; // Invalid format
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { dayjs, getPickerFormat, Handlebars } from '@nocobase/utils/client';
|
import { dayjs, getPickerFormat, Handlebars, getFormatFromDateStr } from '@nocobase/utils/client';
|
||||||
import _, { every, findIndex, some } from 'lodash';
|
import _, { every, findIndex, some } from 'lodash';
|
||||||
import { replaceVariableValue } from '../../../block-provider/hooks';
|
import { replaceVariableValue } from '../../../block-provider/hooks';
|
||||||
import { VariableOption, VariablesContextType } from '../../../variables/types';
|
import { VariableOption, VariablesContextType } from '../../../variables/types';
|
||||||
@ -145,7 +145,15 @@ const processCondition = async (
|
|||||||
const processAdvancedCondition = async (condition, variables, localVariables, jsonLogic) => {
|
const processAdvancedCondition = async (condition, variables, localVariables, jsonLogic) => {
|
||||||
const operator = condition.op;
|
const operator = condition.op;
|
||||||
const rightValue = await parseVariableValue(condition.rightVar, variables, localVariables);
|
const rightValue = await parseVariableValue(condition.rightVar, variables, localVariables);
|
||||||
const leftValue = await parseVariableValue(condition.leftVar, variables, localVariables);
|
let leftValue = await parseVariableValue(condition.leftVar, variables, localVariables);
|
||||||
|
const leftCollectionField = await variables.getCollectionField(condition.leftVar, localVariables);
|
||||||
|
if (
|
||||||
|
leftValue &&
|
||||||
|
['datetime', 'date', 'datetimeNoTz', 'dateOnly', 'unixTimestamp'].includes(leftCollectionField.type)
|
||||||
|
) {
|
||||||
|
const format = getFormatFromDateStr(rightValue);
|
||||||
|
leftValue = dayjs.utc(leftValue).local().format(format);
|
||||||
|
}
|
||||||
if (operator) {
|
if (operator) {
|
||||||
return jsonLogic.apply({ [operator]: [leftValue, rightValue] });
|
return jsonLogic.apply({ [operator]: [leftValue, rightValue] });
|
||||||
}
|
}
|
||||||
|
@ -236,3 +236,13 @@ export const getDateTimeFormat = (picker, format, showTime, timeFormat) => {
|
|||||||
}
|
}
|
||||||
return format;
|
return format;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function getFormatFromDateStr(dateStr: string): string | null {
|
||||||
|
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dateStr)) return 'YYYY-MM-DD HH:mm:ss';
|
||||||
|
if (/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) return 'YYYY-MM-DD';
|
||||||
|
if (/^\d{4}-\d{2}$/.test(dateStr)) return 'YYYY-MM';
|
||||||
|
if (/^\d{4}$/.test(dateStr)) return 'YYYY';
|
||||||
|
if (/^\d{4}Q[1-4]$/.test(dateStr)) return 'YYYY[Q]Q';
|
||||||
|
if (/^\d{4}-\d{2}-\d{2}T/.test(dateStr)) return 'YYYY-MM-DDTHH:mm:ss.SSSZ';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@ -55,6 +55,7 @@ test.describe('direct duplicate & copy into the form and continue to fill in', (
|
|||||||
await page.getByRole('menuitem', { name: 'oneToMany' }).click();
|
await page.getByRole('menuitem', { name: 'oneToMany' }).click();
|
||||||
await page.getByRole('menuitem', { name: 'manyToOne', exact: true }).click();
|
await page.getByRole('menuitem', { name: 'manyToOne', exact: true }).click();
|
||||||
await page.getByRole('menuitem', { name: 'manyToMany' }).click();
|
await page.getByRole('menuitem', { name: 'manyToMany' }).click();
|
||||||
|
await page.mouse.move(300, 0);
|
||||||
await page.getByLabel('schema-initializer-ActionBar-createForm:configureActions-general').click();
|
await page.getByLabel('schema-initializer-ActionBar-createForm:configureActions-general').click();
|
||||||
await page.getByRole('menuitem', { name: 'Submit' }).click();
|
await page.getByRole('menuitem', { name: 'Submit' }).click();
|
||||||
await page.getByLabel('drawer-Action.Container-general-Duplicate-mask').click();
|
await page.getByLabel('drawer-Action.Container-general-Duplicate-mask').click();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user