mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
fix: add defineAction
This commit is contained in:
parent
d911e05a0e
commit
7e29826578
@ -1,6 +1,6 @@
|
||||
import * as icons from '@ant-design/icons';
|
||||
import { Plugin } from '@nocobase/client';
|
||||
import { defineFlow, FlowModel, FlowModelRenderer } from '@nocobase/flow-engine';
|
||||
import { defineAction, defineFlow, FlowModel, FlowModelRenderer } from '@nocobase/flow-engine';
|
||||
import { Button } from 'antd';
|
||||
import React from 'react';
|
||||
import { createApp } from './createApp';
|
||||
@ -40,40 +40,42 @@ const myEventFlow = defineFlow({
|
||||
|
||||
MyModel.registerFlow(myEventFlow);
|
||||
|
||||
const myConfirm = defineAction({
|
||||
name: 'confirm',
|
||||
uiSchema: {
|
||||
title: {
|
||||
type: 'string',
|
||||
title: 'Confirm title',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Input',
|
||||
},
|
||||
content: {
|
||||
type: 'string',
|
||||
title: 'Confirm content',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Input.TextArea',
|
||||
},
|
||||
},
|
||||
defaultParams: {
|
||||
title: 'Confirm Deletion',
|
||||
content: 'Are you sure you want to delete this record?',
|
||||
},
|
||||
async handler(ctx, params) {
|
||||
const confirmed = await ctx.globals.modal.confirm({
|
||||
title: params.title,
|
||||
content: params.content,
|
||||
});
|
||||
if (!confirmed) {
|
||||
ctx.globals.message.info('Action cancelled.');
|
||||
return ctx.exit();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
class PluginDemo extends Plugin {
|
||||
async load() {
|
||||
this.flowEngine.registerModels({ MyModel });
|
||||
this.flowEngine.registerAction({
|
||||
name: 'confirm',
|
||||
uiSchema: {
|
||||
title: {
|
||||
type: 'string',
|
||||
title: 'Confirm title',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Input',
|
||||
},
|
||||
content: {
|
||||
type: 'string',
|
||||
title: 'Confirm content',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Input.TextArea',
|
||||
},
|
||||
},
|
||||
defaultParams: {
|
||||
title: 'Confirm Deletion',
|
||||
content: 'Are you sure you want to delete this record?',
|
||||
},
|
||||
async handler(ctx, params) {
|
||||
const confirmed = await ctx.globals.modal.confirm({
|
||||
title: params.title,
|
||||
content: params.content,
|
||||
});
|
||||
if (!confirmed) {
|
||||
ctx.globals.message.info('Action cancelled.');
|
||||
return ctx.exit();
|
||||
}
|
||||
},
|
||||
});
|
||||
this.flowEngine.registerAction(myConfirm);
|
||||
const model = this.flowEngine.createModel({
|
||||
use: 'MyModel',
|
||||
});
|
||||
|
@ -180,33 +180,3 @@ steps: {
|
||||
- 支持多种定义方式,适应不同复杂度的业务场景。
|
||||
- 可通过 `uiSchema` 和 `defaultParams` 配置参数界面和默认值,提升易用性。
|
||||
- 合理使用 `paramsRequired` 和 `hideInSettings`,提升操作安全性和灵活性。
|
||||
|
||||
---
|
||||
|
||||
## 示例:在 Drawer 中使用
|
||||
|
||||
以下示例演示如何在 Drawer 中使用 FlowAction,并传递 `currentDrawer` 到 `sharedContext`。
|
||||
|
||||
```tsx
|
||||
// 1. 先声明 currentDrawer
|
||||
let currentDrawer: any;
|
||||
|
||||
// 2. 定义内容组件,确保 currentDrawer 已赋值
|
||||
function DrawerContent() {
|
||||
return (
|
||||
<div>
|
||||
<FlowPageComponent
|
||||
uid={`${ctx.model.uid}-drawer`}
|
||||
sharedContext={{ ...ctx.extra, currentDrawer }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 3. 打开 Drawer,并赋值 currentDrawer
|
||||
currentDrawer = ctx.globals.drawer.open({
|
||||
title: '命令式 Drawer',
|
||||
width: 800,
|
||||
content: <DrawerContent />,
|
||||
});
|
||||
```
|
||||
|
@ -8,8 +8,8 @@
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import { DeepPartial, ModelConstructor, FlowDefinition, ParamsContext, FlowContext } from './types';
|
||||
import type { FlowModel } from './models';
|
||||
import { ActionDefinition, DeepPartial, FlowContext, FlowDefinition, ModelConstructor, ParamsContext } from './types';
|
||||
|
||||
export function generateUid(): string {
|
||||
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
||||
@ -118,3 +118,7 @@ export class FlowExitException extends Error {
|
||||
this.modelUid = modelUid;
|
||||
}
|
||||
}
|
||||
|
||||
export function defineAction(options: ActionDefinition) {
|
||||
return options;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user