# 交互时序图

> DDS-Section: Frontend DDS - 9. 交互时序图
> DDS-Lines: L787-L878

## 管理员编辑保存流程

```mermaid
sequenceDiagram
    participant Admin as 超级管理员
    participant Page as ProjectDetail.vue
    participant Dialog as SaveConfirmDialog
    participant API as 后端API

    Admin->>Page: 点击[编辑]按钮
    Page->>Page: isEditMode = true
    Page->>Page: editForm = deepClone(masterData)

    Admin->>Page: 修改字段
    Page->>Page: hasChanges = true

    Admin->>Page: 点击[保存修改]
    Page->>Page: 计算 diffItems
    Page->>Dialog: 显示确认对话框

    Admin->>Dialog: 确认保存
    Dialog->>API: updateProject()
    API-->>Dialog: 成功
    Dialog->>Page: emit('confirm')
    Page->>API: loadProject()
    Page->>Page: isEditMode = false
    Page-->>Admin: Snackbar: 保存成功
```

## 用户草稿提交流程

```mermaid
sequenceDiagram
    participant User as 普通用户
    participant Page as UserProjectDetail.vue
    participant Dialog as SubmitDialog
    participant API as 后端API
    participant WF as 工单模块

    User->>Page: 填写表单
    User->>Page: 点击[保存草稿]
    Page->>API: saveDraft()
    API-->>Page: 草稿保存成功

    User->>Page: 点击[提交审核]
    Page->>Dialog: 显示确认对话框
    User->>Dialog: 填写备注并确认
    Dialog->>API: saveDraft() (最终版本)
    Dialog->>API: submitProjectDetail()
    API->>WF: 触发工单状态转换
    WF-->>API: 成功
    API-->>Dialog: 提交成功
    Page-->>User: 跳转至工单详情页
```

## 管理员审批流程

```mermaid
sequenceDiagram
    participant Admin as 超级管理员
    participant Page as ProjectDetail.vue
    participant Dialog as ApproveDialog/RejectDialog
    participant API as 后端API
    participant WF as 工单模块

    Note over Page: lifecycle_status = reviewing

    Admin->>Page: 查看待审核内容
    
    alt 通过审批
        Admin->>Page: 点击[通过]
        Page->>Dialog: 显示审批对话框
        Admin->>Dialog: 填写备注并确认
        Dialog->>API: transitionWorkflow(approve)
        API->>WF: 工单状态 → approved
        WF-->>API: 回调更新项目状态
        API-->>Dialog: 成功
        Page->>API: updateProjectCertification('official')
        Page-->>Admin: Snackbar: 审批通过
    else 打回修改
        Admin->>Page: 点击[打回]
        Page->>Dialog: 显示打回对话框
        Admin->>Dialog: 填写打回原因并确认
        Dialog->>API: transitionWorkflow(return)
        API->>WF: 工单状态 → returned
        WF-->>API: 回调更新项目状态
        API-->>Dialog: 成功
        Page-->>Admin: Snackbar: 已打回
    end
```

## 版本冲突处理流程

```mermaid
sequenceDiagram
    participant User as 普通用户
    participant Page as UserProjectDetail.vue
    participant API as 后端API
    participant Admin as 超级管理员

    Note over User,API: 用户 A 基于 v3 版本创建草稿

    Admin->>API: 直接修改项目 (v3 → v4)
    
    User->>Page: 点击[提交审核]
    Page->>API: submitDraft() (base_version=v3)
    API->>API: 检查 base_version != current_version
    API-->>Page: 返回 409 Conflict

    Page-->>User: 显示冲突提示对话框

    alt 选择 Rebase
        User->>Page: 点击 [Rebase]
        Page->>API: getProject() (最新 v4 版本)
        Page->>Page: 自动合并草稿到 v4
        Page-->>User: 显示合并结果，可能需要手动解决冲突
    else 选择 Diff Check
        User->>Page: 点击 [查看差异]
        Page->>API: getDiff(v3, v4)
        Page-->>User: 显示 v3 与 v4 的差异
        User->>User: 决定是否覆盖或调整
    end
```
