Files
smart-project/h5/js/api.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

198 lines
5.1 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.
// ============================
// API 基础封装 — Mock 模式
// ============================
const API_BASE = '/v1';
// 登录
function apiLogin(username, password) {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
code: 0,
data: {
token: 'mock-token-' + Date.now(),
expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000).toISOString(),
user: MOCK_USER,
}
});
}, 500);
});
}
// 获取设备列表
function apiGetDevices(params = {}) {
return new Promise((resolve) => {
setTimeout(() => {
let items = [...MOCK_DEVICES];
if (params.type === 'tower_crane') {
items = items.filter(d => d.type === 'tower_crane');
} else if (params.type === 'elevator') {
items = items.filter(d => d.type === 'elevator');
}
resolve({ code: 0, data: { total: items.length, items } });
}, 300);
});
}
// 获取设备实时数据
function apiGetDeviceRealtime(deviceId) {
return new Promise((resolve) => {
setTimeout(() => {
const data = getRealtimeById(deviceId);
resolve({ code: 0, data });
}, 200);
});
}
// 获取预警列表
function apiGetAlerts(params = {}) {
return new Promise((resolve) => {
setTimeout(() => {
let items = [...MOCK_ALERTS];
if (params.level === 'danger') {
items = items.filter(a => a.level === 'danger');
} else if (params.level === 'warning') {
items = items.filter(a => a.level === 'warning');
} else if (params.status === 'handled') {
items = items.filter(a => a.status === 'handled' || a.status === 'ignored');
} else if (params.status === 'unread') {
items = items.filter(a => a.status === 'unread');
}
const unreadCount = MOCK_ALERTS.filter(a => a.status === 'unread').length;
resolve({ code: 0, data: { total: items.length, unreadCount, items } });
}, 300);
});
}
// 获取预警详情
function apiGetAlertDetail(alertId) {
return new Promise((resolve) => {
setTimeout(() => {
const alert = getAlertById(alertId);
resolve({ code: 0, data: alert });
}, 200);
});
}
// 处理预警
function apiHandleAlert(alertId, action, note) {
return new Promise((resolve) => {
setTimeout(() => {
const alert = MOCK_ALERTS.find(a => a.id === alertId);
if (alert) {
alert.status = action === 'handled' ? 'handled' : 'ignored';
if (note) alert.handleNote = note;
}
resolve({ code: 0, message: '操作成功' });
}, 500);
});
}
// 提交隐患随手拍
function apiSubmitReport(formData) {
return new Promise((resolve) => {
setTimeout(() => {
const newReport = {
id: 'rep' + Date.now(),
...formData,
createdAt: new Date().toLocaleString('zh-CN'),
};
MOCK_REPORTS.unshift(newReport);
resolve({ code: 0, data: newReport });
}, 800);
});
}
// 获取随手拍记录
function apiGetReports() {
return new Promise((resolve) => {
setTimeout(() => {
resolve({ code: 0, data: { total: MOCK_REPORTS.length, items: MOCK_REPORTS } });
}, 300);
});
}
// 获取随手拍详情
function apiGetReportDetail(id) {
return new Promise((resolve) => {
setTimeout(() => {
const item = MOCK_REPORTS.find(r => r.id === id);
resolve({ code: 0, data: item });
}, 200);
});
}
// 获取日志列表
function apiGetLogs() {
return new Promise((resolve) => {
setTimeout(() => {
resolve({ code: 0, data: { total: MOCK_LOGS.length, items: MOCK_LOGS } });
}, 300);
});
}
// 获取日志详情
function apiGetLogDetail(id) {
return new Promise((resolve) => {
setTimeout(() => {
const item = MOCK_LOGS.find(l => l.id === id);
resolve({ code: 0, data: item });
}, 200);
});
}
// 提交施工日志
function apiSubmitLog(formData) {
return new Promise((resolve) => {
setTimeout(() => {
const newLog = {
id: 'log' + Date.now(),
...formData,
createdAt: new Date().toLocaleString('zh-CN'),
};
MOCK_LOGS.unshift(newLog);
resolve({ code: 0, data: newLog });
}, 800);
});
}
// OSS 预签名 URLMock
function apiGetUploadToken(filename, contentType) {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
code: 0,
data: {
uploadUrl: 'https://jesxion-ai-studio.oss-cn-beijing.aliyuncs.com/mock/' + filename,
objectKey: 'mock/' + filename,
expiresAt: new Date(Date.now() + 3600 * 1000).toISOString(),
}
});
}, 300);
});
}
// 获取 AI 分析列表
function apiGetAIAnalyses(params = {}) {
return new Promise((resolve) => {
setTimeout(() => {
let items = [...MOCK_AI_ANALYSES];
if (params.type && params.type !== 'all') {
items = items.filter(a => a.analysisType === params.type);
}
resolve({ code: 0, data: { total: items.length, items } });
}, 300);
});
}
// 获取 AI 分析详情
function apiGetAIAnalysisDetail(id) {
return new Promise((resolve) => {
setTimeout(() => {
const item = MOCK_AI_ANALYSES.find(a => a.id === id);
resolve({ code: 0, data: item });
}, 200);
});
}