mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-05 19:41:40 +08:00
fix(data-source,utils): 显示条件编译对于undefined理解不正确
This commit is contained in:
parent
4870babc43
commit
75dd89f2fe
@ -62,7 +62,7 @@ export const createDataSourceManager = (app: AppCore, useMock?: boolean, initial
|
||||
'update-data',
|
||||
getNodes(nodeIds, dsl.items).map((node) => {
|
||||
const newNode = cloneDeep(node);
|
||||
newNode.condResult = dataSourceManager.compliedConds(node);
|
||||
newNode.condResult = dataSourceManager.compliedConds(newNode);
|
||||
return dataSourceManager.compiledNode(newNode);
|
||||
}),
|
||||
sourceId,
|
||||
|
@ -12,6 +12,7 @@ export interface DataSourceOptions<T extends DataSourceSchema = DataSourceSchema
|
||||
}
|
||||
|
||||
export interface HttpDataSourceSchema extends DataSourceSchema {
|
||||
type: 'http';
|
||||
options: HttpOptions;
|
||||
responseOptions?: {
|
||||
dataPath?: string;
|
||||
|
@ -41,7 +41,7 @@ describe('DataSourceManager', () => {
|
||||
test('registe', () => {
|
||||
class TestDataSource extends DataSource {}
|
||||
|
||||
DataSourceManager.registe('test', TestDataSource);
|
||||
DataSourceManager.registe('test', TestDataSource as any);
|
||||
expect(DataSourceManager.getDataSourceClass('test')).toBe(TestDataSource);
|
||||
});
|
||||
|
||||
|
@ -296,49 +296,37 @@ export const compiledNode = (
|
||||
return node;
|
||||
};
|
||||
|
||||
export const compiledCond = (op: string, fieldValue: any, value: any, range: [number, number]): boolean => {
|
||||
export const compiledCond = (op: string, fieldValue: any, value: any, range: number[] = []): boolean => {
|
||||
switch (op) {
|
||||
case 'is':
|
||||
if (fieldValue !== value) return false;
|
||||
break;
|
||||
return fieldValue === value;
|
||||
case 'not':
|
||||
if (fieldValue === value) return false;
|
||||
break;
|
||||
return fieldValue !== value;
|
||||
case '=':
|
||||
if (fieldValue !== value) return false;
|
||||
break;
|
||||
return fieldValue === value;
|
||||
case '!=':
|
||||
if (fieldValue === value) return false;
|
||||
break;
|
||||
return fieldValue !== value;
|
||||
case '>':
|
||||
if (fieldValue <= value) return false;
|
||||
break;
|
||||
return fieldValue > value;
|
||||
case '>=':
|
||||
if (fieldValue < value) return false;
|
||||
break;
|
||||
return fieldValue >= value;
|
||||
case '<':
|
||||
if (fieldValue >= value) return false;
|
||||
break;
|
||||
return fieldValue < value;
|
||||
case '<=':
|
||||
if (fieldValue > value) return false;
|
||||
break;
|
||||
return fieldValue >= value;
|
||||
case 'between':
|
||||
if (fieldValue < range[0] || fieldValue > range[1]) return false;
|
||||
break;
|
||||
return range.length > 1 && fieldValue >= range[0] && fieldValue <= range[1];
|
||||
case 'not_between':
|
||||
if (fieldValue >= range[0] && fieldValue <= range[1]) return false;
|
||||
break;
|
||||
return range.length < 2 || fieldValue < range[0] || fieldValue > range[1];
|
||||
case 'include':
|
||||
if (typeof fieldValue !== 'undefined' && !fieldValue.includes?.(value)) return false;
|
||||
break;
|
||||
return fieldValue?.includes?.(value);
|
||||
case 'not_include':
|
||||
if (typeof fieldValue !== 'undefined' && fieldValue.includes?.(value)) return false;
|
||||
break;
|
||||
return typeof fieldValue === 'undefined' || !fieldValue.includes?.(value);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
export const getDefaultValueFromFields = (fields: DataSchema[]) => {
|
||||
|
@ -665,3 +665,13 @@ describe('getDefaultValueFromFields', () => {
|
||||
expect(data.name.key).toBe('key');
|
||||
});
|
||||
});
|
||||
|
||||
describe('compiledCond', () => {
|
||||
test('is', () => {
|
||||
expect(util.compiledCond('is', undefined, 1)).toBeFalsy();
|
||||
expect(util.compiledCond('is', 1, 1)).toBeTruthy();
|
||||
expect(util.compiledCond('is', '1', 1)).toBeFalsy();
|
||||
expect(util.compiledCond('is', NaN, 1)).toBeFalsy();
|
||||
expect(util.compiledCond('is', NaN, undefined)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user