All files / src/views/logic Device.logic.ts

97.31% Statements 653/671
87.5% Branches 70/80
100% Functions 17/17
97.31% Lines 653/671

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 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 6711x 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 16x 16x 16x 8x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 8x 8x 8x 8x 8x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 1x 7x 7x 7x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 2x 2x 2x 2x 2x 2x 2x 2x 7x 4x 4x 4x 4x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 1x 1x 1x 1x 1x 1x 3x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 3x 3x 5x 2x 2x 2x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 3x 3x 5x 2x 2x 2x 5x 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 10x 10x 10x 10x 10x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 21x 21x 21x 21x 21x 5x 1x 1x 1x 1x 5x 1x 4x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 21x 21x 21x 21x 6x 6x 21x 7x 7x 21x 2x 2x 21x 1x 1x 21x     21x     21x     21x     21x     21x 5x 5x 21x     21x     21x     21x 21x 7x 7x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 8x     8x 10x 10x 1x 1x 10x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 2x 2x 2x 2x 2x 2x 2x 2x 2x 5x 3x 3x 3x 3x 5x 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 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 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
/**
 * 设备管理业务逻辑模块
 * 提供设备的增删改查、状态管理、Excel导入导出等功能
 * 
 * @fileOverview 设备管理模块,基于Vue 3 Composition API实现
 * @author InspectionFlowSystem Team
 * @version 1.0.0
 * @since 2025-11-14
 */
 
import { ref } from "vue";
import * as XLSX from "xlsx";
import { ElMessage, ElMessageBox } from 'element-plus';
import api, { deviceAPI } from '../../api/index';
 
/**
 * 设备数据接口
 * @interface Device
 * @description 定义设备的完整数据结构
 * @since 1.0.0
 */
export interface Device {
  /** 设备ID */
  id?: string;
  /** 设备名称 */
  name?: string;
  /** 设备名称(兼容字段) */
  deviceName?: string;
  /** 规格型号 */
  model?: string;
  /** 规格型号(兼容字段) */
  specification?: string;
  /** 制造厂名称 */
  manufacturer?: string;
  /** 固定资产编码 */
  assetCode?: string;
  /** 检测中心编码 */
  centerCode?: string;
  /** 出厂编号 */
  serialNumber?: string;
  /** 责任人 */
  responsiblePerson?: string;
  /** 主要技术指标 */
  technicalIndicators?: string;
  /** 开始使用日期 */
  startDate?: string;
  /** 最近校准日期 */
  calibrationDate?: string;
  /** 需要计量点 */
  measurementPoint?: string;
  /** 扩展不确定度/最大允差/准确度等级 */
  uncertainty?: string;
  /** 设备状态 */
  status?: string;
}
 
/**
 * 设备列表响应式引用
 * @type {import('vue').Ref<Device[]>}
 * @description 存储所有设备的列表数据
 */
export const devices = ref<Device[]>([]);
 
/**
 * 添加设备表单数据响应式引用
 * @type {import('vue').Ref<Device>}
 * @description 绑定到设备添加表单的数据对象
 */
export const deviceForm = ref<Device>({
  name: "",
  model: "",
  manufacturer: "",
  assetCode: "",
  centerCode: "",
  serialNumber: "",
  responsiblePerson: "",
  technicalIndicators: "",
  startDate: "",
  calibrationDate: "",
  measurementPoint: "",
  uncertainty: ""
});
 
/**
 * 批量添加设备对话框显示状态响应式引用
 * @type {import('vue').Ref<boolean>}
 * @description 控制批量添加设备对话框的显示和隐藏
 */
export const showAddDeviceDialog = ref(false);
 
/**
 * 批量导入设备对话框显示状态响应式引用
 * @type {import('vue').Ref<boolean>}
 * @description 控制批量导入设备对话框的显示和隐藏
 */
export const showImportDevicesDialog = ref(false);
 
/**
 * 批量添加的设备数据响应式引用
 * @type {import('vue').Ref<Device[]>}
 * @description 存储批量添加设备的列表数据
 */
export const addDevicesData = ref<Device[]>([
  {
    name: "",
    model: "",
    manufacturer: "",
    assetCode: "",
    centerCode: "",
    serialNumber: "",
    responsiblePerson: "",
    technicalIndicators: "",
    startDate: "",
    calibrationDate: "",
    measurementPoint: "",
    uncertainty: ""
  }
]);
 
/**
 * 批量导入的设备数据响应式引用
 * @type {import('vue').Ref<Device[]>}
 * @description 存储从Excel导入的设备列表数据
 */
export const importDevicesData = ref<Device[]>([]);
 
/**
 * 获取设备列表
 * 
 * @async
 * @function fetchDevices
 * @returns {void}
 * @description 从后端 API 获取所有设备列表,更新本地 devices 响应式数据
 * 
 * @throws {Error} 当API请求失败时会显示错误消息
 * @since 1.0.0
 */
export async function fetchDevices() {
  try {
    const response = await deviceAPI.getDevices();
    devices.value = response.data.devices.map((device: any) => ({
      id: device.id.toString(),
      name: device.name,
      model: device.model,
      manufacturer: device.manufacturer,
      assetCode: device.asset_code,
      centerCode: device.center_code,
      serialNumber: device.serial_number,
      responsiblePerson: device.responsible_person,
      technicalIndicators: device.technical_specs,
      startDate: device.start_date,
      calibrationDate: device.last_calibration_date,
      measurementPoint: device.calibration_points,
      uncertainty: device.equipment_error,
      status: device.status
    }));
  } catch (error) {
    console.error('获取设备列表失败:', error);
    ElMessage.error('获取设备列表失败');
  }
}
 
/**
 * 打开批量添加设备对话框
 * 
 * @function openAddDeviceDialog
 * @returns {void}
 * @description 打开批量添加设备对话框并初始化一个空的设备数据
 * 
 * @since 1.0.0
 */
export function openAddDeviceDialog() {
  // 初始化一个空的设备数据
  addDevicesData.value = [
    {
      name: "",
      model: "",
      manufacturer: "",
      assetCode: "",
      centerCode: "",
      serialNumber: "",
      responsiblePerson: "",
      technicalIndicators: "",
      startDate: "",
      calibrationDate: "",
      measurementPoint: "",
      uncertainty: ""
    }
  ];
  showAddDeviceDialog.value = true;
}
 
/**
 * 关闭批量添加设备对话框
 * 
 * @function closeAddDeviceDialog
 * @returns {void}
 * @description 关闭批量添加设备对话框并清空设备数据
 * 
 * @since 1.0.0
 */
export function closeAddDeviceDialog() {
  showAddDeviceDialog.value = false;
  addDevicesData.value = [];
}
 
/**
 * 保存批量添加的设备
 * 
 * @async
 * @function saveAddDevices
 * @returns {void}
 * @description 验证并保存批量添加的设备数据到后端
 * 
 * @throws {Error} 当API请求失败时会显示错误消息
 * @since 1.0.0
 */
export async function saveAddDevices() {
  try {
    // 过滤掉空的设备数据
    const validDevices = addDevicesData.value.filter(device => 
      device.name || device.model || device.manufacturer || device.assetCode || 
      device.centerCode || device.serialNumber || device.responsiblePerson || 
      device.technicalIndicators
    );
    
    if (validDevices.length === 0) {
      ElMessage.warning('请至少填写一个设备的信息');
      return;
    }
 
    // 转换设备数据格式
    const batchDevices = validDevices.map(device => ({
      name: device.name,
      model: device.model,
      manufacturer: device.manufacturer,
      asset_code: device.assetCode,
      center_code: device.centerCode,
      serial_number: device.serialNumber,
      responsible_person: device.responsiblePerson,
      technical_specs: device.technicalIndicators,
      start_date: device.startDate,
      last_calibration_date: device.calibrationDate,
      calibration_points: device.measurementPoint,
      equipment_error: device.uncertainty
    }));
 
    // 调用批量创建API
    await deviceAPI.batchCreateDevices(batchDevices);
    
    // 关闭对话框
    closeAddDeviceDialog();
    
    // 刷新设备列表
    await fetchDevices();
    
    ElMessage.success('设备添加成功!');
  } catch (error: any) {
    console.error('添加设备失败:', error);
    const errorMsg = error.response?.data?.message || '设备添加失败';
    ElMessage.error(errorMsg);
  }
}
 
/**
 * 删除设备
 * 
 * @async
 * @function deleteDevice
 * @param {string} deviceId - 要删除的设备ID
 * @returns {void}
 * @description 删除指定ID的设备,操作前会弹出确认对话框
 * 
 * @throws {Error} 当API请求失败时会显示错误消息
 * @since 1.0.0
 */
export async function deleteDevice(deviceId: string) {
  ElMessageBox.confirm(
    '确定要删除这个设备吗?此操作不可恢复。',
    '删除确认',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(async () => {
    try {
      await deviceAPI.deleteDevice(parseInt(deviceId));
      await fetchDevices();
      ElMessage.success('设备删除成功!');
    } catch (error) {
      console.error('删除设备失败:', error);
      ElMessage.error('设备删除失败');
    }
  }).catch(() => {
    // 用户取消删除,什么都不做
  });
}
 
/**
 * 启用设备
 * 
 * @async
 * @function enableDevice
 * @param {string} deviceId - 要启用的设备ID
 * @returns {void}
 * @description 启用指定ID的设备
 * 
 * @throws {Error} 当API请求失败时会显示错误消息
 * @since 1.0.0
 */
export async function enableDevice(deviceId: string) {
  try {
    await deviceAPI.enableDevice(parseInt(deviceId));
    await fetchDevices();
    ElMessage.success('设备已启用!');
  } catch (error) {
    console.error('启用设备失败:', error);
    ElMessage.error('设备启用失败');
  }
}
 
/**
 * 停用设备
 * 
 * @async
 * @function disableDevice
 * @param {string} deviceId - 要停用的设备ID
 * @returns {void}
 * @description 停用指定ID的设备
 * 
 * @throws {Error} 当API请求失败时会显示错误消息
 * @since 1.0.0
 */
export async function disableDevice(deviceId: string) {
  try {
    await deviceAPI.disableDevice(parseInt(deviceId));
    await fetchDevices();
    ElMessage.success('设备已停用!');
  } catch (error) {
    console.error('停用设备失败:', error);
    ElMessage.error('设备停用失败');
  }
}
 
/**
 * 添加设备(打开批量添加对话框)
 * 
 * @function addDevice
 * @returns {void}
 * @description 打开批量添加设备对话框的包装函数
 * 
 * @since 1.0.0
 */
export function addDevice() {
  openAddDeviceDialog();
}
 
/**
 * 从Excel导入设备
 * 
 * @async
 * @function importDevicesFromExcel
 * @param {File} file - 要导入的Excel文件
 * @returns {Promise<void>}
 * @description 解析Excel文件并将其数据加载到导入设备列表中
 * 
 * @throws {Error} 当文件解析失败时会显示错误消息
 * @since 1.0.0
 */
export async function importDevicesFromExcel(file: File): Promise<void> {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    
    reader.onload = (e) => {
      try {
        const data = new Uint8Array(e.target?.result as ArrayBuffer);
        const workbook = XLSX.read(data, { type: 'array', cellDates: true, dateNF: 'yyyy-mm-dd' });
        
        // 获取第一个工作表
        const firstSheetName = workbook.SheetNames[0];
        const worksheet = workbook.Sheets[firstSheetName];
        
        // 将工作表转换为JSON,保持原始格式
        const jsonData: any[] = XLSX.utils.sheet_to_json(worksheet, { header: 1, raw: false, dateNF: 'yyyy-mm-dd' });
        
        if (jsonData.length < 2) {
          reject(new Error('Excel文件中没有数据'));
          return;
        }
        
        // 提取表头
        const headers = jsonData[0] as string[];
        
        // 处理数据行
        const deviceData: Device[] = [];
        for (let i = 1; i < jsonData.length; i++) {
          const row = jsonData[i];
          if (row && row.length > 0) {
            const device: any = {};
            for (let j = 0; j < headers.length && j < row.length; j++) {
              const header = headers[j];
              let value = row[j];
              
              // 处理日期格式
              if (header === '开始使用日期' || header === '最近校准日期') {
                if (value instanceof Date) {
                  // 如果是Date对象,转换为字符串格式
                  value = value.getFullYear() + '-' + 
                          String(value.getMonth() + 1).padStart(2, '0') + '-' + 
                          String(value.getDate()).padStart(2, '0');
                } else if (typeof value === 'string' && value.match(/^\d{4}-\d{2}-\d{2}/)) {
                  // 日期已经是 yyyy-mm-dd 格式
                } else if (typeof value === 'string' && value.match(/^\d{1,2}\/\d{1,2}\/\d{4}/)) {
                  // 处理 M/D/YYYY 或 MM/DD/YYYY 格式的日期
                  const parts = value.split('/');
                  if (parts.length === 3) {
                    const month = parts[0].padStart(2, '0');
                    const day = parts[1].padStart(2, '0');
                    const year = parts[2];
                    value = `${year}-${month}-${day}`;
                  }
                } else if (typeof value === 'string' && value.match(/^\d{1,2}\/\d{1,2}\/\d{2}/)) {
                  // 处理 M/D/YY 或 MM/DD/YY 格式的日期
                  const parts = value.split('/');
                  if (parts.length === 3) {
                    const month = parts[0].padStart(2, '0');
                    const day = parts[1].padStart(2, '0');
                    // 假设 00-29 为 2000-2029 年,30-99 为 1930-1999 年
                    let year = parseInt(parts[2]);
                    year = year < 30 ? 2000 + year : 1900 + year;
                    value = `${year}-${month}-${day}`;
                  }
                } else if (typeof value === 'number') {
                  // Excel日期序列号转换为日期
                  const date = new Date((value - 25569) * 86400 * 1000);
                  value = date.getFullYear() + '-' + 
                          String(date.getMonth() + 1).padStart(2, '0') + '-' + 
                          String(date.getDate()).padStart(2, '0');
                }
              }
              
              // 根据表头映射到设备对象属性
              switch (header) {
                case '序号':
                  device.id = value;
                  break;
                case '设备名称':
                  device.name = device.deviceName = value;
                  break;
                case '规格型号':
                  device.model = device.specification = value;
                  break;
                case '制造厂名称':
                  device.manufacturer = value;
                  break;
                case '固定资产编码':
                  device.assetCode = value;
                  break;
                case '检测中心编码':
                  device.centerCode = value;
                  break;
                case '出厂编号':
                  device.serialNumber = value;
                  break;
                case '责任人':
                  device.responsiblePerson = value;
                  break;
                case '主要技术指标':
                  device.technicalIndicators = value;
                  break;
                case '开始使用日期':
                  device.startDate = value;
                  break;
                case '最近校准日期':
                  device.calibrationDate = value;
                  break;
                case '需要计量点':
                  device.measurementPoint = value;
                  break;
                case '扩展不确定度/最大允差/准确度等级':
                  device.uncertainty = value;
                  break;
              }
            }
            // 如果没有ID,生成一个
            if (!device.id) {
              device.id = Date.now().toString() + i;
            }
            deviceData.push(device);
          }
        }
        
        // 设置导入的设备数据
        importDevicesData.value = deviceData;
        showImportDevicesDialog.value = true;
        resolve();
      } catch (error) {
        reject(new Error('解析Excel文件失败: ' + (error as Error).message));
      }
    };
    
    reader.onerror = () => {
      reject(new Error('读取文件失败'));
    };
    
    reader.readAsArrayBuffer(file);
  });
}
 
/**
 * 保存导入的设备
 * 
 * @async
 * @function saveImportedDevices
 * @returns {void}
 * @description 保存从Excel导入的设备数据到后端
 * 
 * @throws {Error} 当API请求失败时会显示错误消息
 * @since 1.0.0
 */
export async function saveImportedDevices() {
  try {
    // 转换设备数据格式
    const batchDevices = importDevicesData.value.map(device => ({
      name: device.name,
      model: device.model,
      manufacturer: device.manufacturer,
      asset_code: device.assetCode,
      center_code: device.centerCode,
      serial_number: device.serialNumber,
      responsible_person: device.responsiblePerson,
      technical_specs: device.technicalIndicators,
      start_date: device.startDate,
      last_calibration_date: device.calibrationDate,
      calibration_points: device.measurementPoint,
      equipment_error: device.uncertainty
    }));
 
    // 调用批量创建API
    await deviceAPI.batchCreateDevices(batchDevices);
    
    // 关闭对话框
    showImportDevicesDialog.value = false;
    importDevicesData.value = [];
    
    // 刷新设备列表
    await fetchDevices();
    
    ElMessage.success('设备导入成功!');
  } catch (error: any) {
    console.error('导入设备失败:', error);
    const errorMsg = error.response?.data?.message || '设备导入失败';
    ElMessage.error(errorMsg);
  }
}
 
/**
 * 删除导入的设备
 * 
 * @function removeImportDevice
 * @param {number} index - 要删除的设备在导入列表中的索引
 * @returns {void}
 * @description 从导入设备列表中删除指定索引的设备
 * 
 * @since 1.0.0
 */
export function removeImportDevice(index: number) {
  importDevicesData.value.splice(index, 1);
}
 
/**
 * 删除批量添加的设备
 * 
 * @function removeAddDevice
 * @param {number} index - 要删除的设备在批量添加列表中的索引
 * @returns {void}
 * @description 从批量添加设备列表中删除指定索引的设备
 * 
 * @since 1.0.0
 */
export function removeAddDevice(index: number) {
  if (addDevicesData.value.length > 1) {
    addDevicesData.value.splice(index, 1);
  } else {
    // 如果只有一项,清空内容而不是删除
    addDevicesData.value[0] = {
      name: "",
      model: "",
      manufacturer: "",
      assetCode: "",
      centerCode: "",
      serialNumber: "",
      responsiblePerson: "",
      technicalIndicators: "",
      startDate: "",
      calibrationDate: "",
      measurementPoint: "",
      uncertainty: ""
    };
  }
}
 
/**
 * 添加新的导入设备
 * 
 * @function addImportDevice
 * @returns {void}
 * @description 向导入设备列表中添加一个新的空设备对象
 * 
 * @since 1.0.0
 */
export function addImportDevice() {
  importDevicesData.value.push({
    name: "",
    model: "",
    manufacturer: "",
    assetCode: "",
    centerCode: "",
    serialNumber: "",
    responsiblePerson: "",
    technicalIndicators: "",
    startDate: "",
    calibrationDate: "",
    measurementPoint: "",
    uncertainty: ""
  });
}
 
/**
 * 添加新的批量添加设备
 * 
 * @function addAddDevice
 * @returns {void}
 * @description 向批量添加设备列表中添加一个新的空设备对象
 * 
 * @since 1.0.0
 */
export function addAddDevice() {
  addDevicesData.value.push({
    name: "",
    model: "",
    manufacturer: "",
    assetCode: "",
    centerCode: "",
    serialNumber: "",
    responsiblePerson: "",
    technicalIndicators: "",
    startDate: "",
    calibrationDate: "",
    measurementPoint: "",
    uncertainty: ""
  });
}
 
/**
 * 下载模板
 * 
 * @function downloadTemplate
 * @returns {void}
 * @description 触发下载设备导入Excel模板文件
 * 
 * @since 1.0.0
 */
export function downloadTemplate() {
  // 创建下载链接
  const link = document.createElement('a');
  link.href = '/src/assets/检测设备模板表.xlsx';
  link.download = '检测设备模板表.xlsx';
  link.click();
}