跳到主要内容

工件管理文档

概述

本文档详细说明邮轮穿舱件管理系统中工件管理模块的功能实现,重点分析基于WorkpieceView和WorkpieceEdit组件的工件增删改查、状态跟踪等业务流程。

目录

  1. 系统架构概述
  2. 工件管理业务流程
  3. 组件详细分析
  4. 状态跟踪机制
  5. 数据流分析
  6. 依赖关系图
  7. 性能优化建议

系统架构概述

邮轮穿舱件管理系统前端采用Vue.js框架构建,使用Vuetify作为UI组件库。工件管理模块是系统的核心功能模块,负责管理所有穿舱件的生命周期。

技术栈

  • 前端框架: Vue.js 2.x
  • UI组件库: Vuetify
  • 路由管理: Vue Router
  • 状态管理: Vuex
  • HTTP客户端: Axios

路由配置

工件管理相关的路由配置如下:

{
path: "/workpiece",
name: "Workpiece",
component: () => import('@/views/workpiece/WorkpieceView.vue'),
},
{
path: "/workpiece/edit/:id",
name: "WorkpieceEdit",
component: () => import('@/views/workpiece/WorkpieceEdit.vue'),
props: true
}

工件管理业务流程

工件生命周期状态

stateDiagram-v2
[*] --> 未生效
未生效 --> 已生效: 实例化
已生效 --> 维护中: 状态变更
已生效 --> 已停用: 停用
维护中 --> 已生效: 修复完成
已停用 --> [*]: 删除
维护中 --> [*]: 删除
已生效 --> [*]: 删除

核心业务流程

1. 工件创建流程

sequenceDiagram
participant User
participant WorkpieceView
participant Backend
participant WorkpieceEdit

User->>WorkpieceView: 点击"新建工件"
WorkpieceView->>Backend: POST /workpiece
Backend-->>WorkpieceView: 返回基础工件信息
WorkpieceView->>WorkpieceEdit: 跳转到编辑页面
WorkpieceEdit->>User: 显示初始化表单
User->>WorkpieceEdit: 填写工件信息
WorkpieceEdit->>Backend: POST /workpiece-info/
Backend-->>WorkpieceEdit: 创建成功
WorkpieceEdit->>WorkpieceView: 返回列表页面

2. 工件查看流程

sequenceDiagram
participant User
participant WorkpieceView
participant Backend

User->>WorkpieceView: 点击"查看"按钮
WorkpieceView->>WorkpieceView: 打开详情弹窗
WorkpieceView->>Backend: GET /workpiece-info/{id}
Backend-->>WorkpieceView: 返回工件详细信息
WorkpieceView->>User: 显示工件详情

3. 工件编辑流程

sequenceDiagram
participant User
participant WorkpieceView
participant WorkpieceEdit
participant Backend

User->>WorkpieceView: 点击"修改"按钮
WorkpieceView->>WorkpieceEdit: 跳转到编辑页面
WorkpieceEdit->>Backend: GET /workpiece-info/{id}
Backend-->>WorkpieceEdit: 返回现有数据
WorkpieceEdit->>User: 显示编辑表单
User->>WorkpieceEdit: 修改信息并保存
WorkpieceEdit->>Backend: PUT /workpiece-info/{id}
Backend-->>WorkpieceEdit: 更新成功
WorkpieceEdit->>WorkpieceView: 返回列表页面

4. 工件删除流程

sequenceDiagram
participant User
participant WorkpieceView
participant Backend

User->>WorkpieceView: 点击"删除"按钮
WorkpieceView->>WorkpieceView: 显示确认对话框
User->>WorkpieceView: 输入确认信息
WorkpieceView->>Backend: DELETE /workpiece-info/{id}
Backend-->>WorkpieceView: 删除成功
WorkpieceView->>WorkpieceView: 更新列表数据

组件详细分析

WorkpieceView组件分析

WorkpieceView是工件管理的主页面,负责显示工件列表和提供操作入口。

组件结构

classDiagram
class WorkpieceView {
+data()
+computed()
+mounted()
+methods()
-loadWorkpieces()
-createWorkpiece()
-editWorkpiece()
-viewWorkpiece()
-deleteWorkpiece()
}

class DataProperties {
+loading: boolean
+searchKeyword: string
+statusFilter: any
+inactiveWorkpieces: array
+activeWorkpieces: array
+headers: array
}

class ComputedProperties {
+filteredActiveWorkpieces()
+canDelete()
}

WorkpieceView --> DataProperties
WorkpieceView --> ComputedProperties

核心功能实现

数据加载逻辑

async loadWorkpieces() {
this.loading = true
try {
const allWorkpiecesResponse = await http.get('/workpiece/all')
const allWorkpieces = allWorkpiecesResponse.data || []

// 分别存储生效和未生效工件
this.inactiveWorkpieces = []
this.activeWorkpieces = []

// 遍历检查工件状态
for (const workpiece of allWorkpieces) {
try {
const infoResponse = await http.get(`/workpiece-info/${workpiece.workpiece_id}`)
this.activeWorkpieces.push({...workpiece, ...infoResponse.data})
} catch (error) {
if (error.response && error.response.status === 404) {
this.inactiveWorkpieces.push(workpiece)
}
}
}
} catch (error) {
console.error('加载工件数据失败:', error)
} finally {
this.loading = false
}
}

状态筛选逻辑

filteredActiveWorkpieces() {
let filtered = [...this.activeWorkpieces]

// 状态筛选
if (this.statusFilter !== null) {
filtered = filtered.filter(item => item.workpiece_status === this.statusFilter)
}

// 关键词搜索
if (this.searchKeyword) {
const keyword = this.searchKeyword.toLowerCase()
filtered = filtered.filter(item =>
(item.wp_firestop_code && item.wp_firestop_code.toLowerCase().includes(keyword)) ||
(item.wp_matrial && item.wp_matrial.toLowerCase().includes(keyword)) ||
(item.wp_installation_location && item.wp_installation_location.toLowerCase().includes(keyword))
)
}

return filtered
}

WorkpieceEdit组件分析

WorkpieceEdit组件负责工件的创建、编辑和删除操作。

组件结构

classDiagram
class WorkpieceEdit {
+data()
+computed()
+created()
+methods()
-initializeWorkpiece()
-saveWorkpiece()
-deleteWorkpiece()
}

class WorkpieceData {
+workpiece: object
+workpieceInfo: object
+valid: boolean
+loading: boolean
}

class ComputedProps {
+isInitializing()
+isEditing()
}

WorkpieceEdit --> WorkpieceData
WorkpieceEdit --> ComputedProps

核心功能实现

初始化逻辑

async initializeWorkpiece() {
const workpieceId = this.$route.params.id
if (workpieceId && workpieceId !== 'new') {
await this.loadWorkpieceData(workpieceId)
} else {
await this.createBaseWorkpiece()
}
}

保存逻辑

async saveWorkpiece() {
if (!this.$refs.form.validate()) return

this.loading = true
try {
this.workpieceInfo.wp_id = String(this.workpiece.workpiece_id)

if (this.isInitializing) {
await http.post('/workpiece-info/', this.workpieceInfo)
this.showMessage('工件信息创建成功!', 'success')
} else {
await http.put(`/workpiece-info/${this.workpiece.workpiece_id}`, this.workpieceInfo)
this.showMessage('工件信息更新成功!', 'success')
}

setTimeout(() => this.goBack(), 1500)
} catch (error) {
console.error('保存工件失败:', error)
} finally {
this.loading = false
}
}

状态跟踪机制

工件状态定义

系统定义了四种工件状态:

状态值状态名称描述
0未生效已创建基础工件但未填写详细信息
1已生效已完成实例化的正常工件
2维护中正在进行维护的工件
-1已停用已停用的工件

状态转换逻辑

flowchart TD
A[创建基础工件] --> B[状态: 未生效]
B --> C{是否实例化?}
C -->|是| D[状态: 已生效]
C -->|否| B
D --> E{状态变更?}
E -->|维护| F[状态: 维护中]
E -->|停用| G[状态: 已停用]
F --> D
G --> H[删除工件]

状态检测实现

// 通过检查workpiece-info是否存在来判断工件状态
for (const workpiece of allWorkpieces) {
try {
const infoResponse = await http.get(`/workpiece-info/${workpiece.workpiece_id}`)
// 能获取到详细信息 → 已生效工件
this.activeWorkpieces.push({...workpiece, ...infoResponse.data})
} catch (error) {
if (error.response && error.response.status === 404) {
// 获取不到详细信息 → 未生效工件
this.inactiveWorkpieces.push(workpiece)
}
}
}

数据流分析

组件间数据流

flowchart TD
A[WorkpieceView] -->|路由参数| B[WorkpieceEdit]
B -->|表单数据| C[后端API]
C -->|响应数据| B
B -->|导航返回| A
A -->|筛选条件| D[本地数据处理]
D -->|过滤结果| E[界面渲染]

数据模型结构

基础工件模型

workpiece: {
workpiece_id: null, // 工件ID
workpiece_status: 0, // 工件状态
created_at: null, // 创建时间
updated_at: null, // 更新时间
created_by: -1, // 创建者
updated_by: -1, // 更新者
maintainance_reference: 0, // 维护引用
inspect_reference: 0 // 检查引用
}

工件详细信息模型

workpieceInfo: {
wp_id: '', // 工件ID
wp_firestop_code: '', // 防火板代号
wp_matrial: '', // 材料
wp_size: '', // 规格
wp_fire_rating: '', // 防火等级
wp_watertightness: '', // 水密等级
wp_main_vertical_zone: '', // 主竖区
wp_installation_location: '', // 安装位置
wp_z_coordinate: '', // Z坐标
wp_frame_station: '', // 肋位
wp_longitudinal_stiffener: '', // 纵桁
wp_sap1: '', // SAP1
wp_sap2: '', // SAP2
wp_standard_drawing_catalogue: '', // 图册章节
wp_extra: '' // 额外信息
}

依赖关系图

组件依赖关系

flowchart TD
A[App.vue] --> B[WorkpieceView.vue]
A --> C[WorkpieceEdit.vue]
B --> D[Vuetify组件]
C --> D
B --> E[HTTP客户端]
C --> E
B --> F[Vue Router]
C --> F

模块导入关系

graph TD
A[WorkpieceView] --> B[@/http]
C[WorkpieceEdit] --> B
A --> D[Vue]
C --> D
A --> E[Vuetify]
C --> E

性能优化建议

1. 数据加载优化

  • 实现分页加载,避免一次性加载大量数据
  • 添加数据缓存机制,减少重复API调用
  • 使用防抖搜索,减少不必要的API请求

2. 组件性能优化

  • 对大型列表使用虚拟滚动
  • 优化计算属性的依赖关系
  • 使用异步组件加载

3. 用户体验优化

  • 添加加载状态指示器
  • 实现操作撤销功能
  • 添加批量操作支持

4. 错误处理优化

  • 完善网络错误处理
  • 添加重试机制
  • 提供友好的错误提示

索引

工件管理模块通过WorkpieceView和WorkpieceEdit两个核心组件,实现了完整的工件生命周期管理功能。系统采用清晰的状态跟踪机制,通过检查workpiece-info的存在性来判断工件状态,确保了数据的一致性和完整性。

模块设计合理,代码结构清晰,具有良好的可维护性和扩展性。通过进一步优化数据加载和用户体验,可以提升系统的整体性能。

参考文件: