Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/reduce-audit-action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@coding-flow/flow-types": patch
"@coding-flow/flow-core": patch
"@coding-flow/flow-approval-presenter": patch
"@coding-flow/flow-pc-approval": patch
"@coding-flow/flow-mobile-approval": patch
"@coding-flow/flow-design": patch
---

feat: 支持减签动作 REDUCE_AUDIT(codingapi/flow-engine#266、codingapi/flow-frontend#72)

- `ActionType` 增加 `REDUCE_AUDIT`,`actionOptions` 增加「减签」,设计器可配置减签动作。
- PC / 移动端新增减签按钮与提交逻辑,通过 `advice.forwardOperatorIds` 传递被减签人;与加签同构,支持自定义弹框内容与事件总线触发。
- 新增 `ReduceAuditViewPlugin`(`ReduceAuditViewPluginKey`)用于替换减签人员选择视图;默认实现为占位,集成方应列出当前节点的待审批人(不含当前审批人)。
- 设计器新增减签动作配置:仅「减签人员范围」(script),不提供「最大可选人数」。
- `FlowMessageKey.APPROVAL_REDUCE_AUDIT` 增加默认提示文案。
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ React 18、TypeScript 5、pnpm 10、Rsbuild/Rslib(构建)、@rstest/core(

## 开发规范

### 禁止自动提交
### 提交、推送与分支合并

- **未经用户明确要求,任何情况下不得执行 `git commit` / `git push` / `git merge` 操作**
- 所有代码变更需经用户审核后再提交
- **允许执行 `git commit` 与 `git push`**:提交前必须完成本地编译与测试验证,提交信息使用中文并说明改动内容
- **禁止主动合并分支**:不得执行 `git merge`,也不得自行合并或关闭 PR;`dev` / `main` 的合并一律由用户决定
- 推送后保持分支可审核状态,由用户决定是否合并

### 基本规范

Expand Down
7 changes: 4 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ React 18、TypeScript 5、pnpm 10、Rsbuild/Rslib(构建)、@rstest/core(

## 开发规范

### 禁止自动提交
### 提交、推送与分支合并

- **未经用户明确要求,任何情况下不得执行 `git commit` / `git push` / `git merge` 操作**
- 所有代码变更需经用户审核后再提交
- **允许执行 `git commit` 与 `git push`**:提交前必须完成本地编译与测试验证,提交信息使用中文并说明改动内容
- **禁止主动合并分支**:不得执行 `git merge`,也不得自行合并或关闭 PR;`dev` / `main` 的合并一律由用户决定
- 推送后保持分支可审核状态,由用户决定是否合并

### 基本规范

Expand Down
1 change: 1 addition & 0 deletions packages/flow-approval-presenter/src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {type AddAuditViewPlugin,VIEW_KEY as AddAuditViewPluginKey} from "./add-audit-type";
export {type ReduceAuditViewPlugin,VIEW_KEY as ReduceAuditViewPluginKey} from "./reduce-audit-type";
export {type DelegateViewPlugin,VIEW_KEY as DelegateViewPluginKey} from "./delegate-type";
export {type ReturnViewPlugin,VIEW_KEY as ReturnViewPluginKey} from "./return-type";
export {type SignKeyViewPlugin,VIEW_KEY as SignKeyViewPluginKey} from "./sign-key-type";
Expand Down
19 changes: 19 additions & 0 deletions packages/flow-approval-presenter/src/plugins/reduce-audit-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import {ApprovalViewPluginAction} from "@/plugins/approval-view-plugin-action";

export const VIEW_KEY = 'ReduceAuditViewPlugin';

/**
* 减签人员选择视图(issue-72)
*
* 默认实现只是占位,真实项目应注册该视图,列出当前节点的待审批人(不含当前审批人)。
* 被减签人是否合法最终由服务端校验。
*/
export interface ReduceAuditViewPlugin {
/** 返回用户 */
onChange?: (value: string|string[]) => void;
/** 当前用户 */
value?: string|string[];
/** 动作控制 **/
action?:React.Ref<ApprovalViewPluginAction>;
}
2 changes: 2 additions & 0 deletions packages/flow-core/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const FlowMessageKey = {
APPROVAL_REJECT: 'approval.reject',
APPROVAL_DELEGATE: 'approval.delegate',
APPROVAL_ADD_AUDIT: 'approval.add_audit',
APPROVAL_REDUCE_AUDIT: 'approval.reduce_audit',
APPROVAL_TRANSFER: 'approval.transfer',
APPROVAL_RETURN: 'approval.return',
APPROVAL_REVOKE: 'approval.revoke',
Expand Down Expand Up @@ -143,6 +144,7 @@ function getDefaultMessages(): Record<string, MessageTemplate> {
[FlowMessageKey.APPROVAL_REJECT]: '操作成功',
[FlowMessageKey.APPROVAL_DELEGATE]: '操作成功',
[FlowMessageKey.APPROVAL_ADD_AUDIT]: '操作成功',
[FlowMessageKey.APPROVAL_REDUCE_AUDIT]: '操作成功',
[FlowMessageKey.APPROVAL_TRANSFER]: '操作成功',
[FlowMessageKey.APPROVAL_RETURN]: '操作成功',
[FlowMessageKey.APPROVAL_REVOKE]: '流程已撤回',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {ActionFormProps} from "@/script-components/typings";
import {ActionType} from "@coding-flow/flow-types";
import {CustomActionForm} from "@/script-components/components/action/components/custom";
import {AddAuditActionForm} from "@/script-components/components/action/components/add-audit";
import {ReduceAuditActionForm} from "@/script-components/components/action/components/reduce-audit";
import {DelegateActionForm} from "@/script-components/components/action/components/delegate";
import {RejectActionForm} from "@/script-components/components/action/components/reject";
import {TransferActionForm} from "@/script-components/components/action/components/transfer";
Expand All @@ -18,6 +19,7 @@ export class ActionFactory{

private initialize():void{
this.actions.set('ADD_AUDIT',AddAuditActionForm);
this.actions.set('REDUCE_AUDIT',ReduceAuditActionForm);
this.actions.set('CUSTOM',CustomActionForm);
this.actions.set('DELEGATE',DelegateActionForm);
this.actions.set('REJECT',RejectActionForm);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from "react";
import {ActionFormProps} from "@/script-components/typings";
import {Col, Form, Row} from "antd";
import {OperatorLoadPluginView} from "@/plugins/view/operator-load-view";

interface ReduceAuditInputProps{
value?:string;
onChange?:(value:string) => void;
}

const ReduceAuditInput:React.FC<ReduceAuditInputProps> = (props)=>{

const script = props.value || '';

const handleChange = (value:string)=>{
props.onChange && props.onChange(value);
}

return (
<OperatorLoadPluginView
script={script}
onChange={handleChange}
/>
)
}

/**
* 减签动作配置
*
* 仅配置可减签的人员范围,不需要「最大可选人数」:一次减签可以撤下多位审批人。
*/
export const ReduceAuditActionForm:React.FC<ActionFormProps> = (props)=>{

return (
<Row>
<Col span={24}>
<Form.Item
name={"script"}
label={"减签人员范围"}
help={"减签人员范围为空时,即为全部人员;仅对循序/并签多人审批节点生效"}
>
<ReduceAuditInput/>
</Form.Item>
</Col>
</Row>
)
}
26 changes: 26 additions & 0 deletions packages/flow-design/tests/components/reduce-audit-action.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, expect, it } from "@rstest/core";
import { ActionFactory } from "@/script-components/components/action/components/factory";

/**
* 减签动作配置(后端 issue #266 / 前端 issue-72)
*
* 设计器动作列表依赖 actionOptions 展示类型名称,配置弹窗依赖 ActionFactory 选择表单。
*/
describe('设计器减签动作', () => {

it('REDUCE_AUDIT 应映射到减签动作表单', () => {
// when
const form = ActionFactory.getInstance().getActionForm('REDUCE_AUDIT');

// then
expect(form).toBeTruthy();
});

it('未注册的动作类型应返回 undefined', () => {
// when
const form = ActionFactory.getInstance().getActionForm('UNKNOWN_ACTION' as never);

// then
expect(form).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {FlowActionProps} from "./type";
import {FlowAction} from "@coding-flow/flow-types";
import {PassAction} from "@/components/flow-approval/components/action/pass";
import {AddAuditAction} from "@/components/flow-approval/components/action/add-audit";
import {ReduceAuditAction} from "@/components/flow-approval/components/action/reduce-audit";
import {CustomAction} from "@/components/flow-approval/components/action/custom";
import {DelegateAction} from "@/components/flow-approval/components/action/delegate";
import {RejectAction} from "@/components/flow-approval/components/action/reject";
Expand All @@ -28,6 +29,7 @@ export class ActionFactory {

private initActions() {
this.cache.set("ADD_AUDIT", AddAuditAction);
this.cache.set("REDUCE_AUDIT", ReduceAuditAction);
this.cache.set("CUSTOM", CustomAction);
this.cache.set("DELEGATE", DelegateAction);
this.cache.set("PASS", PassAction);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React from "react";
import {FlowActionProps} from "./type";
import {Form, Toast} from "antd-mobile";
import {ApprovalViewPluginAction, DialogContent, useApprovalContext} from "@coding-flow/flow-approval-presenter";
import {ReduceAuditView} from "@/plugins/view/reduce-audit-view";
import {PopupModal} from "@coding-flow/flow-mobile-ui";
import {EventBus, ViewBindPlugin, FlowMessageKey, FlowMessageRegistry} from "@coding-flow/flow-core";
import {APPROVAL_ACTION_REDUCE_AUDIT_KEY} from "@/components/flow-approval";

/**
* 减签
*
* 由当前审批人把指定审批人从当前节点撤下,提交时通过 forwardOperatorIds 传递被减签人;
* 目标是否属于当前节点的待审批人由服务端校验。
* @param props
* @constructor
*/
export const ReduceAuditAction: React.FC<FlowActionProps> = (props) => {

const action = props.action;
const {state, context} = useApprovalContext();
const [form] = Form.useForm();

const actionPresenter = context.getPresenter().getFlowActionPresenter();
const actionLoading = state.actionLoading ?? false;

const [modalVisible, setModalVisible] = React.useState(false);
const [dialogContent, setDialogContent] = React.useState<DialogContent | null>(null);

const actionRef = React.useRef<ApprovalViewPluginAction>(null);

/** 打开弹框:解析自定义弹框内容(标题/中间内容),并重置表单 */
const openModal = () => {
form.resetFields();
setDialogContent(null);
actionPresenter.resolveDialogContent(action.id).then(setDialogContent);
setModalVisible(true);
}

const handlerOK = ()=>{
// 自定义弹框内容时退化为纯确认框,直接提交(无表单可校验)
if(dialogContent?.content){
handleSubmit();
return;
}
if(actionRef.current){
actionRef.current.onValidate().then(res=>{
if(res){
form.submit();
}
})
return;
}
form.submit();
}

const handleSubmit = (params?: any) => {
actionPresenter.action(action.id, params).then((res) => {
if (res.success) {
Toast.show(
FlowMessageRegistry.getInstance().get(
FlowMessageKey.APPROVAL_REDUCE_AUDIT,
actionPresenter.buildActionContext(action.id)
)
);
setModalVisible(false);
context.close();
}
});
}

React.useEffect(()=>{
EventBus.getInstance().on(action.id,()=>{
openModal();
});

return () => {
EventBus.getInstance().off(action.id);
}
},[]);

const ActionView = ViewBindPlugin.getInstance().get(APPROVAL_ACTION_REDUCE_AUDIT_KEY);

if (ActionView) {
return (
<ActionView
{...props}
/>
)
}

return (
<>
<PopupModal
title={dialogContent?.title ?? "减签审批"}
open={modalVisible}
loading={actionLoading}
onClose={() => setModalVisible(false)}
onOk={() => {
handlerOK();
}}
>
{dialogContent?.content ? (
dialogContent.content
) : (
<Form
form={form}
layout="vertical"
onFinish={(values) => {
handleSubmit(values);
}}
>
<Form.Item
name={"forwardOperatorIds"}
label={"减签人员"}
required={true}
rules={[
{
required: true,
message:'减签人员不能为空'
}
]}
>
<ReduceAuditView
action={actionRef}
/>
</Form.Item>
</Form>
)}
</PopupModal>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const APPROVAL_BODY_VIEW_KEY = 'APPROVAL_BODY_VIEW_KEY';
export const APPROVAL_FOOTER_VIEW_KEY = 'APPROVAL_FOOTER_VIEW_KEY';

export const APPROVAL_ACTION_ADD_AUDIT_KEY = 'APPROVAL_ACTION_ADD_AUDIT_KEY';
export const APPROVAL_ACTION_REDUCE_AUDIT_KEY = 'APPROVAL_ACTION_REDUCE_AUDIT_KEY';
export const APPROVAL_ACTION_CUSTOM_KEY = 'APPROVAL_ACTION_CUSTOM_KEY';
export const APPROVAL_ACTION_DELEGATE_KEY = 'APPROVAL_ACTION_DELEGATE_KEY';
export const APPROVAL_ACTION_PASS_KEY = 'APPROVAL_ACTION_PASS_KEY';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from "react";
import {ReduceAuditViewPlugin, ReduceAuditViewPluginKey} from "@coding-flow/flow-approval-presenter";
import {ViewBindPlugin} from "@coding-flow/flow-core";
import {Selector} from "antd-mobile";
import {useApprovalContext} from "@coding-flow/flow-approval-presenter";

/**
* 减签人员选择视图
*
* 默认实现只提供占位选项,真实项目应通过 ViewBindPlugin 注册视图,
* 列出当前节点的待审批人(不含当前审批人)。
*/
export const ReduceAuditView: React.FC<ReduceAuditViewPlugin> = (props) => {
const ReduceAuditViewComponent = ViewBindPlugin.getInstance().get(ReduceAuditViewPluginKey);

const {state} = useApprovalContext();

const value = React.useMemo(()=>{
if(props.value) {
if (Array.isArray(props.value)) {
return props.value;
}else {
return [props.value]
}
}
return [];
},[props.value]);

const createOperator = state.flow?.createOperator;

const options = createOperator?[
{
label:createOperator.name,
value:createOperator.id + '',
}
]:[];

if (ReduceAuditViewComponent) {
return (
<ReduceAuditViewComponent {...props} />
);
}

return (
<Selector
multiple={true}
value={value}
onChange={(next) => {
props.onChange?.(next);
}}
options={options}
/>
)
}
Loading
Loading