Suzhou-SafetyToolsWarning-WX/utils/mockData.js

309 lines
7.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 模拟数据
* 用于开发和测试
*/
const deviceUtils = require('./deviceUtils');
/**
* 生成模拟设备数据
* @returns {Array} 设备数组
*/
function getMockDevices() {
const devices = [
{
id: '1',
deviceName: '绝缘手套',
deviceCode: 'SB-2023-001',
deviceType: '绝缘手套',
specification: 'YS101-10kV',
manufacturer: '某某电力设备厂',
useUnit: '施工一队',
belongUnit: '电力公司',
location: '工具仓库A区',
responsible: '张三',
purchaseDate: '2022-06-01',
lastInspectionDate: '2023-06-01',
nextInspectionDate: '2024-06-01',
inspectionCycle: 12,
remark: '该设备即将到期,请及时安排检验'
},
{
id: '2',
deviceName: '安全帽',
deviceCode: 'SB-2023-015',
deviceType: '安全帽',
specification: 'ABS-001',
manufacturer: '安全防护用品厂',
useUnit: '施工二队',
belongUnit: '电力公司',
location: '工具仓库B区',
responsible: '李四',
purchaseDate: '2022-08-15',
lastInspectionDate: '2023-08-15',
nextInspectionDate: '2024-08-15',
inspectionCycle: 12,
remark: ''
},
{
id: '3',
deviceName: '安全带',
deviceCode: 'SB-2023-028',
deviceType: '安全带',
specification: 'AD-500',
manufacturer: '高空作业设备厂',
useUnit: '施工三队',
belongUnit: '电力公司',
location: '工具仓库A区',
responsible: '王五',
purchaseDate: '2022-05-20',
lastInspectionDate: '2023-05-20',
nextInspectionDate: '2024-05-20',
inspectionCycle: 12,
remark: '已到期,需立即检验'
},
{
id: '4',
deviceName: '验电器',
deviceCode: 'SB-2023-042',
deviceType: '验电器',
specification: 'YDQ-10kV',
manufacturer: '电力检测设备厂',
useUnit: '维护班组',
belongUnit: '电力公司',
location: '工具仓库C区',
responsible: '赵六',
purchaseDate: '2022-09-10',
lastInspectionDate: '2023-09-10',
nextInspectionDate: '2024-09-10',
inspectionCycle: 12,
remark: ''
},
{
id: '5',
deviceName: '绝缘鞋',
deviceCode: 'SB-2023-056',
deviceType: '绝缘鞋',
specification: 'JYX-10kV',
manufacturer: '某某电力设备厂',
useUnit: '检修班组',
belongUnit: '电力公司',
location: '工具仓库B区',
responsible: '孙七',
purchaseDate: '2022-07-01',
lastInspectionDate: '2023-07-01',
nextInspectionDate: '2024-07-01',
inspectionCycle: 12,
remark: ''
},
{
id: '6',
deviceName: '接地线',
deviceCode: 'SB-2023-070',
deviceType: '接地线',
specification: 'JDX-35mm²',
manufacturer: '电力安全设备厂',
useUnit: '施工一队',
belongUnit: '电力公司',
location: '工具仓库A区',
responsible: '张三',
purchaseDate: '2022-10-15',
lastInspectionDate: '2023-10-15',
nextInspectionDate: '2024-10-15',
inspectionCycle: 12,
remark: ''
},
{
id: '7',
deviceName: '安全围栏',
deviceCode: 'SB-2023-085',
deviceType: '安全围栏',
specification: 'WL-1.2m',
manufacturer: '安全防护用品厂',
useUnit: '施工二队',
belongUnit: '电力公司',
location: '工具仓库C区',
responsible: '李四',
purchaseDate: '2022-11-20',
lastInspectionDate: '2023-11-20',
nextInspectionDate: '2024-11-20',
inspectionCycle: 12,
remark: ''
},
{
id: '8',
deviceName: '绝缘杆',
deviceCode: 'SB-2023-099',
deviceType: '绝缘杆',
specification: 'JYG-10kV-3m',
manufacturer: '电力检测设备厂',
useUnit: '维护班组',
belongUnit: '电力公司',
location: '工具仓库A区',
responsible: '赵六',
purchaseDate: '2022-12-05',
lastInspectionDate: '2023-12-05',
nextInspectionDate: '2024-12-05',
inspectionCycle: 12,
remark: ''
},
{
id: '9',
deviceName: '绝缘垫',
deviceCode: 'SB-2023-112',
deviceType: '绝缘垫',
specification: 'JYD-5mm',
manufacturer: '某某电力设备厂',
useUnit: '检修班组',
belongUnit: '电力公司',
location: '工具仓库B区',
responsible: '孙七',
purchaseDate: '2023-01-10',
lastInspectionDate: '2024-01-10',
nextInspectionDate: '2025-01-10',
inspectionCycle: 12,
remark: ''
},
{
id: '10',
deviceName: '标示牌',
deviceCode: 'SB-2023-125',
deviceType: '标示牌',
specification: 'BSP-A4',
manufacturer: '安全标识厂',
useUnit: '施工三队',
belongUnit: '电力公司',
location: '工具仓库C区',
responsible: '王五',
purchaseDate: '2023-02-15',
lastInspectionDate: '2024-02-15',
nextInspectionDate: '2025-02-15',
inspectionCycle: 12,
remark: ''
}
];
// 处理设备数据,添加计算字段
return deviceUtils.processDeviceList(devices);
}
/**
* 根据ID获取设备详情
* @param {string} id - 设备ID
* @returns {Object|null} 设备详情
*/
function getDeviceById(id) {
const devices = getMockDevices();
return devices.find(device => device.id === id) || null;
}
/**
* 获取预警设备列表
* @param {number} days - 预警天数阈值默认30天
* @returns {Array} 预警设备数组
*/
function getWarningDevices(days = 30) {
const devices = getMockDevices();
return devices.filter(device =>
device.status === 'warning' || device.status === 'expired'
).sort((a, b) => a.daysLeft - b.daysLeft);
}
/**
* 获取最近操作记录
* @returns {Array} 操作记录数组
*/
function getRecentOperations() {
return [
{
id: '1',
deviceId: '1',
deviceName: '绝缘手套',
operation: '查看详情',
time: new Date(Date.now() - 2 * 60 * 1000),
icon: 'view-list'
},
{
id: '2',
deviceId: '2',
deviceName: '安全帽',
operation: '更新检验日期',
time: new Date(Date.now() - 60 * 60 * 1000),
icon: 'edit'
},
{
id: '3',
deviceId: '3',
deviceName: '安全带',
operation: '添加设备',
time: new Date(Date.now() - 3 * 60 * 60 * 1000),
icon: 'add'
},
{
id: '4',
deviceId: '4',
deviceName: '验电器',
operation: '查看详情',
time: new Date(Date.now() - 24 * 60 * 60 * 1000),
icon: 'view-list'
},
{
id: '5',
deviceId: '5',
deviceName: '绝缘鞋',
operation: '编辑设备',
time: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000),
icon: 'edit'
}
].map(item => ({
...item,
time: deviceUtils.getRelativeTime(item.time)
}));
}
/**
* 获取设备类型列表
* @returns {Array} 设备类型数组
*/
function getDeviceTypes() {
return ['全部', '安全帽', '安全带', '绝缘手套', '绝缘鞋', '验电器', '接地线', '安全围栏', '绝缘杆', '绝缘垫', '标示牌'];
}
/**
* 获取使用单位列表
* @returns {Array} 使用单位数组
*/
function getUseUnits() {
return ['全部', '施工一队', '施工二队', '施工三队', '维护班组', '检修班组'];
}
/**
* 获取首页数据
* @returns {Object} 首页数据
*/
function getHomeData() {
const devices = getMockDevices();
const statistics = deviceUtils.getDeviceStatistics(devices);
const warningList = getWarningDevices().slice(0, 3);
const recentList = getRecentOperations().slice(0, 5);
return {
totalDevices: statistics.total,
warningDevices: statistics.warning,
expiredDevices: statistics.expired,
warningList,
recentList
};
}
module.exports = {
getMockDevices,
getDeviceById,
getWarningDevices,
getRecentOperations,
getDeviceTypes,
getUseUnits,
getHomeData
};