Files
amis-fork/packages/amis-core/src/actions/SwitchAction.ts

45 lines
996 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {RendererEvent} from '../utils/renderer-event';
import {evalExpressionWithConditionBuilderAsync} from '../utils/tpl';
import {
RendererAction,
ListenerContext,
registerAction,
runActions,
ILogicAction
} from './Action';
export interface ISwitchAction extends ILogicAction {
actionType: 'switch';
}
/**
* 排他动作
*/
export class SwitchAction implements RendererAction {
async run(
action: ISwitchAction,
renderer: ListenerContext,
event: RendererEvent<any>,
mergeData: any
) {
for (const branch of action.children || []) {
if (!branch.expression) {
continue;
}
const isPass = await evalExpressionWithConditionBuilderAsync(
branch.expression,
mergeData
);
if (isPass) {
await runActions(branch, renderer, event);
// 去掉runAllMatch,这里只做排他,多个可以直接通过expression
break;
}
}
}
}
registerAction('switch', new SwitchAction());