Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x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6x 6x 6x 6x 6x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 19x 19x 19x 19x 19x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 19x 19x 19x 19x 19x 19x 4x 4x 4x 4x 19x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /**
* 数据查看与展示业务逻辑模块
* 提供检测任务数据的查询、筛选、展示及导出功能
*
* @fileOverview 数据查看模块,基于Vue 3 Composition API实现
* @author InspectionFlowSystem Team
* @version 1.0.0
* @since 2025-11-17
*/
import { ref, reactive } from 'vue';
import { ElMessage } from 'element-plus';
import { taskAPI, subitemAPI } from '../../api';
/**
* 任务状态映射表
* @constant {Record<number, string>}
* @description 定义任务状态码与状态名称的映射关系
* @since 1.0.0
*/
const STATUS_LABELS: Record<number, string> = {
1: '草稿',
2: '待接取',
3: '进行中',
4: '已完成',
5: '已评审',
6: '已授权',
7: '已中止',
8: '已归档'
};
/**
* 子任务状态映射表
* @constant {Record<number, string>}
* @description 定义子任务状态码与状态名称的映射关系
* @since 1.0.0
*/
const SUBTASK_STATUS_LABELS: Record<number, string> = {
1: '待处理',
2: '进行中',
3: '已完成',
4: '已中止'
};
/**
* 托盘状态映射表
* @constant {Record<string, string>}
* @description 定义托盘状态与状态名称的映射关系
* @since 1.0.0
*/
const TRAY_STATUS_LABELS: Record<string, string> = {
'空闲': '空闲',
'已分配': '已分配',
'检测中': '检测中',
'已完成': '已完成'
};
/**
* 检测任务数据接口
* @interface Task
* @description 定义检测任务的完整数据结构
* @since 1.0.0
*/
export interface Task {
/** 任务ID */
id: number;
/** 产品名称 */
product_name: string;
/** 试验性质 */
test_property: string;
/** 试验依据 */
test_basis: string;
/** 型号规格 */
model_spec: string;
/** 封装形式 */
package_form: string;
/** 生产批次 */
prod_batch: string;
/** 检测批次 */
detect_batch: string;
/** 产品数量 */
product_count: number;
/** 项目负责人ID */
manager_id: number;
/** 拟制人ID */
drafter_id: number;
/** 审核人ID */
reviewer_id: number;
/** 批准人ID */
approver_id: number;
/** 子项目信息列表 */
subitems: Subtask[];
/** 备注信息 */
remark: string;
/** 任务状态 */
status: number;
/** 创建时间 */
created_at?: string;
/** 更新时间 */
updated_at?: string;
}
/**
* 子检测项目数据接口
* @interface Subtask
* @description 定义子检测项目的完整数据结构
* @since 1.0.0
*/
export interface Subtask {
/** 子项目ID */
id: number;
/** 关联的检测流程ID */
flow_id: number;
/** 序号 */
serial: number;
/** 检测项目 */
item: string;
/** 试验条件 */
condition: string;
/** 接收数量 */
receive_count: number;
/** 接收人ID */
receiver_id: number;
/** 检测合格数 */
qualified_count: number;
/** 检测不合格数 */
unqualified_count: number;
/** 检查人ID列表 */
inspector_ids: string;
/** 优先级 */
priority: number;
/** 子项目状态 */
status: number;
/** 创建时间 */
created_at?: string;
/** 更新时间 */
updated_at?: string;
}
/**
* 托盘数据接口
* @interface Tray
* @description 定义托盘的完整数据结构
* @since 1.0.0
*/
export interface Tray {
/** 托盘ID */
id: number;
/** 托盘类型 */
tray_type: string;
/** 托盘编码 */
tray_code: string;
/** 满载数量 */
full_count: number;
/** 使用状态 */
status: string;
/** 备注 */
remark: string;
/** 创建时间 */
created_at?: string;
/** 更新时间 */
updated_at?: string;
/** 关联信息 */
association?: TrayAssociation;
}
/**
* 托盘关联信息接口
* @interface TrayAssociation
* @description 定义托盘与子任务的关联信息
* @since 1.0.0
*/
export interface TrayAssociation {
/** 关联ID */
id: number;
/** 子项目ID */
subitem_id: number;
/** 托盘ID */
tray_id: number;
/** 备注 */
remark: string;
/** 创建时间 */
created_at?: string;
/** 更新时间 */
updated_at?: string;
}
/**
* 托盘使用记录接口
* @interface TrayUsageRecord
* @description 定义托盘使用记录的完整数据结构(基于托盘和关联信息构建)
* @since 1.0.0
*/
export interface TrayUsageRecord {
/** 记录ID */
id: number;
/** 关联检测流程表ID */
flow_id: number;
/** 关联子检测项目ID */
subitem_id: number;
/** 托盘ID */
tray_id: number;
/** 实际检测数量 */
actual_count: number;
/** 检测状态 */
detect_status: string;
/** 检测开始时间 */
start_time?: string;
/** 检测开始用户ID */
start_user_id: number;
/** 检测结束时间 */
end_time?: string;
/** 检测结束用户ID */
end_user_id: number;
/** 备注 */
remark: string;
/** 创建时间 */
created_at?: string;
/** 更新时间 */
updated_at?: string;
}
/**
* 查询表单数据接口
* @interface QueryForm
* @description 定义查询表单的数据结构
* @since 1.0.0
*/
interface QueryForm {
/** 任务时间段开始 */
startTime: string;
/** 任务时间段结束 */
endTime: string;
/** 试验性质 */
testProperty: string;
}
/**
* 查询表单响应式引用
* @type {import('vue').Reactive<QueryForm>}
* @description 绑定到查询表单的数据对象
* @since 1.0.0
*/
export const queryForm = reactive<QueryForm>({
startTime: '',
endTime: '',
testProperty: ''
});
/**
* 任务列表响应式引用
* @type {import('vue').Ref<Task[]>}
* @description 存储所有检测任务的列表数据
* @since 1.0.0
*/
export const tasks = ref<Task[]>([]);
/**
* 选中任务响应式引用
* @type {import('vue').Ref<Task | null>}
* @description 存储当前选中的检测任务数据
* @since 1.0.0
*/
export const selectedTask = ref<Task | null>(null);
/**
* 子任务列表响应式引用
* @type {import('vue').Ref<Subtask[]>}
* @description 存储当前选中任务的子任务列表数据
* @since 1.0.0
*/
export const subtasks = ref<Subtask[]>([]);
/**
* 托盘使用记录列表响应式引用
* @type {import('vue').Ref<TrayUsageRecord[]>}
* @description 存储托盘使用记录的列表数据
* @since 1.0.0
*/
export const trayUsageRecords = ref<TrayUsageRecord[]>([]);
/**
* 查询任务列表
*
* @async
* @function searchTasks
* @returns {Promise<void>}
* @description 根据查询条件获取检测任务列表
*
* @example
* // 查询任务列表
* searchTasks();
*
* @throws {Error} 当API请求失败时会显示错误消息
* @since 1.0.0
*/
export async function searchTasks() {
try {
// 构建查询参数
const params: any = {};
// 添加时间段查询参数
if (queryForm.startTime) {
params.start_time = queryForm.startTime;
}
if (queryForm.endTime) {
params.end_time = queryForm.endTime;
}
// 添加试验性质查询参数
if (queryForm.testProperty) {
params.test_property = queryForm.testProperty;
}
// 发送请求
const response = await taskAPI.getTasks(params);
// 处理响应数据
if (Array.isArray(response.data)) {
tasks.value = response.data.map(task => ({
...task,
status_label: STATUS_LABELS[task.status] || '未知状态'
}));
} else if (response.data && Array.isArray(response.data.tasks)) {
tasks.value = response.data.tasks.map(task => ({
...task,
status_label: STATUS_LABELS[task.status] || '未知状态'
}));
} else {
tasks.value = [];
}
// 清空选中任务和子任务
selectedTask.value = null;
subtasks.value = [];
trayUsageRecords.value = [];
ElMessage.success('查询成功');
} catch (error: any) {
console.error('查询任务列表失败:', error);
const errorMessage = error.response?.data?.message || '未知错误';
ElMessage.error(`查询失败: ${errorMessage}`);
}
}
/**
* 选择任务
*
* @async
* @function selectTask
* @param {Task} task - 选中的任务
* @returns {Promise<void>}
* @description 选中任务并获取其子任务列表
*
* @example
* // 选中任务
* selectTask(task);
*
* @throws {Error} 当API请求失败时会显示错误消息
* @since 1.0.0
*/
export async function selectTask(task: Task) {
try {
// 获取任务详情(包含子任务信息)
const response = await taskAPI.getTask(task.id);
const detailedTask = response.data;
console.log('获取到的任务详情:', detailedTask);
selectedTask.value = detailedTask;
subtasks.value = detailedTask.subtasks || [];
console.log('子任务列表:', subtasks.value);
trayUsageRecords.value = [];
console.log('使用传入的任务数据:', task);
} catch (error: any) {
console.error('获取任务详情失败:', error);
// 如果获取详情失败,使用传入的任务数据
selectedTask.value = task;
subtasks.value = task.subitems || [];
trayUsageRecords.value = [];
const errorMessage = error.response?.data?.message || '未知错误';
ElMessage.error(`获取任务详情失败: ${errorMessage}`);
}
}
/**
* 获取托盘使用记录
*
* @async
* @function fetchTrayUsageRecords
* @param {number} subtaskId - 子任务ID
* @returns {Promise<void>}
* @description 获取指定子任务关联的托盘使用记录
*
* @example
* // 获取托盘使用记录
* fetchTrayUsageRecords(1);
*
* @throws {Error} 当API请求失败时会显示错误消息
* @since 1.0.0
*/
export async function fetchTrayUsageRecords(subtaskId: number) {
try {
// 获取子任务关联的托盘
const response = await subitemAPI.getSubitemTrays(subtaskId);
const trays: Tray[] = response.data.trays || response.data || [];
// 构建托盘使用记录
const records: TrayUsageRecord[] = trays.map(tray => ({
id: tray.association?.id || 0,
flow_id: 0, // 暂时使用默认值,实际应该从任务中获取
subitem_id: subtaskId,
tray_id: tray.id,
actual_count: tray.full_count || 0, // 实际数量暂时使用满载数量
detect_status: tray.status || '未知',
start_time: tray.association?.created_at || tray.created_at,
start_user_id: 1, // 暂时使用默认值
end_time: tray.updated_at || '',
end_user_id: 1, // 暂时使用默认值
remark: tray.remark || tray.association?.remark || '',
created_at: tray.created_at,
updated_at: tray.updated_at
}));
// 只更新当前子任务的托盘使用记录,而不是替换所有记录
const existingRecords = trayUsageRecords.value.filter(record => record.subitem_id !== subtaskId);
trayUsageRecords.value = [...existingRecords, ...records];
} catch (error: any) {
console.error('获取托盘使用记录失败:', error);
const errorMessage = error.response?.data?.message || '未知错误';
ElMessage.error(`获取托盘使用记录失败: ${errorMessage}`);
}
}
/**
* 导出数据
*
* @function exportData
* @returns {void}
* @description 导出当前查询结果的数据
*
* @example
* // 导出数据
* exportData();
*
* @since 1.0.0
*/
export function exportData() {
ElMessage.info('导出数据功能待实现');
// TODO: 实现数据导出逻辑
}
|