Files
smart-project/h5/js/mock.js
Jesxion 982f57a169 Task 4: 创建Mock数据文件
- MOCK_DEVICES: 5台设备 (3台塔吊, 2台升降机)
- MOCK_REALTIME: 设备实时监测数据
- MOCK_ALERTS: 6条预警记录
- MOCK_REPORTS: 3条隐患随手拍记录
- MOCK_LOGS: 3条施工日志
- MOCK_USER: 用户信息
- 辅助函数: getDeviceById, getAlertById, getRealtimeById
2026-04-14 12:27:10 +08:00

330 lines
7.2 KiB
JavaScript
Raw 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.
// Mock数据文件 - 智慧工地H5原型
// 本文件包含所有Mock数据供其他JS文件使用
// ==================== 设备数据 ====================
const MOCK_DEVICES = [
{
id: 'tc001',
name: '1号塔吊',
type: 'tower_crane',
model: 'QTZ500',
location: 'A区施工现场',
status: 'online',
lastSeen: '2026-04-14 12:00:00'
},
{
id: 'tc002',
name: '2号塔吊',
type: 'tower_crane',
model: 'QTZ630',
location: 'B区施工现场',
status: 'online',
lastSeen: '2026-04-14 12:00:00'
},
{
id: 'tc003',
name: '3号塔吊',
type: 'tower_crane',
model: 'QTZ500',
location: 'C区施工现场',
status: 'offline',
lastSeen: '2026-04-14 08:30:00'
},
{
id: 'el001',
name: '1号升降机',
type: 'elevator',
model: 'SC200/200',
location: 'A区主楼',
status: 'online',
lastSeen: '2026-04-14 12:00:00'
},
{
id: 'el002',
name: '2号升降机',
type: 'elevator',
model: 'SC200/200',
location: 'B区主楼',
status: 'online',
lastSeen: '2026-04-14 12:00:00'
}
];
// ==================== 实时数据 ====================
const MOCK_REALTIME = {
tc001: {
weight: 45.2,
windSpeed: 5.2,
range: 30.5,
height: 85.0,
angle: 120.5,
momentPercent: 85.3,
alert: 'danger',
alertMsg: '载重超限'
},
tc002: {
weight: 32.1,
windSpeed: 4.8,
range: 25.0,
height: 92.3,
angle: 45.2,
momentPercent: 55.8,
alert: null,
alertMsg: null
},
tc003: {
weight: 0,
windSpeed: 0,
range: 0,
height: 0,
angle: 0,
momentPercent: 0,
alert: null,
alertMsg: null
},
el001: {
realtimeWeight: 1.2,
realtimeSpeed: 1.0,
realtimeHeight: 45.5,
realtimeDipX: 0.5,
realtimeDipY: 0.3,
outDoorStatus: '0',
alert: 'warning',
alertMsg: '风速过大'
},
el002: {
realtimeWeight: 0.8,
realtimeSpeed: 0.8,
realtimeHeight: 32.0,
realtimeDipX: 0.2,
realtimeDipY: 0.1,
outDoorStatus: '0',
alert: null,
alertMsg: null
}
};
// ==================== 预警数据 ====================
const MOCK_ALERTS = [
{
id: 'al001',
deviceId: 'tc001',
deviceName: '1号塔吊',
deviceType: 'tower_crane',
level: 'danger',
message: '载重超限',
metric: 'weight',
value: 45.2,
createdAt: '2026-04-14 11:30:00',
status: 'unread',
handleNote: null
},
{
id: 'al002',
deviceId: 'el001',
deviceName: '1号升降机',
deviceType: 'elevator',
level: 'warning',
message: '风速过大',
metric: 'windSpeed',
value: 5.2,
createdAt: '2026-04-14 10:15:00',
status: 'unread',
handleNote: null
},
{
id: 'al003',
deviceId: 'tc002',
deviceName: '2号塔吊',
deviceType: 'tower_crane',
level: 'warning',
message: '力矩超限',
metric: 'momentPercent',
value: 78.5,
createdAt: '2026-04-13 16:20:00',
status: 'handled',
handleNote: '已安排人员检修,现已恢复正常'
},
{
id: 'al004',
deviceId: 'tc001',
deviceName: '1号塔吊',
deviceType: 'tower_crane',
level: 'danger',
message: '回转角度异常',
metric: 'angle',
value: 185.0,
createdAt: '2026-04-13 14:00:00',
status: 'handled',
handleNote: '传感器误报,已校准'
},
{
id: 'al005',
deviceId: 'el001',
deviceName: '1号升降机',
deviceType: 'elevator',
level: 'warning',
message: '高度接近上限',
metric: 'realtimeHeight',
value: 95.0,
createdAt: '2026-04-12 09:30:00',
status: 'ignored',
handleNote: '属正常施工需要'
},
{
id: 'al006',
deviceId: 'tc003',
deviceName: '3号塔吊',
deviceType: 'tower_crane',
level: 'warning',
message: '设备离线',
metric: 'status',
value: null,
createdAt: '2026-04-14 08:30:00',
status: 'unread',
handleNote: null
}
];
// ==================== 隐患随手拍数据 ====================
const MOCK_REPORTS = [
{
id: 'rep001',
category: '高空坠落',
severity: '较大',
location: 'A区基坑',
description: '基坑周边防护栏杆缺失,存在高空坠落风险',
reporter: '张三',
reportedAt: '2026-04-14 09:00:00',
status: 'pending'
},
{
id: 'rep002',
category: '触电',
severity: '一般',
location: 'B区钢筋加工区',
description: '配电箱门未关闭,电缆裸露',
reporter: '李四',
reportedAt: '2026-04-13 15:30:00',
status: 'resolved'
},
{
id: 'rep003',
category: '物体打击',
severity: '重大',
location: 'C区脚手架',
description: '脚手架上散落物料未清理,高空落物风险',
reporter: '王五',
reportedAt: '2026-04-12 11:20:00',
status: 'processing'
}
];
// ==================== 施工日志数据 ====================
const MOCK_LOGS = [
{
id: 'log001',
date: '2026-04-14',
location: 'A区主楼',
content: '完成3层混凝土浇筑',
workers: 28,
weather: '晴',
remark: '施工顺利,质量合格'
},
{
id: 'log002',
date: '2026-04-13',
location: 'B区地下室',
content: '土方开挖',
workers: 18,
weather: '多云',
remark: '发现地下管线,已联系相关部门'
},
{
id: 'log003',
date: '2026-04-12',
location: 'C区基坑',
content: '基坑支护施工',
workers: 12,
weather: '阴',
remark: '按计划进行中'
}
];
// ==================== 用户数据 ====================
const MOCK_USER = {
id: 1,
username: 'admin',
realName: '张工地',
role: '管理员',
phone: '138****1234',
avatar: null,
department: '工程部'
};
// ==================== 辅助函数 ====================
/**
* 根据设备ID获取设备信息
* @param {string} id - 设备ID
* @returns {Object|undefined} 设备对象
*/
function getDeviceById(id) {
return MOCK_DEVICES.find(function(device) {
return device.id === id;
});
}
/**
* 根据预警ID获取预警信息
* @param {string} id - 预警ID
* @returns {Object|undefined} 预警对象
*/
function getAlertById(id) {
return MOCK_ALERTS.find(function(alert) {
return alert.id === id;
});
}
/**
* 根据设备ID获取实时数据
* @param {string} id - 设备ID
* @returns {Object|undefined} 实时数据对象
*/
function getRealtimeById(id) {
return MOCK_REALTIME[id];
}
/**
* 获取所有在线设备
* @returns {Array} 在线设备列表
*/
function getOnlineDevices() {
return MOCK_DEVICES.filter(function(device) {
return device.status === 'online';
});
}
/**
* 获取未读预警数量
* @returns {number} 未读预警数量
*/
function getUnreadAlertCount() {
return MOCK_ALERTS.filter(function(alert) {
return alert.status === 'unread';
}).length;
}
// 导出全局变量和函数
window.MOCK_DEVICES = MOCK_DEVICES;
window.MOCK_REALTIME = MOCK_REALTIME;
window.MOCK_ALERTS = MOCK_ALERTS;
window.MOCK_REPORTS = MOCK_REPORTS;
window.MOCK_LOGS = MOCK_LOGS;
window.MOCK_USER = MOCK_USER;
window.getDeviceById = getDeviceById;
window.getAlertById = getAlertById;
window.getRealtimeById = getRealtimeById;
window.getOnlineDevices = getOnlineDevices;
window.getUnreadAlertCount = getUnreadAlertCount;