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 | 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 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 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 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 1x 1x 1x 4x 4x 3x 3x 1x 1x 1x 6x 6x 2x 2x 10x 8x 8x 8x 2x 2x 6x 6x 1x 1x 5x 3x 2x 1x 1x 6x 6x 1x 1x 1x 5x 4x 1x 6x 6x 1x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 6x 6x 7x 4x 7x 7x 4x 7x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 7x 1x 1x 1x 1x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 8x 7x 7x 7x 1x 6x 6x 6x 6x 8x 5x 2x 1x 1x 1x 6x 6x 6x 6x 8x 5x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 1x | /**
* 工作台业务逻辑模块
* 提供工作台数据展示和筛选功能
*
* @fileOverview 工作台模块,基于Vue 3 Composition API实现
* @author InspectionFlowSystem Team
* @version 1.0.0
* @since 2025-11-19
*/
import { ref, computed, onMounted } from 'vue';
import { ElMessage } from 'element-plus';
import { taskAPI } from '../../api';
/**
* 检测任务数据接口
* @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;
/** 备注信息 */
remark: string;
/** 任务状态 */
status: number;
/** 创建时间 */
created_at?: string;
/** 更新时间 */
updated_at?: string;
/** 状态标签 */
status_label?: string;
}
/**
* 任务状态映射表
* @constant {Record<number, string>}
* @description 定义任务状态码与状态名称的映射关系
* @since 1.0.0
*/
const STATUS_LABELS: Record<number, string> = {
1: '草稿',
2: '待接取',
3: '进行中',
4: '已完成',
5: '已评审',
6: '已授权',
7: '已中止',
8: '已归档'
};
/**
* 任务状态枚举
* @enum {number}
* @description 定义任务的各种状态码
*/
export const TASK_STATUS = {
DRAFT: 1, // 草稿
PENDING: 2, // 待接取
IN_PROGRESS: 3, // 进行中
COMPLETED: 4, // 已完成
REVIEWED: 5, // 已评审
AUTHORIZED: 6, // 已授权
TERMINATED: 7, // 已中止
ARCHIVED: 8 // 已归档
};
/**
* 工作台标签页配置
* @constant {Array}
* @description 定义工作台标签页的显示和筛选配置
*/
export const DASHBOARD_TABS = [
{ key: 'recent', label: '近期检测任务', filter: 'recent' },
{ key: 'month', label: '本月检测任务', filter: 'month' },
{ key: 'in_progress', label: '进行中任务', filter: 'in_progress' },
{ key: 'pending', label: '待处理任务', filter: 'pending' }
];
/**
* 当前激活的标签页
* @type {import('vue').Ref<string>}
* @description 当前选中的工作台标签页
*/
export const activeTab = ref('recent');
/**
* 任务列表响应式引用
* @type {import('vue').Ref<Task[]>}
* @description 存储所有检测任务的列表数据
*/
export const tasks = ref<Task[]>([]);
/**
* 统计数据响应式引用
* @type {import('vue').Ref<Object>}
* @description 存储各种任务统计信息
*/
export const stats = ref({
totalTasks: 0, // 总检测任务数
monthTasks: 0, // 本月检测任务数
inProgressTasks: 0, // 进行中任务数
pendingTasks: 0 // 待处理任务数
});
/**
* 过滤后的任务列表
* @type {import('vue').ComputedRef<Task[]>}
* @description 根据当前激活标签页过滤后的任务列表
*/
export const filteredTasks = computed(() => {
const now = new Date();
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
switch (activeTab.value) {
case 'recent':
// 近期任务:显示最近10项任务(按创建时间倒序排列)
return [...tasks.value]
.sort((a, b) => {
// 按创建时间倒序排列
if (a.created_at && b.created_at) {
return new Date(b.created_at).getTime() - new Date(a.created_at).getTime();
}
return 0;
})
.slice(0, 10);
case 'month':
// 本月任务:显示本月创建的任务
return tasks.value.filter(task => {
if (task.created_at) {
const taskDate = new Date(task.created_at);
return taskDate >= startOfMonth;
}
return false;
});
case 'in_progress':
// 进行中任务:显示未归档状态的任务(草稿、待接取、进行中、已完成、已评审、已授权)
return tasks.value.filter(task =>
task.status === TASK_STATUS.DRAFT ||
task.status === TASK_STATUS.PENDING ||
task.status === TASK_STATUS.IN_PROGRESS ||
task.status === TASK_STATUS.COMPLETED ||
task.status === TASK_STATUS.REVIEWED ||
task.status === TASK_STATUS.AUTHORIZED
);
case 'pending':
// 待处理任务:显示需要当前用户进行确认、审核、批准、测试的任务
// 这里简化处理,实际应该根据当前用户ID来筛选
return tasks.value.filter(task =>
task.status === TASK_STATUS.PENDING || // 待接取(需要确认)
task.status === TASK_STATUS.COMPLETED // 已完成(需要审核)
);
default:
return tasks.value;
}
});
/**
* 获取任务列表和统计数据
*
* @async
* @function fetchDashboardData
* @returns {Promise<void>}
* @description 获取所有检测任务并计算统计数据
*
* @throws {Error} 当API请求失败时会显示错误消息
* @since 1.0.0
*/
export async function fetchDashboardData() {
try {
// 获取所有任务
const response = await taskAPI.getTasks();
// 处理响应数据
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 = [];
}
// 计算统计数据
calculateStats();
console.log('获取工作台数据成功:', tasks.value);
} catch (error: any) {
console.error('获取工作台数据失败:', error);
const errorMessage = error.response?.data?.message || '未知错误';
ElMessage.error(`获取数据失败: ${errorMessage}`);
}
}
/**
* 计算统计数据
*
* @function calculateStats
* @returns {void}
* @description 根据任务列表计算各种统计数据
*
* @since 1.0.0
*/
function calculateStats() {
const now = new Date();
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
const recentDate = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
// 总检测任务数
stats.value.totalTasks = tasks.value.length;
// 本月检测任务数
stats.value.monthTasks = tasks.value.filter(task => {
if (task.created_at) {
const taskDate = new Date(task.created_at);
return taskDate >= startOfMonth;
}
return false;
}).length;
// 进行中任务数
stats.value.inProgressTasks = tasks.value.filter(task =>
task.status === TASK_STATUS.DRAFT ||
task.status === TASK_STATUS.PENDING ||
task.status === TASK_STATUS.IN_PROGRESS ||
task.status === TASK_STATUS.COMPLETED ||
task.status === TASK_STATUS.REVIEWED ||
task.status === TASK_STATUS.AUTHORIZED
).length;
// 待处理任务数
stats.value.pendingTasks = tasks.value.filter(task =>
task.status === TASK_STATUS.PENDING || // 待接取(需要确认)
task.status === TASK_STATUS.COMPLETED // 已完成(需要审核)
).length;
}
/**
* 切换标签页
*
* @function switchTab
* @param {string} tabKey - 标签页的key值
* @returns {void}
* @description 切换到指定的标签页
*
* @since 1.0.0
*/
export function switchTab(tabKey: string) {
activeTab.value = tabKey;
}
/**
* 获取当前标签页的显示名称
*
* @function getCurrentTabLabel
* @returns {string} 当前标签页的显示名称
* @description 获取当前选中标签页的显示名称
*
* @since 1.0.0
*/
export function getCurrentTabLabel() {
const currentTab = DASHBOARD_TABS.find(tab => tab.key === activeTab.value);
return currentTab ? currentTab.label : '近期检测任务';
}
// 组件加载时获取数据
onMounted(() => {
fetchDashboardData();
}); |