Skip to content
Merged

Dev #79

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
9 changes: 9 additions & 0 deletions .changeset/issue-272-reissue-finished-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@coding-flow/flow-types": minor
"@coding-flow/flow-core": minor
"@coding-flow/flow-approval-presenter": minor
"@coding-flow/flow-pc-approval": minor
"@coding-flow/flow-mobile-approval": minor
---

已办详情支持已完成流程「重新发起」(issue #272):由详情 `reissue` 标识驱动,复制原流程表单数据创建新流程并回到发起人待办,原流程记录保持不变。
14 changes: 14 additions & 0 deletions packages/flow-approval-presenter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @coding-flow/flow-approval-presenter

## 0.2.21

### Patch Changes

- 0b9b8d6: fix: 退回候选节点改为后端按执行历史下发(issue #270)

- 详情响应新增 `backNodes`:只包含当前记录真实执行过的历史节点,按“最近优先”排序(例如停留在 C 节点时为 B、A),`nodes` 仍保留流程定义全量节点不受影响。
- PC / 移动端退回弹框改用 `backNodes`(`buildReturnNodeOptions`),不再从流程定义节点中截取,避免列出未走过、甚至位于当前节点之后的节点;`backNodes` 为空时不展示退回入口。
- 兼容旧版后端:缺少 `backNodes` 字段时回退到原有按定义顺序截取的逻辑。

- Updated dependencies [0b9b8d6]
- @coding-flow/flow-types@0.2.21
- @coding-flow/flow-core@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-approval-presenter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-approval-presenter",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine approval presenter framework ",
"type": "module",
"sideEffects": [
Expand Down
1 change: 1 addition & 0 deletions packages/flow-approval-presenter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * from '@/hooks';
export * from '@/interceptor';
export * from '@/utils/operator-count';
export * from '@/utils/active-form';
export * from '@/utils/return-nodes';
export { FlowActionPresenter } from '@/presenters/action';
24 changes: 23 additions & 1 deletion packages/flow-approval-presenter/src/presenters/action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApprovalState, FlowApprovalApi } from "@/typings";
import { FormActionContext, FlowAction, FlowSubProcessResetRequest } from "@coding-flow/flow-types";
import { FormActionContext, FlowAction, FlowReissueRequest, FlowSubProcessResetRequest } from "@coding-flow/flow-types";
import {
ActionInterceptor,
ActionInterceptorManager,
Expand Down Expand Up @@ -449,6 +449,28 @@ export class FlowActionPresenter {
}
}

/**
* 已完成流程二次发起(独立能力,非审批动作)。
*
* 仅当详情数据 `reissue` 标识为 true 时可调用:复制当前已完成流程的表单数据
* 创建一条新流程,新流程停在开始节点成为发起人的待办,源流程记录不做改写。
*
* @param advice 二次发起说明(可选)
* @param formData 覆盖复制的表单数据(可选,缺省时复制源流程数据)
*/
public async reissue(advice?: string, formData?: Record<string, any>) {
this.setLoading(true);
try {
const recordId = this.state.flow?.recordId;
if (recordId) {
const body: FlowReissueRequest = { sourceRecordId: recordId, advice, formData };
return await this.api.reissue(body, this.mockKey);
}
} finally {
this.setLoading(false);
}
}

/**
* 执行已订阅的审批操作拦截器。
*
Expand Down
7 changes: 7 additions & 0 deletions packages/flow-approval-presenter/src/typings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ export interface FlowApprovalApi {
* 请求体为 FlowSubProcessResetRequest(recordId + resetInstanceProcessIds + advice)。
*/
resetSubProcess(body: Record<string, any>, mockKey: string): Promise<any>;

/**
* 已完成流程二次发起(独立接口,不属于常规审批动作)。
* 仅当详情数据 reissue 标识为 true 时可调用,
* 请求体为 FlowReissueRequest(sourceRecordId + 可选的 formData / advice)。
*/
reissue(body: Record<string, any>, mockKey: string): Promise<any>;
}
47 changes: 47 additions & 0 deletions packages/flow-approval-presenter/src/utils/return-nodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { FlowContent } from "@coding-flow/flow-types";

/**
* 退回节点下拉选项
*/
export interface ReturnNodeOption {
label: string;
value: string;
}

/**
* 构建退回候选节点。
*
* <p>优先使用后端 `backNodes`:它只包含当前记录真实执行过的历史节点,并已按“最近优先”排序
* (例如停留在 C 节点时为 B、A),避免从流程定义的全量节点 `nodes` 中截取时把未走过、
* 甚至位于当前节点之后的节点也列出来(issue #270)。</p>
*
* <p>`backNodes` 为空数组表示明确没有可退回节点(如开始节点),此时不再回退;
* 只有旧版后端完全不下发该字段时才回退到原有“按定义顺序截取到当前节点”的兼容逻辑。</p>
*
* @param flow 流程详情内容
* @returns 退回候选节点选项,最近优先
*/
export const buildReturnNodeOptions = (flow?: FlowContent): ReturnNodeOption[] => {
if (!flow) {
return [];
}
if (flow.backNodes) {
return flow.backNodes.map(node => ({
label: node.name,
value: node.id,
}));
}
const options: ReturnNodeOption[] = [];
for (const node of flow.nodes || []) {
if (node.id === flow.nodeId) {
break;
}
if (node.display) {
options.push({
label: node.name,
value: node.id,
});
}
}
return options;
};
72 changes: 72 additions & 0 deletions packages/flow-approval-presenter/tests/reissue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { describe, expect, it, rs } from "@rstest/core";
import { FlowActionPresenter } from "@/presenters/action";
import { ApprovalState, FlowApprovalApi } from "@/typings";
import { FormActionContext } from "@coding-flow/flow-types";

/** 已完成的流程记录详情:仅用于验证二次发起的请求参数 */
const buildFinishedState = (): ApprovalState => ({
flow: {
recordId: 88,
reissue: true,
},
} as unknown as ApprovalState);

interface ReissueMock {
mock: { calls: any[][] };
}

const buildApi = () => {
const api: FlowApprovalApi = {
create: rs.fn(async () => 100),
processNodes: rs.fn(async () => []),
action: rs.fn(async () => ({ success: true })),
revoke: rs.fn(async () => ({ success: true })),
urge: rs.fn(async () => ({ success: true })),
resetSubProcess: rs.fn(async () => ({ success: true })),
reissue: rs.fn(async () => ({ success: true, data: 99 })),
};
return api;
};

describe('FlowActionPresenter 二次发起(reissue)', () => {

it('以当前详情记录作为源记录调用二次发起接口', async () => {
const api = buildApi();
const presenter = new FlowActionPresenter(
buildFinishedState(),
api,
new FormActionContext(),
'mockKey',
() => {},
);

const res = await presenter.reissue('业务数据有误,重新发起');

const reissueMock = api.reissue as unknown as ReissueMock;
expect(reissueMock.mock.calls.length).toBe(1);
const [body, mockKey] = reissueMock.mock.calls[0];
expect(body.sourceRecordId).toBe(88);
expect(body.advice).toBe('业务数据有误,重新发起');
expect(mockKey).toBe('mockKey');
expect(res.success).toBe(true);
expect(res.data).toBe(99);
});

it('未提供数据时只提交源记录 id,由服务端复制源流程表单数据', async () => {
const api = buildApi();
const presenter = new FlowActionPresenter(
buildFinishedState(),
api,
new FormActionContext(),
'mockKey',
() => {},
);

await presenter.reissue();

const body = (api.reissue as unknown as ReissueMock).mock.calls[0][0];
expect(body.sourceRecordId).toBe(88);
expect(body.advice).toBeUndefined();
expect(body.formData).toBeUndefined();
});
});
55 changes: 55 additions & 0 deletions packages/flow-approval-presenter/tests/return-nodes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { describe, expect, it } from "@rstest/core";
import { FlowContent, NodeOption } from "@coding-flow/flow-types";
import { buildReturnNodeOptions } from "@/utils/return-nodes";

/** 构造最小可用的节点选项 */
const buildNode = (id: string, name: string, display = true): NodeOption => ({
id,
name,
type: 'APPROVAL',
display,
} as NodeOption);

/** 构造仅包含退回相关字段的流程详情 */
const buildFlow = (data: Partial<FlowContent>): FlowContent => ({
nodeId: 'C',
nodes: [buildNode('A', '开始节点'), buildNode('B', 'B审批'), buildNode('C', 'C审批'), buildNode('D', '结束节点')],
...data,
} as FlowContent);

describe('buildReturnNodeOptions(退回候选节点)', () => {
it('优先使用后端 backNodes,并按最近优先顺序输出', () => {
const flow = buildFlow({
backNodes: [buildNode('B', 'B审批'), buildNode('A', '开始节点')],
});
expect(buildReturnNodeOptions(flow)).toEqual([
{label: 'B审批', value: 'B'},
{label: '开始节点', value: 'A'},
]);
});

it('backNodes 为空数组时表示没有可退回节点,不再按 nodes 截取', () => {
const flow = buildFlow({backNodes: []});
expect(buildReturnNodeOptions(flow)).toEqual([]);
});

it('旧版后端缺失 backNodes 时回退到按定义顺序截取到当前节点', () => {
const flow = buildFlow({});
expect(buildReturnNodeOptions(flow)).toEqual([
{label: '开始节点', value: 'A'},
{label: 'B审批', value: 'B'},
]);
});

it('回退逻辑仍会跳过硬编码 display=false 的节点', () => {
const flow = buildFlow({
nodes: [buildNode('A', '开始节点'), buildNode('X', '隐藏节点', false), buildNode('C', 'C审批')],
nodeId: 'C',
});
expect(buildReturnNodeOptions(flow)).toEqual([{label: '开始节点', value: 'A'}]);
});

it('流程内容为空时返回空列表', () => {
expect(buildReturnNodeOptions(undefined)).toEqual([]);
});
});
2 changes: 2 additions & 0 deletions packages/flow-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @coding-flow/flow-core

## 0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-core",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine core lib framework ",
"type": "module",
"sideEffects": [
Expand Down
3 changes: 3 additions & 0 deletions packages/flow-core/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const FlowMessageKey = {
APPROVAL_RETURN: 'approval.return',
APPROVAL_REVOKE: 'approval.revoke',
APPROVAL_URGE: 'approval.urge',
/** 已完成流程二次发起(复制流程重新执行) */
APPROVAL_REISSUE: 'approval.reissue',
APPROVAL_CUSTOM: 'approval.custom',
/** 保存 — 上下文包含 isStartNode,下游可自行区分 */
APPROVAL_SAVE: 'approval.save',
Expand Down Expand Up @@ -149,6 +151,7 @@ function getDefaultMessages(): Record<string, MessageTemplate> {
[FlowMessageKey.APPROVAL_RETURN]: '操作成功',
[FlowMessageKey.APPROVAL_REVOKE]: '流程已撤回',
[FlowMessageKey.APPROVAL_URGE]: '已发送催办提醒.',
[FlowMessageKey.APPROVAL_REISSUE]: '已重新发起,新流程已回到发起人待办',
[FlowMessageKey.APPROVAL_CUSTOM]: '操作成功',
[FlowMessageKey.APPROVAL_NO_SELECTED]: '请先选择审批流程.',

Expand Down
10 changes: 10 additions & 0 deletions packages/flow-design/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @coding-flow/flow-design

## 0.2.21

### Patch Changes

- Updated dependencies [0b9b8d6]
- @coding-flow/flow-types@0.2.21
- @coding-flow/flow-core@0.2.21
- @coding-flow/flow-icons@0.2.21
- @coding-flow/flow-pc-ui@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-design/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-design",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine design components ",
"type": "module",
"sideEffects": [
Expand Down
6 changes: 6 additions & 0 deletions packages/flow-icons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @coding-flow/flow-icons

## 0.2.21

### Patch Changes

- @coding-flow/flow-core@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-icons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-icons",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine icons ",
"type": "module",
"sideEffects": [
Expand Down
18 changes: 18 additions & 0 deletions packages/flow-mobile/flow-mobile-approval/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @coding-flow/flow-mobile-approval

## 0.2.21

### Patch Changes

- 0b9b8d6: fix: 退回候选节点改为后端按执行历史下发(issue #270)

- 详情响应新增 `backNodes`:只包含当前记录真实执行过的历史节点,按“最近优先”排序(例如停留在 C 节点时为 B、A),`nodes` 仍保留流程定义全量节点不受影响。
- PC / 移动端退回弹框改用 `backNodes`(`buildReturnNodeOptions`),不再从流程定义节点中截取,避免列出未走过、甚至位于当前节点之后的节点;`backNodes` 为空时不展示退回入口。
- 兼容旧版后端:缺少 `backNodes` 字段时回退到原有按定义顺序截取的逻辑。

- Updated dependencies [0b9b8d6]
- @coding-flow/flow-approval-presenter@0.2.21
- @coding-flow/flow-types@0.2.21
- @coding-flow/flow-mobile-form@0.2.21
- @coding-flow/flow-core@0.2.21
- @coding-flow/flow-icons@0.2.21
- @coding-flow/flow-mobile-ui@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-mobile/flow-mobile-approval/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-mobile-approval",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine pc mobile approval components",
"type": "module",
"sideEffects": [
Expand Down
5 changes: 5 additions & 0 deletions packages/flow-mobile/flow-mobile-approval/src/api/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const resetSubProcess = (body:any,mockKey?:string) => {
return httpClient.post('/api/cmd/record/subProcess/reset?mockKey='+key,body);
}

export const reissue = (body:any,mockKey?:string) => {
const key = mockKey?mockKey:'';
return httpClient.post('/api/cmd/record/reissue?mockKey='+key,body);
}

export const list = (request: any,mockKey?:string) => {
const key = mockKey?mockKey:'';
return httpClient.page('/api/query/record/list?mockKey='+key, request, {}, {}, []);
Expand Down
Loading
Loading