feat: 增加左侧出现一个侧边栏,可以从侧边栏拖动阶段到画布

This commit is contained in:
zhanghao 2026-10-26 17:33:14 +08:00
parent 3a3fd826b0
commit e149fd11aa
19 changed files with 249 additions and 68 deletions

View File

@ -564,3 +564,11 @@ CREATE TABLE pm_collab_stage_revision_member (
CONSTRAINT ck_pm_group_snapshot CHECK((snapshot_json IS NULL AND frozen_at IS NULL) OR (snapshot_json IS NOT NULL AND frozen_at IS NOT NULL AND JSON_VALID(snapshot_json))),
CONSTRAINT ck_pm_group_self CHECK(parent_stage_id<>child_stage_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='项目协作:阶段组版本成员及冻结历史';
-- 画布分类固定于阶段身份,不随执行版本变化;历史普通阶段使用 STAGE。
ALTER TABLE pm_collab_project_stage
ADD COLUMN node_type VARCHAR(24) NOT NULL DEFAULT 'STAGE' COMMENT '固定节点类型:GROUP阶段组,REQUIREMENT需求,PROPOSAL方案,PURCHASE采购,DESIGN设计,MACHINING加工,ASSEMBLY组装,DEBUGGING调试,DEVELOPMENT研发,TESTING测试,STAGE历史普通阶段',
ADD CONSTRAINT ck_pm_stage_node_type CHECK (
(node_type='GROUP' AND stage_kind='GROUP') OR
(node_type IN ('STAGE','REQUIREMENT','PROPOSAL','PURCHASE','DESIGN','MACHINING','ASSEMBLY','DEBUGGING','DEVELOPMENT','TESTING') AND stage_kind='WORK')
);

View File

@ -0,0 +1,22 @@
-- 项目协作:画布节点分类。021 后执行,可重复执行;保留阶段、版本、工作项和排期。
-- 类型只在创建时选择,历史工作阶段保留 STAGE(普通阶段),阶段组保留 GROUP。
SET NAMES utf8mb4;
SET @pm_node_column_exists=(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='pm_collab_project_stage' AND COLUMN_NAME='node_type');
SET @pm_node_ddl=IF(@pm_node_column_exists=0,
'ALTER TABLE pm_collab_project_stage ADD COLUMN node_type VARCHAR(24) NOT NULL DEFAULT ''STAGE'' COMMENT ''固定节点类型:GROUP阶段组,REQUIREMENT需求,PROPOSAL方案,PURCHASE采购,DESIGN设计,MACHINING加工,ASSEMBLY组装,DEBUGGING调试,DEVELOPMENT研发,TESTING测试,STAGE历史普通阶段''',
'SELECT 1');
PREPARE pm_node_stmt FROM @pm_node_ddl;
EXECUTE pm_node_stmt;
DEALLOCATE PREPARE pm_node_stmt;
-- 新列默认值用于旧工作阶段;仅首次升级时补齐已有组的分类,不更改结构或版本。
UPDATE pm_collab_project_stage SET node_type='GROUP' WHERE stage_kind='GROUP' AND node_type='STAGE';
SET @pm_node_constraint_exists=(SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA=DATABASE() AND TABLE_NAME='pm_collab_project_stage' AND CONSTRAINT_NAME='ck_pm_stage_node_type');
SET @pm_node_ddl=IF(@pm_node_constraint_exists=0,
'ALTER TABLE pm_collab_project_stage ADD CONSTRAINT ck_pm_stage_node_type CHECK ((node_type=''GROUP'' AND stage_kind=''GROUP'') OR (node_type IN (''STAGE'',''REQUIREMENT'',''PROPOSAL'',''PURCHASE'',''DESIGN'',''MACHINING'',''ASSEMBLY'',''DEBUGGING'',''DEVELOPMENT'',''TESTING'') AND stage_kind=''WORK''))',
'SELECT 1');
PREPARE pm_node_stmt FROM @pm_node_ddl;
EXECUTE pm_node_stmt;
DEALLOCATE PREPARE pm_node_stmt;

View File

@ -0,0 +1,25 @@
package com.ruoyi.project.manage.domain;
import com.ruoyi.project.manage.exception.PmException;
/** 画布节点的固定业务类型;仅 GROUP 承载子阶段,其余类型共用工作阶段的执行规则。 */
public enum StageNodeType {
GROUP, REQUIREMENT, PROPOSAL, PURCHASE, DESIGN, MACHINING, ASSEMBLY, DEBUGGING, DEVELOPMENT, TESTING, STAGE;
/** 将分类映射为既有结构类型,返回 GROUP 容器或 WORK 工作阶段,不改变执行和排期规则。 */
public String kind() { return this == GROUP ? "GROUP" : "WORK"; }
/**
* 解析创建请求中的节点分类,兼容旧客户端仅提交 WORK/GROUP 的形式。
* @param nodeType 画布分类;省略时保留普通阶段或阶段组的旧语义
* @param stageKind 可选的结构类型;与分类矛盾时拒绝,不能把工作节点转成容器
* @return 已校验的固定分类;非法分类或组合抛出字段错误
*/
public static StageNodeType resolve(String nodeType, String stageKind) {
StageNodeType type;
try { type = nodeType == null ? ("GROUP".equals(stageKind) ? GROUP : STAGE) : valueOf(nodeType); }
catch (IllegalArgumentException invalid) { throw PmException.bad("节点类型无效"); }
if (stageKind != null && !type.kind().equals(stageKind)) throw PmException.bad("节点类型与阶段结构不匹配");
return type;
}
}

View File

@ -1,7 +1,9 @@
package com.ruoyi.project.manage.dto;
/** 阶段创建同时提交组织身份和整日计划;编辑不允许通过元数据接口偷偷迁移父级。 */
public record StageInput(String name,Integer sortOrder,Long ownerId,String description,Integer version,String stageKind,Long parentStageId,String plannedStartAt,String plannedEndAt) {
/** 阶段创建同时提交固定节点分类、组织身份和整日计划;编辑不能迁移父级或修改节点类型。 */
public record StageInput(String name,Integer sortOrder,Long ownerId,String description,Integer version,String stageKind,Long parentStageId,String plannedStartAt,String plannedEndAt,String nodeType) {
/** 兼容仅提交结构身份的内部调用;缺失分类时按普通阶段或阶段组处理。 */
public StageInput(String name,Integer sortOrder,Long ownerId,String description,Integer version,String stageKind,Long parentStageId,String plannedStartAt,String plannedEndAt) { this(name,sortOrder,ownerId,description,version,stageKind,parentStageId,plannedStartAt,plannedEndAt,null); }
/** 原内部元数据调用省略结构字段;创建入口仍要求显式有效计划。 */
public StageInput(String name,Integer sortOrder,Long ownerId,String description,Integer version) { this(name,sortOrder,ownerId,description,version,null,null,null,null); }
}

View File

@ -216,7 +216,7 @@ public class PmIterationServiceImpl implements IPmIterationService {
* 一次复制先建立阶段 ID 映射,再写边和新 v1,不携带来源执行事实。
* @param source 同项目来源迭代,允许终态和归档,但历史负责人可能已经离开项目
* @param target 本事务创建的筹备迭代,所有新对象使用独立 ID
* @return 无法继续分配的负责人清空说明,随创建结果保存供幂等重放
* @return 无法继续分配的负责人清空说明,随创建结果保存供幂等重放;复制仍保留固定节点分类
* 注意:只调整新阶段及新快照,不改写来源阶段;项目锁覆盖当前成员资格读取及全部复制。
*/
private List<Map<String,Object>> copyStructure(long projectId,long source,long target,long actor,long now) {
@ -233,7 +233,7 @@ public class PmIterationServiceImpl implements IPmIterationService {
}
Long oldParent=nullable(stage,"parent_stage_id"),parent=oldParent==null?null:ids.get(oldParent);
if(oldParent!=null&&parent==null) throw new IllegalStateException("复制来源的父阶段组缺失");
Map<String,Object> values=map("project_id",projectId,"iteration_id",target,"name",stage.get("name"),"sort_order",stage.get("sort_order"),"owner_id",owner,"description",stage.get("description"),"stage_kind",stage.get("stage_kind"),"parent_stage_id",parent,"created_by",actor,"created_at",now);
Map<String,Object> values=map("project_id",projectId,"iteration_id",target,"name",stage.get("name"),"sort_order",stage.get("sort_order"),"owner_id",owner,"description",stage.get("description"),"stage_kind",stage.get("stage_kind"),"node_type",stage.get("node_type"),"parent_stage_id",parent,"created_by",actor,"created_at",now);
long id=mapper.insertCopiedStage(values); ids.put(number(stage,"id"),id);
values.put("stage_id",id); values.remove("id");
long revision=mapper.insertCopiedRevision(values);

View File

@ -7,6 +7,7 @@ import com.ruoyi.project.manage.dto.VersionInput;
import com.ruoyi.project.manage.exception.PmException;
import com.ruoyi.project.manage.domain.Graph;
import com.ruoyi.project.manage.domain.StageLink;
import com.ruoyi.project.manage.domain.StageNodeType;
import com.ruoyi.project.manage.mapper.PmRevisionMapper;
import com.ruoyi.project.manage.mapper.PmStageMapper;
import com.ruoyi.project.manage.mapper.PmWorkItemMapper;
@ -105,11 +106,18 @@ public class PmStageServiceImpl implements IPmStageService {
return map("reworkEdges",reworkEdges,"iterationId",iterationId,"graphVersion",number(revisionMapper.selectGraphVersion(projectId,iterationId),"graph_version"),"stages",stages,"stageEdges",stageEdges,"unassigned",summary(items,null,graph),"items",List.of(),"dependencies",List.of());
}
/** 创建空阶段时原子保存首版计划和父级组合;手工创建必须填写日期,系统换版使用独立内部入口。 */
/**
* 创建时固定节点分类,在项目锁内原子保存阶段、首版计划、父级组合、历史及事件。
* @param projectId 已鉴权的协作项目 ID
* @param iterationId 明确的可编辑迭代,不能跨迭代指定父级
* @param input 固定分类、可编辑名称和整日计划;仅 GROUP 可承载子阶段
* @return 新阶段 ID,供浏览器保存本地落点
* 注意:分类非法、父级已执行或计划冲突时整体回滚,不能留下空版本或成功事件。
*/
public long createStage(long projectId,long iterationId,StageInput input) {
locked(projectId,iterationId,"admin"); validateStage(projectId,input);
String kind=input.stageKind()==null?"WORK":input.stageKind();
if(!Set.of("WORK","GROUP").contains(kind)) throw PmException.bad("阶段类型无效");
StageNodeType nodeType=StageNodeType.resolve(input.nodeType(),input.stageKind());
String kind=nodeType.kind();
if("GROUP".equals(kind)&&input.parentStageId()!=null) throw PmException.conflict("STAGE_HIERARCHY_INVALID","阶段组只能创建在根画布,不支持第三层阶段");
var plan=PmTime.planned(input.plannedStartAt(),input.plannedEndAt());
if(plan.start()==null||plan.end()==null||plan.end()<plan.start()) throw PmException.bad("新建阶段必须填写有效的预计开始和结束日期");
@ -120,7 +128,7 @@ public class PmStageServiceImpl implements IPmStageService {
requireNoExecutionHistory(projectId,iterationId,input.parentStageId());
}
long id=stageMapper.insertStage(map("project_id",projectId,"iteration_id",iterationId,"name",input.name().trim(),"sort_order",input.sortOrder()==null?0:input.sortOrder(),
"stage_kind",kind,"parent_stage_id",input.parentStageId(),"owner_id",input.ownerId(),"description",input.description(),"created_by",access.actor(),"created_at",PmTime.now()));
"stage_kind",kind,"node_type",nodeType.name(),"parent_stage_id",input.parentStageId(),"owner_id",input.ownerId(),"description",input.description(),"created_by",access.actor(),"created_at",PmTime.now()));
long revision=revisionMapper.insertRevision(map("project_id",projectId,"iteration_id",iterationId,"stage_id",id,"revision_no",1,"stage_name_snapshot",input.name().trim(),"stage_owner_snapshot",input.ownerId(),"stage_kind_snapshot",kind,"parent_stage_snapshot_id",input.parentStageId(),"stage_description_snapshot",input.description(),"planned_start_at",plan.start(),"planned_end_at",plan.end(),"plan_source","NORMAL","plan_recorded_at",PmTime.now(),"created_by",access.actor(),"created_at",PmTime.now()));
if(revisionMapper.initializeCurrentRevision(projectId,id,revision)!=1) throw PmException.conflict("VERSION_CONFLICT","阶段初始版本建立失败");
groups.bind(projectId,iterationId); Graph after=graphService.load(projectId,iterationId);
@ -129,19 +137,25 @@ public class PmStageServiceImpl implements IPmStageService {
auditService.record(projectId,iterationId,null,"STAGE_CREATED",map("stageId",id,"name",input.name().trim()),access.actor()); return id;
}
/** 在统一项目锁下版本更新阶段元数据,不改变工作项状态、预计时间或有效依赖。 */
/**
* 在统一项目锁内按版本编辑名称、负责人及说明,节点分类和 WORK/GROUP 结构不允许转换。
* @param projectId 阶段所属的协作项目 ID
* @param iterationId 所属可编辑迭代,权限与版本均在持锁后复查
* @param id 需要编辑的有效阶段 ID
* @param input 元数据及当前版本;改期和父级迁移必须使用既有专用入口
* 注意:分类变更或旧版本请求会被拒绝并回滚,历史与事件仅随成功编辑提交。
*/
public void editStage(long projectId,long iterationId,long id,StageInput input) {
locked(projectId,iterationId,"admin"); Map<String,Object> existing=stage(projectId,iterationId,id); version(input.version(),(int)number(existing,"version")); validateStage(projectId,input);
Graph before=graphService.load(projectId,iterationId),after=before.copy();
String kind=input.stageKind()==null?text(existing,"stage_kind"):input.stageKind();
if(!Set.of("WORK","GROUP").contains(kind)) throw PmException.bad("阶段类型无效");
String kind=text(existing,"stage_kind");
StageNodeType existingType=StageNodeType.resolve(text(existing,"node_type"),kind);
if ((input.nodeType()!=null&&!existingType.name().equals(input.nodeType()))||(input.stageKind()!=null&&!kind.equals(input.stageKind()))) throw PmException.conflict("STAGE_NODE_TYPE_LOCKED","节点类型创建后不可修改");
if(input.parentStageId()!=null&&!Objects.equals(input.parentStageId(),nullable(existing,"parent_stage_id"))) throw PmException.bad("请使用结构调整入口修改父级");
if(!kind.equals(text(existing,"stage_kind"))&&(workItemMapper.selectItemInStage(projectId,id)!=null||!com.ruoyi.project.manage.rule.PmStageHierarchyRules.children(before,id).isEmpty()||!"NOT_STARTED".equals(PmStageRules.executionStatus(before,id)))) throw PmException.conflict("STAGE_KIND_LOCKED","仅未执行的空阶段可以转换类型");
if(!kind.equals(text(existing,"stage_kind"))&&revisionMapper.selectStageRevisions(projectId,iterationId,id).stream().anyMatch(row->nullable(row,"started_at")!=null)) throw PmException.conflict("STAGE_KIND_LOCKED","曾执行的阶段不能转换类型");
if(input.plannedStartAt()!=null||input.plannedEndAt()!=null) throw PmException.bad("阶段改期请使用版本排期入口");
after.hierarchy().put(id,new com.ruoyi.project.manage.domain.StageInfo(id,kind,nullable(existing,"parent_stage_id"),input.description()));
PmRules.validateAcyclic(after); PmStageRules.validateExecutedAncestors(before,after);
stageMapper.updateStage(id,(int)number(existing,"version"),map("stage_kind",kind,"name",input.name().trim(),"sort_order",input.sortOrder()==null?0:input.sortOrder(),"owner_id",input.ownerId(),"description",input.description()));
stageMapper.updateStage(id,(int)number(existing,"version"),map("name",input.name().trim(),"sort_order",input.sortOrder()==null?0:input.sortOrder(),"owner_id",input.ownerId(),"description",input.description()));
stageMapper.refreshDraftRevisionIdentity(number(existing,"current_revision_id"),kind,nullable(existing,"parent_stage_id"),input.description());
groups.bind(projectId,iterationId); snapshotDefinition(projectId,iterationId);
auditService.record(projectId,iterationId,null,"STAGE_EDITED",map("stageId",id,"name",input.name().trim()),access.actor());

View File

@ -53,7 +53,7 @@
OR completed_at IS NOT NULL OR superseded_at IS NOT NULL OR legacy_passed_at IS NOT NULL))
</select>
<select id="selectCopyStages" resultType="java.util.LinkedHashMap">
SELECT id,name,sort_order,owner_id,description,stage_kind,parent_stage_id FROM pm_collab_project_stage
SELECT id,name,sort_order,owner_id,description,stage_kind,node_type,parent_stage_id FROM pm_collab_project_stage
WHERE project_id=#{projectId} AND iteration_id=#{iterationId} AND deleted=false ORDER BY (parent_stage_id IS NOT NULL),sort_order,id
</select>
<select id="selectCopyEdges" resultType="java.util.LinkedHashMap">
@ -63,8 +63,8 @@
WHERE e.project_id=#{projectId} AND e.iteration_id=#{iterationId} ORDER BY e.id
</select>
<insert id="insertCopiedStageRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
INSERT INTO pm_collab_project_stage(project_id,iteration_id,name,sort_order,owner_id,description,stage_kind,parent_stage_id,created_by,created_at)
VALUES(#{values.project_id},#{values.iteration_id},#{values.name},#{values.sort_order},#{values.owner_id},#{values.description},#{values.stage_kind},#{values.parent_stage_id},#{values.created_by},#{values.created_at})
INSERT INTO pm_collab_project_stage(project_id,iteration_id,name,sort_order,owner_id,description,stage_kind,node_type,parent_stage_id,created_by,created_at)
VALUES(#{values.project_id},#{values.iteration_id},#{values.name},#{values.sort_order},#{values.owner_id},#{values.description},#{values.stage_kind},#{values.node_type},#{values.parent_stage_id},#{values.created_by},#{values.created_at})
</insert>
<insert id="insertCopiedRevisionRow" useGeneratedKeys="true" keyProperty="values.id" keyColumn="id">
INSERT INTO pm_collab_stage_revision(project_id,iteration_id,stage_id,revision_no,stage_name_snapshot,stage_owner_snapshot,stage_kind_snapshot,parent_stage_snapshot_id,stage_description_snapshot,created_by,created_at)

View File

@ -18,7 +18,7 @@
<select id="selectVisibleStages" resultType="java.util.LinkedHashMap">
<!-- 仅返回当前版本的回退来源,避免画布把有历史回退记录的正常阶段持续标记为待重做。 -->
SELECT s.id,s.name,s.stage_kind AS stageKind,s.parent_stage_id AS parentStageId,s.sort_order AS sortOrder,s.owner_id AS ownerId,u.nick_name AS ownerName,s.description,s.version,s.current_revision_id AS currentRevisionId,r.revision_no AS revisionNo,r.rework_id AS reworkId,s.created_by AS creatorId,s.created_at AS createdAt,
SELECT s.id,s.name,s.stage_kind AS stageKind,s.node_type AS nodeType,s.parent_stage_id AS parentStageId,s.sort_order AS sortOrder,s.owner_id AS ownerId,u.nick_name AS ownerName,s.description,s.version,s.current_revision_id AS currentRevisionId,r.revision_no AS revisionNo,r.rework_id AS reworkId,s.created_by AS creatorId,s.created_at AS createdAt,
EXISTS(SELECT 1 FROM pm_collab_stage_revision h WHERE h.stage_id=s.id AND h.project_id=s.project_id AND (h.started_at IS NOT NULL OR h.legacy_passed_at IS NOT NULL)) AS executionHistory
FROM pm_collab_project_stage s LEFT JOIN sys_user u ON u.user_id=s.owner_id
LEFT JOIN pm_collab_stage_revision r ON r.id=s.current_revision_id
@ -39,6 +39,7 @@
<if test="values.containsKey('project_id')">project_id,</if>
<if test="values.containsKey('iteration_id')">iteration_id,</if>
<if test="values.containsKey('stage_kind')">stage_kind,</if>
<if test="values.containsKey('node_type')">node_type,</if>
<if test="values.containsKey('parent_stage_id')">parent_stage_id,</if>
<if test="values.containsKey('name')">name,</if>
<if test="values.containsKey('sort_order')">sort_order,</if>
@ -54,6 +55,7 @@
<if test="values.containsKey('project_id')">#{values.project_id},</if>
<if test="values.containsKey('iteration_id')">#{values.iteration_id},</if>
<if test="values.containsKey('stage_kind')">#{values.stage_kind},</if>
<if test="values.containsKey('node_type')">#{values.node_type},</if>
<if test="values.containsKey('parent_stage_id')">#{values.parent_stage_id},</if>
<if test="values.containsKey('name')">#{values.name},</if>
<if test="values.containsKey('sort_order')">#{values.sort_order},</if>
@ -70,7 +72,6 @@
UPDATE pm_collab_project_stage
<set>
<if test="values.containsKey('project_id')">project_id=#{values.project_id},</if>
<if test="values.containsKey('stage_kind')">stage_kind=#{values.stage_kind},</if>
<if test="values.containsKey('parent_stage_id')">parent_stage_id=#{values.parent_stage_id},</if>
<if test="values.containsKey('name')">name=#{values.name},</if>
<if test="values.containsKey('sort_order')">sort_order=#{values.sort_order},</if>

View File

@ -57,6 +57,9 @@ manage/
## 工作项分工与前置条件
- 阶段节点展示已有描述的两行摘要,完整说明在阶段抽屉查看;拖入新阶段时可填写描述。
- 流程画布左侧节点库提供阶段组、需求、方案、采购、设计、加工、组装、调试、研发和测试,支持搜索与拖放。普通类型拖入组内(包括子节点上方)自动归属,组本身仍只支持根画布;未执行及历史保护规则保持不变。
- 节点分类创建后固定,名称、负责人和说明可编辑;只有阶段组承载子阶段,其余分类沿用工作阶段规则。组内快捷创建可在提交前选择工作分类;复制迭代保留来源分类,回退换版沿用同一节点身份。
- 已有数据库上线前执行 `ruoyi-project/sql/upgrade/022_stage_node_types.sql`;脚本可重复执行,已有工作阶段标为普通阶段,已有组标为阶段组,不改动排期、执行版本或工作项。新安装结构已包含分类字段和组合约束。
- 新建和编辑工作项可从项目成员中多选协作人,负责人仍为单选。协作分工不改变项目角色或访问权限,历史版本保留原分工;回退复制仅继承仍有效的成员,并在预览中说明移除项。
- 新建工作项可选多个同迭代前置工作项,需求、任务、缺陷均可作为依赖两端。所有前置已完成或已关闭才满足条件,取消不满足;编辑依赖仍使用详情中的专用入口。
- 依赖、工作项和协作分工在同一项目锁事务中保存,继续共用实际开始、排期及混合执行图环检测。新建表单排期提示由后端约束预览计算,提交时重新验证。

View File

@ -1,8 +1,9 @@
<template>
<el-dialog :close-on-click-modal="false" :model-value="visible" :title="parent ? `新建子阶段 · ${parent.name}` : '新建阶段'" width="540px" append-to-body @close="emit('close')">
<el-dialog :close-on-click-modal="false" :model-value="visible" :title="parent ? `新建子阶段 · ${parent.name}` : '新建阶段'" width="min(540px, 94vw)" append-to-body @close="emit('close')">
<el-form size="small" label-position="top" @submit.prevent>
<el-form-item v-if="!parent" label="阶段类型"><el-radio-group v-model="draft.stageKind"><el-radio-button value="WORK">工作阶段</el-radio-button><el-radio-button value="GROUP">阶段组</el-radio-button></el-radio-group></el-form-item>
<p class="hint">{{ draft.stageKind === 'GROUP' ? '阶段组只承载子阶段,全部子阶段完成后才放行后续。' : '工作阶段可以保持为空;添加工作项并全部完成后才放行后续。' }}</p>
<el-form-item label="节点类型(创建后不可修改)"><el-tag v-if="nodeType" size="small">{{ stageNodeTypeLabel({ nodeType: draft.nodeType }) }}</el-tag><el-select v-else v-model="draft.nodeType" placeholder="选择节点类型"><el-option v-for="type in WORK_STAGE_NODE_TYPES" :key="type.value" :value="type.value" :label="type.label" /></el-select></el-form-item>
<p v-if="parent" class="hint">所属阶段组:{{ parent.name }}</p>
<p class="hint">{{ draft.nodeType === 'GROUP' ? '阶段组只承载子阶段,全部子阶段完成后才放行后续。' : '工作阶段可以保持为空;添加工作项并全部完成后才放行后续。' }}</p>
<el-form-item label="阶段名称" required><el-input v-model="draft.name" maxlength="120" /></el-form-item>
<el-form-item label="阶段描述"><el-input v-model="draft.description" type="textarea" :rows="3" maxlength="10000" placeholder="说明本阶段需要完成的事项" /></el-form-item>
<el-form-item label="阶段负责人"><el-select v-model="draft.ownerId" clearable><el-option v-for="member in members" :key="member.userId" :value="member.userId" :label="member.name" /></el-select></el-form-item>
@ -14,23 +15,24 @@
</template>
<script setup lang="ts">
import { onBeforeUnmount, reactive, ref, watch } from 'vue'
import type { Member, Stage } from '../../../types'
import type { Member, Stage, StageNodeType } from '../../../types'
import { api, errorText } from '../../../api'
import TimeField from '../../../shared/components/TimeField.vue'
const props = defineProps<{ visible: boolean; projectId: number; iterationId?: number; parent?: Stage | null; members: Member[] }>()
import { stageNodeTypeLabel, WORK_STAGE_NODE_TYPES } from '../../../shared/constants/stageNodeTypes'
const props = defineProps<{ visible: boolean; projectId: number; iterationId?: number; parent?: Stage | null; nodeType?: StageNodeType; members: Member[] }>()
const emit = defineEmits<{ close: []; created: [id: number] }>()
const busy = ref(false), failure = ref('')
const draft = reactive({ name: '', description: '', stageKind: 'WORK' as 'WORK' | 'GROUP', ownerId: null as number | null, plannedStartAt: null as string | null, plannedEndAt: null as string | null })
const draft = reactive({ name: '', description: '', nodeType: 'REQUIREMENT' as StageNodeType, ownerId: null as number | null, plannedStartAt: null as string | null, plannedEndAt: null as string | null })
let generation = 0
/** 每次创建重置类型与日期,子阶段固定为工作阶段,不继承旧迭代的草稿。 */
watch(() => props.visible, visible => { generation++; if (visible) { Object.assign(draft, { name: '', description: '', stageKind: 'WORK', ownerId: null, plannedStartAt: null, plannedEndAt: null }); failure.value = '' } })
/** 每次打开从素材分类重置草稿;组内快捷创建只提供工作分类,不继承其他迭代的输入。 */
watch(() => props.visible, visible => { generation++; if (visible) { Object.assign(draft, { name: '', description: '', nodeType: props.nodeType || 'REQUIREMENT', ownerId: null, plannedStartAt: null, plannedEndAt: null }); failure.value = '' } })
/** 离开项目或迭代后不再处理旧创建请求的界面回调,服务端事务结果仍由后续同步读取。 */
onBeforeUnmount(() => { generation++ })
/** 日期与结构在同一后端事务创建;失败保留输入以便调整父级范围。 */
/** 固定分类与整日计划在同一事务创建;结构类型由分类派生,失败保留草稿供修正日期等输入。 */
async function save() {
if (busy.value || !draft.name.trim() || !draft.plannedStartAt || !draft.plannedEndAt) return
const request = generation; busy.value = true; failure.value = ''
try { const id = await api.createStage(props.projectId, { ...draft, name: draft.name.trim(), sortOrder: 0, parentStageId: props.parent?.id ?? null }, props.iterationId); if (request === generation) emit('created', id) }
try { const id = await api.createStage(props.projectId, { ...draft, stageKind: draft.nodeType === 'GROUP' ? 'GROUP' : 'WORK', name: draft.name.trim(), sortOrder: 0, parentStageId: props.parent?.id ?? null }, props.iterationId); if (request === generation) emit('created', id) }
catch (error) { if (request === generation) failure.value = errorText(error) } finally { busy.value = false }
}
</script>

View File

@ -1,18 +1,20 @@
<template>
<el-dialog :close-on-click-modal="false" :model-value="visible" title="项目阶段" width="780px" append-to-body @close="emit('close')">
<el-alert title="在流程画布拖入阶段并手工连线确定执行顺序;前置阶段全部工作项完成或关闭后,下游工作项才可开始。含工作项的阶段须先调整归属再删除。" type="info" :closable="false" />
<el-dialog :close-on-click-modal="false" :model-value="visible" title="项目阶段" width="min(1100px, 96vw)" append-to-body @close="emit('close')">
<div class="stage-manager-content">
<el-alert title="从左侧节点库拖入阶段并手工连线确定执行顺序;前置阶段全部工作项完成或关闭后,下游工作项才可开始。含工作项的阶段须先调整归属再删除。" type="info" :closable="false" />
<el-button v-if="iterationId && view" size="small" class="structure-button" @click="structureOpen = true">调整阶段层级与连线</el-button>
<el-table :data="stages" size="small" max-height="450">
<el-table-column label="阶段" min-width="180"><template #default="{ row }">{{ row.stagePath || row.name }}<el-tag v-if="row.stageKind === 'GROUP'" size="small" type="info">阶段组</el-tag></template></el-table-column>
<el-table-column label="负责人" width="120"><template #default="{ row }">{{ row.ownerName || '未分配' }}</template></el-table-column>
<el-table-column label="工作项" width="80"><template #default="{ row }">{{ row.counts.total }}</template></el-table-column><el-table-column label="完成" width="80"><template #default="{ row }">{{ row.complete ? '已完成' : '未完成' }}</template></el-table-column>
<el-table :data="stages" size="small" table-layout="fixed" max-height="min(55vh, 520px)" class="stage-table">
<el-table-column label="阶段" min-width="245"><template #default="{ row }"><div class="stage-name"><el-tag size="small" type="info">{{ stageNodeTypeLabel(row) }}</el-tag><span :title="row.stagePath || row.name">{{ row.stagePath || row.name }}</span></div></template></el-table-column>
<el-table-column label="负责人" width="100" show-overflow-tooltip><template #default="{ row }">{{ row.ownerName || '未分配' }}</template></el-table-column>
<el-table-column label="工作项" width="70"><template #default="{ row }">{{ row.counts.total }}</template></el-table-column><el-table-column label="完成" width="80"><template #default="{ row }">{{ row.complete ? '已完成' : '未完成' }}</template></el-table-column>
<el-table-column label="描述" prop="description" min-width="200" show-overflow-tooltip />
<el-table-column label="操作" width="145" class-name="business-operation-cell"><template #default="{ row }"><el-button link type="primary" @click="open(row)">编辑</el-button><el-tooltip content="请先移动阶段中的工作项" :disabled="!row.counts.total"><span><el-button link type="danger" :disabled="!!row.counts.total || !!row.childStageCount || busy" @click="remove(row)">删除</el-button></span></el-tooltip></template></el-table-column>
<el-table-column label="操作" width="126" fixed="right" class-name="business-operation-cell"><template #default="{ row }"><div class="stage-operations"><el-button size="small" link type="primary" @click="open(row)">编辑</el-button><el-tooltip :content="row.childStageCount ? '请先移出或删除组内子阶段' : '请先移动阶段中的工作项'" :disabled="!row.counts.total && !row.childStageCount"><span><el-button size="small" link type="danger" :disabled="!!row.counts.total || !!row.childStageCount || busy" @click="remove(row)">删除</el-button></span></el-tooltip></div></template></el-table-column>
</el-table>
<el-alert v-if="failure" type="error" :title="failure" :closable="false" class="failure" />
<el-dialog :close-on-click-modal="false" v-model="editorOpen" title="编辑阶段" width="520px" append-to-body>
</div>
<el-dialog :close-on-click-modal="false" v-model="editorOpen" title="编辑阶段" width="min(520px, 94vw)" append-to-body>
<el-form label-position="top" size="small">
<el-form-item v-if="!editing?.parentStageId" label="阶段类型"><el-select v-model="draft.stageKind" :disabled="!editing?.canEditStructure || !!editing?.counts.total || !!editing?.childStageCount"><el-option label="工作阶段" value="WORK" /><el-option label="阶段组" value="GROUP" /></el-select></el-form-item>
<el-form-item v-if="editing" label="节点类型(不可修改)"><el-tag size="small" type="info">{{ stageNodeTypeLabel(editing) }}</el-tag></el-form-item>
<el-form-item label="阶段名称" required><el-input v-model="draft.name" maxlength="120" /></el-form-item>
<el-form-item label="阶段负责人"><el-select v-model="draft.ownerId" clearable placeholder="未分配"><el-option v-for="member in members" :key="member.userId" :value="member.userId" :label="member.name" /></el-select></el-form-item>
<el-form-item label="阶段描述"><el-input v-model="draft.description" type="textarea" :rows="3" maxlength="10000" placeholder="说明本阶段需要完成的事项" /></el-form-item>
@ -29,19 +31,21 @@ import { ElMessageBox } from 'element-plus'
import { api, errorText } from '../../../api'
import StageStructureDialog from './StageStructureDialog.vue'
import type { Stage, StageInput, Member, FlowView } from '../../../types'
import { stageNodeTypeLabel } from '../../../shared/constants/stageNodeTypes'
const props = defineProps<{ visible: boolean; projectId: number; iterationId?: number; stages: Stage[]; members: Member[]; view?: FlowView }>()
const emit = defineEmits<{ close: []; changed: [] }>()
const structureOpen = ref(false)
const editing = ref<Stage | null>(null), editorOpen = ref(false), busy = ref(false), failure = ref(''), editorFailure = ref('')
const draft = reactive<StageInput>({ name: '', sortOrder: 0, ownerId: null, description: '' })
watch(() => props.visible, visible => { if (!visible) { editorOpen.value = false; structureOpen.value = false } failure.value = '' })
/** 只编辑现有阶段元数据;新增阶段由画布拖入操作提供明确落点。 */
function open(stage: Stage) { editing.value = stage; Object.assign(draft, { name: stage.name, sortOrder: stage.sortOrder, ownerId: stage.ownerId ?? null, description: stage.description || '', stageKind: stage.stageKind || 'WORK', version: stage.version }); editorFailure.value = ''; editorOpen.value = true }
/** 类型仅作只读展示;编辑草稿保留原分类,改名或说明不会把既有阶段转换为其他类型。 */
function open(stage: Stage) { editing.value = stage; Object.assign(draft, { name: stage.name, sortOrder: stage.sortOrder, ownerId: stage.ownerId ?? null, description: stage.description || '', stageKind: stage.stageKind || 'WORK', nodeType: stage.nodeType, version: stage.version }); editorFailure.value = ''; editorOpen.value = true }
/** 保存经经理鉴权与阶段版本校验的元数据,失败保留草稿。 */
async function save() { if (!editing.value) return; busy.value = true; editorFailure.value = ''; try { await api.editStage(props.projectId, editing.value.id, { ...draft }, props.iterationId); editorOpen.value = false; emit('changed') } catch (error) { editorFailure.value = errorText(error) } finally { busy.value = false } }
/** 经产品内确认软删除空阶段,后端仍在项目锁内重查是否为空。 */
async function remove(stage: Stage) { try { await ElMessageBox.confirm('删除这个空阶段?历史数据将保留。', '删除阶段', { type: 'warning', closeOnClickModal: false }) } catch { return } busy.value = true; failure.value = ''; try { await api.removeStage(props.projectId, stage.id, stage.version, props.iterationId); emit('changed') } catch (error) { failure.value = errorText(error) } finally { busy.value = false } }
</script>
<style scoped>.failure{margin-top:12px;white-space:pre-line}.structure-button{margin:10px 0}
.stage-manager-content{max-height:calc(100vh - 175px);overflow:auto;min-width:0}.stage-table{width:100%;min-width:0}.stage-name{display:flex;align-items:center;gap:6px;min-width:0}.stage-name :deep([class~="el-tag"]){flex:none}.stage-name>span{min-width:0;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.stage-operations{display:flex;align-items:center;gap:16px;white-space:nowrap}.stage-operations>span{display:inline-flex}
/* 组件 DOM 和状态类由运行时生成;按 class token 匹配保持原选择器的含义和优先级,避免 IDE 静态模板匹配误报。 */
:deep([class~="el-select"]){width:100%}</style>

View File

@ -0,0 +1,28 @@
import type { Stage, StageNodeType } from '../../types'
/** 画布素材和创建表单共用分类;业务执行仍统一使用 WORK/GROUP。 */
export const STAGE_NODE_TYPES = [
{ value: 'GROUP', label: '阶段组', symbol: '组', description: '容纳子阶段和内部执行连线' },
{ value: 'REQUIREMENT', label: '需求', symbol: '需', description: '梳理目标、需求和验收范围' },
{ value: 'PROPOSAL', label: '方案', symbol: '案', description: '制定和评审实施方案' },
{ value: 'PURCHASE', label: '采购', symbol: '采', description: '安排物料或服务采购' },
{ value: 'DESIGN', label: '设计', symbol: '设', description: '开展结构、产品或技术设计' },
{ value: 'MACHINING', label: '加工', symbol: '加', description: '安排加工制作工作' },
{ value: 'ASSEMBLY', label: '组装', symbol: '装', description: '完成部件和系统装配' },
{ value: 'DEBUGGING', label: '调试', symbol: '调', description: '开展设备或系统调试' },
{ value: 'DEVELOPMENT', label: '研发', symbol: '研', description: '实施研发与功能开发' },
{ value: 'TESTING', label: '测试', symbol: '测', description: '执行测试和验证工作' },
] as const satisfies readonly { value: StageNodeType; label: string; symbol: string; description: string }[]
export const WORK_STAGE_NODE_TYPES = STAGE_NODE_TYPES.filter(type => type.value !== 'GROUP')
/** 从受控列表识别拖放载荷,拒绝来自其他页面或外部文本的未知节点类型。 */
export function isPaletteNodeType(value: string): value is Exclude<StageNodeType, 'STAGE'> {
return STAGE_NODE_TYPES.some(type => type.value === value)
}
/** 旧阶段依据结构展示分类;类型不从可编辑名称推断,改名不会改变节点身份。 */
export function stageNodeTypeLabel(stage: Pick<Stage, 'nodeType' | 'stageKind'>): string {
const value = stage.nodeType || (stage.stageKind === 'GROUP' ? 'GROUP' : 'STAGE')
return STAGE_NODE_TYPES.find(type => type.value === value)?.label || '普通阶段'
}

View File

@ -25,8 +25,12 @@ export interface StageSummary {
export type StageExecutionStatus = 'NOT_STARTED' | 'IN_PROGRESS' | 'COMPLETED' | 'LEGACY_PASSED'
/** 节点分类创建后固定;STAGE 只用于兼容历史普通阶段。 */
export type StageNodeType = 'GROUP' | 'REQUIREMENT' | 'PROPOSAL' | 'PURCHASE' | 'DESIGN' | 'MACHINING' | 'ASSEMBLY' | 'DEBUGGING' | 'DEVELOPMENT' | 'TESTING' | 'STAGE'
export interface Stage extends StageSummary, Omit<StageSchedule, 'plannedStartAt' | 'plannedEndAt'> {
stageKind?: 'WORK' | 'GROUP'
nodeType?: StageNodeType
parentStageId?: number | null
stagePath?: string
childStageCount?: number
@ -59,6 +63,7 @@ export interface Stage extends StageSummary, Omit<StageSchedule, 'plannedStartAt
}
export interface StageInput {
nodeType?: StageNodeType
stageKind?: 'WORK' | 'GROUP'
parentStageId?: number | null
plannedStartAt?: string | null

View File

@ -2,10 +2,12 @@
<section class="flow-view">
<div class="flow-toolbar">
<div class="flow-tools"><el-button size="small" @click="autoLayout" :disabled="busy">自动布局</el-button><el-button size="small" @click="fitAll">适应画布</el-button></div>
<div class="flow-tools"><button v-if="canManage" class="stage-palette" draggable="true" title="拖到画布后命名阶段" @dragstart="dragPalette">+ 阶段 · 拖入画布</button><span class="flow-help">点击阶段查看当前及历史工作项;画布位置只保存在当前浏览器</span><el-button v-if="canManage" size="small" @click="stageOpen = true">管理阶段</el-button></div>
<div class="flow-tools"><span class="flow-help">点击阶段查看当前及历史工作项;画布位置只保存在当前浏览器</span><el-button v-if="canManage" size="small" @click="stageOpen = true">管理阶段</el-button></div>
</div>
<el-alert v-if="failure" type="error" :title="failure" :closable="false" class="flow-failure" />
<div ref="canvas" class="flow-canvas" :class="{ inactive: !active }" @dragover.prevent @drop.prevent="dropStage">
<div class="flow-editor" :class="{ inactive: !active }">
<FlowNodePalette :enabled="canManage && !busy && !stageNameOpen" />
<div ref="canvas" class="flow-canvas" @dragover.prevent @drop.prevent="dropStage">
<!-- 保持阶段组、子阶段和连线的固定层级;选中时自动提升父组会使其背景遮住内部连线。 -->
<VueFlow v-if="active" :id="flowId" v-model:nodes="nodes" :edges="edges" :connection-line-type="ConnectionLineType.Bezier" :delete-key-code="null" :min-zoom="0.1" :max-zoom="4" :nodes-connectable="canManage && !busy" :edges-updatable="false" :nodes-draggable="!busy" :elevate-nodes-on-select="false" @connect="connectStages" @edge-click="edgeClicked" @node-click="selectNode" @node-drag-start="dragging = true" @node-drag="nodeDragged" @node-drag-stop="dragStopped" @move-end="viewportMoved" @nodes-initialized="restoreViewport">
<Background :gap="22" :size="1" pattern-color="var(--el-border-color)" />
@ -15,10 +17,11 @@
<template #node-stage="{ data }"><FlowStageNode :data="data" @view="openDrawer($event, 'current')" @create="createInStage" @rework="openRework" @history="openDrawer($event, 'history')" /></template>
<template #node-group="{ data }"><FlowStageNode :data="data" @view="openDrawer($event, 'current')" @create-child="createChildStage" @toggle="toggleGroup" @rework="openRework" @history="openDrawer($event, 'history')" /></template>
</VueFlow>
<div v-if="!view.unassigned?.counts?.total && !view.stages.length" class="canvas-empty">{{ canManage ? '从上方拖入阶段节点,然后连接执行顺序。' : '暂无阶段和工作项。' }}</div>
<div v-if="!view.unassigned?.counts?.total && !view.stages.length" class="canvas-empty">{{ canManage ? '从左侧拖入节点,然后连接阶段执行顺序。' : '暂无阶段和工作项。' }}</div>
<div class="canvas-legend"><span class="legend-line"></span>未执行 <span class="legend-line green"></span>已完成 <span class="legend-line legacy"></span>历史沿用 <span class="legend-line rework" :style="{ borderColor: FLOW_REWORK_COLOR }"></span>回退记录 · 多条入边须全部满足</div>
</div>
<StageCreateDialog :visible="stageNameOpen" :project-id="projectId" :iteration-id="iterationId" :parent="createParent" :members="members" @close="stageNameOpen = false" @created="stageCreated" />
</div>
<StageCreateDialog :visible="stageNameOpen" :project-id="projectId" :iteration-id="iterationId" :parent="createParent" :node-type="createNodeType" :members="members" @close="stageNameOpen = false" @created="stageCreated" />
<StageManager :visible="stageOpen" :project-id="projectId" :iteration-id="iterationId" :stages="view.stages" :members="members" :view="view" @close="stageOpen = false" @changed="emit('changed')" />
<StageReworkDialog :visible="reworkSourceId !== null" :source-id="reworkSourceId" :project-id="projectId" :iteration-id="iterationId" :view="view" @close="reworkSourceId = null" @changed="emit('changed')" />
<StageWorkItemsDrawer :stage-id="drawerStageId" :initial-tab="drawerTab" :project-id="projectId" :iteration-id="iterationId" :view="view" :members="members" :can-create="canCreate" :can-manage="canManage" @changed="emit('changed')" @close="drawerStageId = null" @open="openItem" @create="createFromDrawer" @navigate="drawerStageId = $event" @create-child="createChildFromDrawer" />
@ -40,11 +43,14 @@ import { api, errorText } from '../../api'
import { buildFlowGraph, absoluteRectangle, resizeStageGroup, updateReworkRoutes } from './utils/graph'
import { readFlowPreferences, writeFlowPreferences } from './utils/preferences'
import { stageAppearance } from './utils/stageAppearance'
import { stageGroupAt } from './utils/stageDrop'
import { isPaletteNodeType } from '../../shared/constants/stageNodeTypes'
import type { FlowNodeData, FlowEdgeData } from './utils/graph'
import type { FlowView, Member, Point } from '../../types'
import type { FlowView, Member, Point, StageNodeType } from '../../types'
import StageManager from '../../features/stages/components/StageManager.vue'
import StageCreateDialog from '../../features/stages/components/StageCreateDialog.vue'
import FlowStageNode from './components/FlowStageNode.vue'
import FlowNodePalette from './components/FlowNodePalette.vue'
import FlowReworkEdge from './components/FlowReworkEdge.vue'
import { FLOW_REWORK_COLOR } from './constants/theme'
import StageReworkDialog from '../../features/stages/components/StageReworkDialog.vue'
@ -59,6 +65,7 @@ const nodes = ref<Node<FlowNodeData>[]>([]), edges = ref<Edge<FlowEdgeData>[]>([
const busy = ref(false), dragging = ref(false), failure = ref(''), stageOpen = ref(false), stageNameOpen = ref(false), pendingStagePoint = ref<Point | null>(null)
const draftViewport = ref<(Point & { zoom: number }) | null>(null)
const createParentId = ref<number | null>(null), collapsedStages = ref<number[]>([])
const createNodeType = ref<StageNodeType | undefined>(undefined)
const createParent = computed(() => props.view.stages.find(stage => stage.id === createParentId.value) || null)
const reworkSourceId = ref<number | null>(null), drawerStageId = ref<number | null>(null), drawerTab = ref<'current' | 'history'>('current')
// 展示坐标与视口只存在当前浏览器;抽屉工作项始终取父页面更新后的服务端快照。
@ -150,22 +157,29 @@ function createInStage(stageId: number) { if (!props.canCreate || stageId !== 0
function openRework(stageId: number) { if (props.canManage && props.view.stages.some(stage => stage.id === stageId && stage.canRework)) reworkSourceId.value = stageId }
/** 小地图复用当前版本的状态色,便于缩小时定位回退待重做阶段;主题切换由 CSS 变量即时响应。 */
function minimapColor(node: GraphNode<FlowNodeData>) { return stageAppearance(node.data?.stage).accent }
/** 阶段素材只发出拖放标记,普通阶段点击不会误创建新阶段。 */
function dragPalette(event: DragEvent) { if (!props.canManage || !event.dataTransfer) return; event.dataTransfer.setData('application/x-pm-stage', 'new-stage'); event.dataTransfer.effectAllowed = 'copy' }
/** 拖入阶段组内部时预选父级;外层落点创建根阶段,最终归属始终由后端校验。 */
/**
* 将素材分类和画布落点转为创建草稿,命中子节点或组背景均自动归入同一组。
* @param event 浏览器拖放事件,坐标须按当前缩放和平移转换,不能用 DOM 层级推测归属
* @remarks 已执行组不允许新增;阶段组不能嵌套,失败时不打开表单也不保存数据。
*/
function dropStage(event: DragEvent) {
if (!props.canManage || busy.value || event.dataTransfer?.getData('application/x-pm-stage') !== 'new-stage') return
const target = (event.target as Element).closest('[data-stage]'), id = Number(target?.getAttribute('data-stage'))
const parent = props.view.stages.find(stage => stage.id === id && stage.stageKind === 'GROUP' && stage.canCreateChildStage)
const type = event.dataTransfer?.getData('application/x-pm-stage') || ''
if (!props.active || !props.canManage || busy.value || stageNameOpen.value || !isPaletteNodeType(type)) return
const point = screenToFlowCoordinate({ x: event.clientX, y: event.clientY })
const parent = stageGroupAt(point, getNodes.value, props.view.stages)
if (parent && type === 'GROUP') { failure.value = '阶段组只能创建在根画布,请拖到阶段组外。'; return }
if (parent && !parent.canCreateChildStage) { failure.value = '该阶段组已有执行记录,不能添加子阶段。'; return }
createNodeType.value = type
createParentId.value = parent?.id ?? null
const point = screenToFlowCoordinate({ x: event.clientX, y: event.clientY }), parentNode = nodes.value.find(node => node.id === 's:' + parent?.id)
const parentNode = getNodes.value.find(node => node.id === 's:' + parent?.id)
const origin = parentNode ? absoluteRectangle(parentNode, nodes.value) : { x: 0, y: 0 }
pendingStagePoint.value = { x: point.x - origin.x, y: point.y - origin.y }; failure.value = ''; stageNameOpen.value = true
// 组标题也接受拖放,最终局部坐标必须落在标题下方,避免新节点遮住组操作入口。
pendingStagePoint.value = { x: Math.max(parent ? 24 : -Infinity, point.x - origin.x), y: Math.max(parent ? 194 : -Infinity, point.y - origin.y) }; failure.value = ''; stageNameOpen.value = true
}
/** 阶段组上的入口与拖入子画布共用日期表单,不创建第三层阶段组。 */
function createChildStage(id: number) { if (!props.view.stages.some(stage => stage.id === id && stage.canCreateChildStage)) return; createParentId.value = id; pendingStagePoint.value = null; stageNameOpen.value = true }
/** 创建后只保存本地位置,跨用户共享的阶段内容来自后端下一次同步。 */
function stageCreated(id: number) { if (pendingStagePoint.value) positions.value = { ...positions.value, ['s:' + id]: pendingStagePoint.value }; stageNameOpen.value = false; pendingStagePoint.value = null; if (createParentId.value) collapsedStages.value = collapsedStages.value.filter(value => value !== createParentId.value); savePreference(); emit('changed') }
/** 组内快捷创建允许先选择工作节点分类;只在创建前选择,不提供阶段组或后续改类型入口。 */
function createChildStage(id: number) { if (!props.view.stages.some(stage => stage.id === id && stage.canCreateChildStage)) return; createParentId.value = id; createNodeType.value = undefined; pendingStagePoint.value = null; stageNameOpen.value = true }
/** 创建后把本地坐标与父级一起记录;新子节点的偏好不能因尚未刷新父级索引而丢失。 */
function stageCreated(id: number) { if (pendingStagePoint.value) positions.value = { ...positions.value, ['s:' + id]: pendingStagePoint.value }; previousParents['s:' + id] = createParentId.value; stageNameOpen.value = false; pendingStagePoint.value = null; if (createParentId.value) collapsedStages.value = collapsedStages.value.filter(value => value !== createParentId.value); savePreference(); emit('changed') }
/** 折叠状态按用户、项目、迭代保存在当前浏览器,展开后恢复子节点相对位置。 */
function toggleGroup(id: number) { collapsedStages.value = collapsedStages.value.includes(id) ? collapsedStages.value.filter(value => value !== id) : [...collapsedStages.value, id]; savePreference(); rebuild() }
/** 仅连接当前项目的两个真实阶段;后端在项目锁内复验权限、环和已执行门禁。 */
@ -189,10 +203,11 @@ async function edgeClicked(event: { edge: Edge<FlowEdgeData> }) {
}
</script>
<style scoped>
.flow-toolbar,.flow-tools{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.flow-toolbar{justify-content:space-between;margin-bottom:10px}.flow-tools :deep(.el-button+.el-button){margin-left:0}.flow-help{font-size:11px;color:var(--el-text-color-secondary)}.flow-canvas{--vf-connection-path:var(--el-color-primary);height:max(470px,calc(100vh - 315px));position:relative;overflow:hidden;border:1px solid var(--el-border-color-light);border-radius:10px;background:var(--el-fill-color-extra-light)}.flow-canvas.inactive{height:0}
.flow-toolbar,.flow-tools{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.flow-toolbar{justify-content:space-between;margin-bottom:10px}.flow-tools :deep(.el-button+.el-button){margin-left:0}.flow-help{font-size:11px;color:var(--el-text-color-secondary)}.flow-editor{display:flex;gap:10px;height:max(470px,calc(100vh - 315px));min-width:0}.flow-editor.inactive{display:none}.flow-canvas{--vf-connection-path:var(--el-color-primary);flex:1;min-width:0;height:100%;position:relative;overflow:hidden;border:1px solid var(--el-border-color-light);border-radius:10px;background:var(--el-fill-color-extra-light);box-sizing:border-box}
/* 组件 DOM 和状态类由运行时生成;按 class token 匹配保持原选择器的含义和优先级,避免 IDE 静态模板匹配误报。 */
.flow-canvas :deep([class~="vue-flow"]){height:100%}
.flow-canvas :deep([class~="vue-flow__node-stage"]),.flow-canvas :deep([class~="vue-flow__node-group"]){padding:0;border:0;background:transparent}.canvas-legend{position:absolute;left:16px;bottom:12px;display:flex;align-items:center;gap:8px;font-size:11px;color:var(--el-text-color-secondary);pointer-events:none}.legend-line{width:24px;border-top:2px solid var(--el-text-color-placeholder)}.legend-line.green{border-color:var(--el-color-success)}.legend-line.rework{border-top-style:dashed}.legend-line.legacy{border-color:var(--el-color-warning);border-top-style:dashed}.canvas-empty{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);color:var(--el-text-color-secondary);pointer-events:none}.flow-failure{margin-bottom:10px;white-space:pre-line}.stage-palette{border:1px dashed var(--el-color-primary-light-3);border-radius:6px;background:var(--el-color-primary-light-9);color:var(--el-color-primary);padding:6px 11px;font-size:12px;cursor:grab}.stage-palette:active{cursor:grabbing}@media(max-width:900px){.flow-canvas{height:560px}}
/* 图例上移并避开左下缩放控件,给画布底部保留间距,防止文字被底边遮挡。 */
.flow-canvas :deep([class~="vue-flow__node-stage"]),.flow-canvas :deep([class~="vue-flow__node-group"]){padding:0;border:0;background:transparent}.canvas-legend{position:absolute;left:60px;right:16px;bottom:32px;display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:11px;color:var(--el-text-color-secondary);pointer-events:none}.legend-line{width:24px;border-top:2px solid var(--el-text-color-placeholder)}.legend-line.green{border-color:var(--el-color-success)}.legend-line.rework{border-top-style:dashed}.legend-line.legacy{border-color:var(--el-color-warning);border-top-style:dashed}.canvas-empty{position:absolute;left:50%;top:50%;width:min(310px,80%);text-align:center;transform:translate(-50%,-50%);color:var(--el-text-color-secondary);pointer-events:none}.flow-failure{margin-bottom:10px;white-space:pre-line}@media(max-width:900px){.flow-editor{height:560px}}
/* Vue Flow 自带控件和小地图有独立浅色默认值,限定在协作画布内覆盖,避免影响系统其他页面。 */
.flow-canvas :deep([class~="vue-flow__controls"]){box-shadow:var(--el-box-shadow-lighter)}
.flow-canvas :deep([class~="vue-flow__controls-button"]){background:var(--el-bg-color-overlay);color:var(--el-text-color-primary);fill:currentColor;border-bottom-color:var(--el-border-color-light)}

View File

@ -0,0 +1,35 @@
<template>
<aside class="node-palette" aria-label="流程节点库">
<div class="palette-heading"><strong>节点库</strong><span>{{ STAGE_NODE_TYPES.length }} 种类型</span></div>
<el-input v-model="search" size="small" clearable placeholder="搜索节点类型" aria-label="搜索节点类型" />
<p class="palette-hint">{{ enabled ? '拖入画布创建;拖入阶段组自动归属' : '节点类型创建后固定;当前不可新增节点' }}</p>
<div class="palette-list">
<button v-for="type in filteredTypes" :key="type.value" type="button" class="palette-node" :class="{ 'is-group': type.value === 'GROUP' }" :draggable="enabled" :disabled="!enabled" :data-node-type="type.value" @dragstart="startDrag($event, type.value)">
<span class="node-symbol">{{ type.symbol }}</span><span class="node-info"><strong>{{ type.label }}</strong><span>{{ type.description }}</span></span><span class="node-grip" aria-hidden="true">⠿</span>
</button>
<el-empty v-if="!filteredTypes.length" description="没有匹配的节点类型" :image-size="45" />
</div>
</aside>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import { STAGE_NODE_TYPES } from '../../../shared/constants/stageNodeTypes'
import type { StageNodeType } from '../../../types'
const props = defineProps<{ enabled: boolean }>()
const search = ref('')
const filteredTypes = computed(() => STAGE_NODE_TYPES.filter(type => (type.label + type.description).includes(search.value.trim())))
/** 拖放只传递固定分类;归属和落点由画布计算,实际创建仍需后台权限与阶段规则校验。 */
function startDrag(event: DragEvent, type: StageNodeType) {
if (!props.enabled || !event.dataTransfer) { event.preventDefault(); return }
event.dataTransfer.setData('application/x-pm-stage', type)
event.dataTransfer.effectAllowed = 'copy'
}
</script>
<style scoped>
.node-palette{width:214px;flex:none;min-height:0;display:flex;flex-direction:column;padding:14px 10px 0;box-sizing:border-box;background:var(--el-bg-color);border:1px solid var(--el-border-color-light);border-radius:10px;color:var(--el-text-color-primary)}
.palette-heading{display:flex;align-items:center;justify-content:space-between;gap:6px;margin-bottom:12px}.palette-heading strong{font-size:14px}.palette-heading>span,.palette-hint{color:var(--el-text-color-secondary);font-size:11px}.palette-hint{line-height:1.6;margin:8px 0 10px}.palette-list{overflow-y:auto;min-height:0;padding-bottom:10px;scrollbar-width:thin}
.palette-node{display:flex;align-items:center;gap:9px;width:100%;padding:11px 9px;margin-bottom:7px;text-align:left;border:1px solid var(--el-border-color-light);border-radius:7px;background:var(--el-bg-color-overlay);color:inherit;cursor:grab}.palette-node:hover:not(:disabled){border-color:var(--el-color-primary-light-3);background:var(--el-color-primary-light-9)}.palette-node:active:not(:disabled){cursor:grabbing}.palette-node:disabled{cursor:default;opacity:.65}.node-symbol{display:flex;align-items:center;justify-content:center;width:30px;height:32px;flex:none;border-radius:7px;color:var(--el-color-primary);background:var(--el-color-primary-light-9);font-size:14px;font-weight:600}.is-group .node-symbol{color:var(--el-color-warning);background:var(--el-color-warning-light-9)}.node-info{display:flex;flex-direction:column;gap:4px;min-width:0;flex:1}.node-info strong{font-size:12px}.node-info>span{font-size:10px;line-height:1.5;color:var(--el-text-color-secondary)}.node-grip{color:var(--el-text-color-placeholder);font-size:18px}
@media(max-width:900px){.node-palette{width:166px}.palette-node{padding:9px 7px;gap:6px}.node-symbol{width:25px}.node-info>span{display:none}}
</style>

View File

@ -23,7 +23,7 @@ const labelX = computed(() => (props.sourceX + props.targetX) / 2)
const path = computed(() => {
if (props.source === props.target) return `M ${props.sourceX} ${props.sourceY} C ${props.sourceX} ${laneY.value} ${props.sourceX} ${laneY.value} ${labelX.value} ${laneY.value} C ${props.targetX} ${laneY.value} ${props.targetX} ${laneY.value} ${props.targetX} ${props.targetY}`
const fromX = props.data?.sourceEscapeX ?? props.sourceX + 40, toX = props.data?.targetEscapeX ?? props.targetX - 40
// 保留节点外侧的竖向通道,进入底部32px区域后再转弯,避免曲线切过同列其他阶段。
// 只沿两端节点外侧绕到底部固定间距,其他阶段不参与避让,避免拖动无关节点导致路径跳动。
const sourceTurnY = Math.max(props.sourceY + 14, laneY.value - 32), targetTurnY = Math.max(props.targetY + 14, laneY.value - 32)
return [
`M ${props.sourceX} ${props.sourceY}`,

View File

@ -1,7 +1,7 @@
<template>
<div class="phase-group" :class="{ 'is-current': data.stage?.isCurrent, 'is-container': data.stage?.stageKind === 'GROUP' && !data.collapsed }" :data-stage="data.stageId" :data-state="appearance.tone" :style="{ '--phase-background': appearance.background, '--phase-border': appearance.border, '--phase-accent': appearance.accent }">
<Handle v-if="data.stage" id="in" type="target" :position="Position.Left" :connectable="!!data.canManage" :style="{ top: '42px' }" />
<header class="stage-drag"><span class="phase-dot"></span><strong :title="data.title">{{ data.title }}</strong><span v-if="data.stage?.isCurrent" class="stage-current">当前</span><button v-if="data.stage?.stageKind === 'GROUP'" class="nodrag stage-toggle" @click.stop="emit('toggle', data.stageId!)">{{ data.collapsed ? '展开' : '折叠' }}</button><span v-if="data.stage" class="stage-version">v{{ data.stage.revisionNo || 1 }}</span></header>
<header class="stage-drag"><span class="phase-dot"></span><span v-if="data.stage" class="stage-type">{{ stageNodeTypeLabel(data.stage) }}</span><strong :title="data.title">{{ data.title }}</strong><span v-if="data.stage?.isCurrent" class="stage-current">当前</span><button v-if="data.stage?.stageKind === 'GROUP'" class="nodrag stage-toggle" @click.stop="emit('toggle', data.stageId!)">{{ data.collapsed ? '展开' : '折叠' }}</button><span v-if="data.stage" class="stage-version">v{{ data.stage.revisionNo || 1 }}</span></header>
<p v-if="data.stage" class="phase-description" :class="{ empty: !data.stage.description?.trim() }" :title="data.stage.description || '未填写阶段描述'">{{ data.stage.description || '未填写阶段描述' }}</p>
<div class="phase-body"><button class="nodrag stage-items" title="查看当前版本工作项" @click.stop="emit('view', data.stageId!)">{{ data.itemCount || 0 }} 个工作项</button><span v-if="data.stage" class="stage-status" :title="appearance.description">{{ appearance.label }}</span></div>
<div v-if="data.stage" class="phase-plan" :class="{ warning: data.stage.scheduleReviewRequired || data.stage.overdue }" :title="planLabel(data.stage)">{{ planLabel(data.stage) }}</div>
@ -17,6 +17,7 @@ import { computed } from 'vue'
import { Handle, Position } from '@vue-flow/core'
import type { FlowNodeData } from '../utils/graph'
import { stageAppearance } from '../utils/stageAppearance'
import { stageNodeTypeLabel } from '../../../shared/constants/stageNodeTypes'
import type { Stage } from '../../../types'
import { plannedDate } from '../../../shared/utils/time'
const props = defineProps<{ data: FlowNodeData }>()
@ -31,6 +32,7 @@ function planLabel(stage: Stage): string {
}
</script>
<style scoped>
.stage-type{flex:none;white-space:nowrap;font-size:10px;line-height:16px;padding:0 4px;border-radius:3px;color:var(--phase-accent);background:color-mix(in srgb,var(--phase-accent) 12%,var(--el-bg-color-overlay))}
.phase-group[class~="is-current"]{border-color:var(--el-color-primary)}.stage-current{font-size:10px;color:var(--el-color-primary);background:var(--el-color-primary-light-9);border-radius:3px;padding:1px 4px;white-space:nowrap;flex:none}
.phase-group{width:100%;height:100%;background:var(--phase-background);border:1px solid var(--phase-border);border-radius:11px;color:var(--el-text-color-primary);cursor:pointer;box-sizing:border-box}.stage-drag{display:flex;align-items:center;gap:8px;padding:13px 14px 4px;cursor:grab}.stage-drag strong{font-size:13px;flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.stage-version{font-size:11px;color:var(--el-text-color-secondary)}.phase-dot{width:8px;height:8px;border-radius:50%;background:var(--phase-accent);flex:none}
.phase-body{display:flex;align-items:center;justify-content:space-between;gap:6px;padding:1px 14px 0}.stage-items{font-size:12px;font-weight:600;color:var(--el-color-primary)}.stage-status{font-size:11px;color:var(--el-text-color-regular);white-space:nowrap}.phase-actions{display:flex;align-items:center;gap:11px;padding:5px 14px}.stage-items,.phase-actions button{border:0;background:transparent;padding:0;cursor:pointer}.phase-actions button{color:var(--el-color-primary);font-size:11px;white-space:nowrap}

View File

@ -135,21 +135,18 @@ export function resizeStageGroup(nodes: Node<FlowNodeData>[], groupId: string, e
}
/**
* 按当前节点的绝对边界更新回退通道,保持拖动和组尺寸变化时连线及次数标签位于节点下方。
* @param nodes 当前节点及父子坐标
* 仅按回退两端的绝对边界计算固定间距通道,避免无关节点或其他回退线拉长、移动当前路径。
* @param nodes 当前节点及父子坐标;父级仅用于换算端点绝对位置
* @param edges 原地更新的可见连线;执行边的几何位置继续由 Vue Flow 维护
* @remarks 不以整张画布边界或连线顺序避让;两端几何位置不变时,路径和标签位置保持不变。
*/
export function updateReworkRoutes(nodes: Node<FlowNodeData>[], edges: Edge<FlowEdgeData>[]): void {
const laneCounts = new Map<string | null, number>()
for (const edge of edges) {
if (edge.data?.kind !== 'rework') continue
const source = nodes.find(node => node.id === edge.source), target = nodes.find(node => node.id === edge.target)
if (!source || !target) continue
const scope = source.parentNode || null, index = laneCounts.get(scope) || 0
laneCounts.set(scope, index + 1)
const siblings = nodes.filter(node => (node.parentNode || null) === scope).map(node => absoluteRectangle(node, nodes))
const from = absoluteRectangle(source, nodes), to = absoluteRectangle(target, nodes)
edge.data = { ...edge.data, laneY: Math.max(...siblings.map(rect => rect.y + rect.height)) + 32 + index * 52, sourceEscapeX: from.x + from.width + 12, targetEscapeX: to.x - 12 }
edge.data = { ...edge.data, laneY: Math.max(from.y + from.height, to.y + to.height) + 32, sourceEscapeX: from.x + from.width + 12, targetEscapeX: to.x - 12 }
}
}

View File

@ -0,0 +1,18 @@
import type { Node } from '@vue-flow/core'
import type { Point, Stage } from '../../../types'
import { absoluteRectangle } from './graph'
import type { FlowNodeData } from './graph'
/**
* 用画布坐标命中组外框,子节点及组内连线也视为该组的接收区域。
* @param point 经过当前平移和缩放换算后的画布落点
* @param nodes 当前显示节点,折叠后的组也可作为接收区域
* @param stages 最新后台阶段摘要;是否可新增由调用方与后台再次判断
* @returns 落点所在的最小阶段组;不在组内时返回空,不自动改变已有阶段归属
*/
export function stageGroupAt(point: Point, nodes: Node<FlowNodeData>[], stages: Stage[]): Stage | undefined {
return nodes.filter(node => node.type === 'group').map(node => ({ node, bounds: absoluteRectangle(node, nodes) }))
.filter(({ bounds }) => point.x >= bounds.x && point.x <= bounds.x + bounds.width && point.y >= bounds.y && point.y <= bounds.y + bounds.height)
.sort((a, b) => a.bounds.width * a.bounds.height - b.bounds.width * b.bounds.height)
.map(({ node }) => stages.find(stage => stage.id === node.data?.stageId && stage.stageKind === 'GROUP')).find(stage => !!stage)
}