vendor: amis 6.13.0 base (fork root)
This commit is contained in:
44
packages/amis-core/src/actions/SwitchAction.ts
Normal file
44
packages/amis-core/src/actions/SwitchAction.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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());
|
||||
Reference in New Issue
Block a user