Files
smart-project/h5/js/mock.js
Jesxion e70e5cc69d feat(h5): 修复alert.html认证Bug + 新增log-detail.html日志详情页
- alert.html: requireAuth()后加return防止未登录时继续执行
- 新增log-detail.html: 独立详情页(骨架屏+设备标签+安全备注+照片)
- logs.html: 列表项跳转log-detail.html?id=xxx
- mock.js: MOCK_LOGS补全part/equipment/author/created_at/safety_note字段
- 补全equip-checkbox等CSS样式
2026-04-14 18:22:00 +08:00

415 lines
10 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区主楼',
part: 'A区主楼3层',
content: '完成3层混凝土浇筑浇筑方量约120立方米混凝土标号C35浇筑过程顺利质量检验合格。',
workers: 28,
weather: '晴',
equipment: ['tower_crane', 'elevator'],
safety_note: null,
remark: '施工顺利,质量合格',
photos: [],
author: '张工地',
created_at: '2026-04-14 18:30:00'
},
{
id: 'log002',
date: '2026-04-13',
location: 'B区地下室',
part: 'B区地下室基坑',
content: '土方开挖施工开挖深度约6米使用挖掘机配合自卸汽车作业。',
workers: 18,
weather: '多云',
equipment: ['truck'],
safety_note: '发现地下管线,已联系相关部门处理,现场已设置警示标志',
remark: '发现地下管线,已联系相关部门',
photos: [],
author: '张工地',
created_at: '2026-04-13 17:45:00'
},
{
id: 'log003',
date: '2026-04-12',
location: 'C区基坑',
part: 'C区基坑支护',
content: '基坑支护施工安装锚杆20根喷射混凝土约30平方米。',
workers: 12,
weather: '阴',
equipment: ['tower_crane'],
safety_note: null,
remark: '按计划进行中',
photos: [],
author: '张工地',
created_at: '2026-04-12 18:00:00'
}
];
// ==================== 用户数据 ====================
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;
}
// ==================== AI 智能分析数据 ====================
const MOCK_AI_ANALYSES = [
{
id: 'ai001',
deviceId: 'tc001',
deviceName: '1号塔吊',
deviceType: 'tower_crane',
analysisType: 'person_safety',
confidence: 0.92,
description: '检测到人员靠近吊装区域,触发区域入侵告警',
measures: '建议立即疏散人员,后续加强吊装区域围挡和警示标志',
triggeredAt: '2026-04-14 10:25:00'
},
{
id: 'ai002',
deviceId: 'el001',
deviceName: '1号升降机',
deviceType: 'elevator',
analysisType: 'equipment_anomaly',
confidence: 0.87,
description: '载重超限预警当前载重1.8吨额定载重1.5吨',
measures: '建议减少载重后再进行升降操作',
triggeredAt: '2026-04-14 09:10:00'
},
{
id: 'ai003',
deviceId: 'tc002',
deviceName: '2号塔吊',
deviceType: 'tower_crane',
analysisType: 'environment_risk',
confidence: 0.95,
description: '风速持续超过安全阈值当前风速8.2m/s安全阈值6.0m/s',
measures: '建议停止高空作业,落下吊臂',
triggeredAt: '2026-04-13 15:40:00'
},
{
id: 'ai004',
deviceId: 'el002',
deviceName: '2号升降机',
deviceType: 'elevator',
analysisType: 'person_safety',
confidence: 0.78,
description: '检测到升降机运行中门未关闭,存在人员坠落风险',
measures: '建议立即检查门限位开关',
triggeredAt: '2026-04-12 14:20:00'
}
];
// 辅助函数:根据分析类型获取标签和图标
function getAnalysisTypeInfo(type) {
const map = {
'person_safety': { label: '人员安全', icon: 'ri-user-heart-line', colorClass: 'danger' },
'equipment_anomaly': { label: '设备异常', icon: 'ri-settings-3-line', colorClass: 'warning' },
'environment_risk': { label: '环境风险', icon: 'ri-windy-line', colorClass: 'warning' },
'other': { label: '其他', icon: 'ri-alert-line', colorClass: 'muted' }
};
return map[type] || map['other'];
}
// 辅助函数根据ID获取AI分析
function getAIAnalysisById(id) {
return MOCK_AI_ANALYSES.find(a => a.id === id);
}
// 导出全局变量和函数
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_AI_ANALYSES = MOCK_AI_ANALYSES;
window.MOCK_USER = MOCK_USER;
window.getDeviceById = getDeviceById;
window.getAlertById = getAlertById;
window.getRealtimeById = getRealtimeById;
window.getOnlineDevices = getOnlineDevices;
window.getUnreadAlertCount = getUnreadAlertCount;
window.getAIAnalysisById = getAIAnalysisById;
window.getAnalysisTypeInfo = getAnalysisTypeInfo;