feat: 增加审批步骤发起人部门限制

- 增加配置期与提审期合法审批账号校验

- 冻结发起人部门并统一待办与办理权限判断

- 增加兼容迁移、前端联动和自动化测试
This commit is contained in:
2026-07-31 09:38:53 +08:00
parent 0b764b79de
commit 048aa9bc1e
19 changed files with 1089 additions and 18 deletions

View File

@@ -82,6 +82,8 @@
"finishedAt": "Finished At",
"assigneeType": "Assignee Type",
"assigneeTarget": "Assignee",
"restrictToApplicantDept": "Applicant department only",
"applicantDept": "Applicant Department",
"selectedDeptCount": "Selected departments: {value}",
"actedBy": "Acted By",
"actedAt": "Acted At",
@@ -118,6 +120,7 @@
"needStep": "At least one step is required",
"needStepAssignee": "Each approval step requires an assignee",
"confirmAssigneeTypeChange": "Changing the assignee type clears the current selections. Continue?",
"confirmApplicantDeptRestriction": "This will switch to role approval and clear selected departments. Continue?",
"saveSuccess": "Flow saved",
"statusUpdated": "Flow status updated",
"deleteSuccess": "Flow deleted",

View File

@@ -82,6 +82,8 @@
"finishedAt": "完成时间",
"assigneeType": "对象类型",
"assigneeTarget": "审批对象",
"restrictToApplicantDept": "限发起人部门",
"applicantDept": "发起人部门",
"selectedDeptCount": "已选 {value} 个部门",
"actedBy": "处理人",
"actedAt": "处理时间",
@@ -118,6 +120,7 @@
"needStep": "至少需要一个审批步骤",
"needStepAssignee": "每个审批步骤都需要配置审批对象",
"confirmAssigneeTypeChange": "切换审批方式会清空当前已选对象,确认继续吗?",
"confirmApplicantDeptRestriction": "开启后将改为角色审批并清空已选部门,确认继续吗?",
"saveSuccess": "审批流程已保存",
"statusUpdated": "流程状态已更新",
"deleteSuccess": "流程已删除",

View File

@@ -374,6 +374,12 @@ function formatEventInfo(row: Record<string, any>) {
)
}}
</ElDescriptionsItem>
<ElDescriptionsItem
v-if="detail.snapshotJson?.applicantDeptName"
:label="$t('approval.fields.applicantDept')"
>
{{ detail.snapshotJson.applicantDeptName }}
</ElDescriptionsItem>
<ElDescriptionsItem :label="$t('approval.fields.submittedAt')">
{{ detail.submittedAt || '-' }}
</ElDescriptionsItem>

View File

@@ -1,6 +1,8 @@
<script setup lang="ts">
import type { FormInstance } from 'element-plus';
import type { ApprovalAssigneeType as AssigneeType } from './approval-flow-restriction';
import { computed, nextTick, ref, watch } from 'vue';
import { EasyFlowFormModal } from '@easyflow/common-ui';
@@ -23,6 +25,14 @@ import {
import { api } from '#/api/request';
import { $t } from '#/locales';
import {
applyApplicantDeptRestriction,
isApplicantDeptAssigneeTypeDisabled,
needsApplicantDeptRestrictionConfirmation,
normalizeApplicantDeptRestriction,
serializeApplicantDeptRestriction,
} from './approval-flow-restriction';
const emit = defineEmits<{
reload: [];
}>();
@@ -33,7 +43,6 @@ defineExpose({
type ResourceType = '' | 'BOT' | 'KNOWLEDGE' | 'WORKFLOW';
type ActionType = '' | 'DELETE' | 'OFFLINE' | 'PUBLISH';
type AssigneeType = 'DEPT' | 'ROLE' | 'USER';
type ScopeType = 'CATEGORY' | 'DEPT';
type FlowStatus = 'DISABLED' | 'ENABLED';
@@ -55,6 +64,7 @@ interface StepItem {
assigneeType: AssigneeType;
includeChildrenByTarget: Record<string, boolean>;
id?: number | string;
restrictToApplicantDept: boolean;
stepName: string;
}
@@ -191,6 +201,7 @@ function buildDefaultStep(): StepItem {
assigneeTargets: [],
assigneeType: 'ROLE',
includeChildrenByTarget: {},
restrictToApplicantDept: false,
stepName: '',
};
}
@@ -241,6 +252,9 @@ async function openDialog(row: any = {}) {
assigneeType: item.assigneeType || 'ROLE',
id: item.id,
includeChildrenByTarget: buildIncludeChildrenByTarget(targets),
restrictToApplicantDept: normalizeApplicantDeptRestriction(
item.restrictToApplicantDept,
),
stepName: item.stepName,
};
}),
@@ -413,7 +427,13 @@ async function handleAssigneeTypeChange(
step: StepItem,
assigneeType: AssigneeType,
) {
if (step.assigneeType === assigneeType) {
if (
step.assigneeType === assigneeType ||
isApplicantDeptAssigneeTypeDisabled(
step.restrictToApplicantDept,
assigneeType,
)
) {
return;
}
if (step.assigneeTargetIds.length > 0) {
@@ -443,6 +463,32 @@ async function handleAssigneeTypeChange(
}
}
async function handleApplicantDeptRestrictionChange(
step: StepItem,
enabled: boolean | number | string,
) {
const restricted = normalizeApplicantDeptRestriction(enabled);
if (needsApplicantDeptRestrictionConfirmation(step, restricted)) {
try {
await ElMessageBox.confirm(
$t('approval.message.confirmApplicantDeptRestriction'),
$t('approval.fields.restrictToApplicantDept'),
{
cancelButtonText: $t('button.cancel'),
confirmButtonText: $t('button.confirm'),
type: 'warning',
},
);
} catch (error) {
if (error === 'cancel' || error === 'close') {
return;
}
throw error;
}
}
applyApplicantDeptRestriction(step, restricted);
}
function handleAssigneeTargetChange(step: StepItem) {
const selectedIds = new Set(step.assigneeTargetIds.map(String));
step.assigneeTargets = step.assigneeTargets.filter((target) =>
@@ -515,6 +561,9 @@ async function save() {
})),
assigneeType: step.assigneeType,
id: step.id,
restrictToApplicantDept: serializeApplicantDeptRestriction(
step.restrictToApplicantDept,
),
stepName: step.stepName?.trim(),
stepNo: index + 1,
}))
@@ -733,14 +782,25 @@ function closeDialog() {
<span class="approval-flow-modal__step-index">
{{ $t('approval.fields.stepNo', { value: index + 1 }) }}
</span>
<ElButton
text
type="danger"
:disabled="formModel.steps.length <= 1"
@click="removeStep(index)"
>
{{ $t('button.delete') }}
</ElButton>
<div class="approval-flow-modal__step-actions">
<label class="approval-flow-modal__restriction-switch">
<span>{{ $t('approval.fields.restrictToApplicantDept') }}</span>
<ElSwitch
:model-value="step.restrictToApplicantDept"
@change="
(value) => handleApplicantDeptRestrictionChange(step, value)
"
/>
</label>
<ElButton
text
type="danger"
:disabled="formModel.steps.length <= 1"
@click="removeStep(index)"
>
{{ $t('button.delete') }}
</ElButton>
</div>
</div>
<div class="approval-flow-modal__step-grid">
<div class="approval-flow-modal__step-field">
@@ -765,7 +825,17 @@ function closeDialog() {
class="approval-flow-modal__assignee-type-item"
:class="{
'is-active': step.assigneeType === item.value,
'is-disabled': isApplicantDeptAssigneeTypeDisabled(
step.restrictToApplicantDept,
item.value,
),
}"
:disabled="
isApplicantDeptAssigneeTypeDisabled(
step.restrictToApplicantDept,
item.value,
)
"
:aria-pressed="step.assigneeType === item.value"
@click="handleAssigneeTypeChange(step, item.value)"
>
@@ -995,6 +1065,21 @@ function closeDialog() {
border-radius: var(--radius-pill);
}
.approval-flow-modal__step-actions {
display: inline-flex;
gap: var(--space-3);
align-items: center;
}
.approval-flow-modal__restriction-switch {
display: inline-flex;
gap: var(--space-2);
align-items: center;
font-size: 13px;
color: hsl(var(--text-muted));
white-space: nowrap;
}
.approval-flow-modal__step-grid {
display: grid;
grid-template-columns: minmax(0, 1fr);
@@ -1051,6 +1136,15 @@ function closeDialog() {
color: hsl(var(--foreground));
}
.approval-flow-modal__assignee-type-item:disabled {
color: hsl(var(--text-muted) / 48%);
cursor: not-allowed;
}
.approval-flow-modal__assignee-type-item:disabled:hover {
color: hsl(var(--text-muted) / 48%);
}
.approval-flow-modal__assignee-type-item:focus-visible {
outline: 2px solid hsl(var(--primary) / 28%);
outline-offset: 1px;

View File

@@ -0,0 +1,41 @@
import { describe, expect, it } from 'vitest';
import {
applyApplicantDeptRestriction,
isApplicantDeptAssigneeTypeDisabled,
needsApplicantDeptRestrictionConfirmation,
normalizeApplicantDeptRestriction,
serializeApplicantDeptRestriction,
} from './approval-flow-restriction';
describe('approval flow applicant department restriction', () => {
it('normalizes edit values and serializes save values', () => {
expect(normalizeApplicantDeptRestriction(1)).toBe(true);
expect(normalizeApplicantDeptRestriction(undefined)).toBe(false);
expect(serializeApplicantDeptRestriction(true)).toBe(1);
expect(serializeApplicantDeptRestriction(false)).toBe(0);
});
it('switches a department step to role and clears department targets', () => {
const step = {
assigneeTargetIds: [21],
assigneeTargets: [{ targetId: 21 }],
assigneeType: 'DEPT' as const,
includeChildrenByTarget: { '21': true },
restrictToApplicantDept: false,
};
expect(needsApplicantDeptRestrictionConfirmation(step, true)).toBe(true);
applyApplicantDeptRestriction(step, true);
expect(step).toEqual({
assigneeTargetIds: [],
assigneeTargets: [],
assigneeType: 'ROLE',
includeChildrenByTarget: {},
restrictToApplicantDept: true,
});
expect(isApplicantDeptAssigneeTypeDisabled(true, 'DEPT')).toBe(true);
expect(isApplicantDeptAssigneeTypeDisabled(true, 'ROLE')).toBe(false);
});
});

View File

@@ -0,0 +1,46 @@
export type ApprovalAssigneeType = 'DEPT' | 'ROLE' | 'USER';
export interface ApplicantDeptRestrictionStepState<TTarget = unknown> {
assigneeTargetIds: Array<number | string>;
assigneeTargets: TTarget[];
assigneeType: ApprovalAssigneeType;
includeChildrenByTarget: Record<string, boolean>;
restrictToApplicantDept: boolean;
}
export function normalizeApplicantDeptRestriction(value: unknown) {
return value === true || value === 1 || value === '1' || value === 'true';
}
export function needsApplicantDeptRestrictionConfirmation(
step: ApplicantDeptRestrictionStepState,
enabled: boolean,
) {
return (
enabled && step.assigneeType === 'DEPT' && step.assigneeTargetIds.length > 0
);
}
export function applyApplicantDeptRestriction<TTarget>(
step: ApplicantDeptRestrictionStepState<TTarget>,
enabled: boolean,
) {
if (enabled && step.assigneeType === 'DEPT') {
step.assigneeType = 'ROLE';
step.assigneeTargetIds = [];
step.assigneeTargets = [];
step.includeChildrenByTarget = {};
}
step.restrictToApplicantDept = enabled;
}
export function isApplicantDeptAssigneeTypeDisabled(
restricted: boolean,
assigneeType: ApprovalAssigneeType,
) {
return restricted && assigneeType === 'DEPT';
}
export function serializeApplicantDeptRestriction(restricted: boolean) {
return restricted ? 1 : 0;
}