feat: 初始化智能电量监控系统项目

该提交完成了完整的电费监控系统项目初始化,包含:
1.  后端Node.js+Express服务,支持定时采集、登录认证、数据API
2.  React前端界面,包含登录页和数据仪表盘
3.  Docker容器化配置和docker-compose部署文件
4.  环境变量示例和gitignore、dockerignore配置
5.  完整的项目文档README
This commit is contained in:
EchoZenith
2026-05-22 19:10:30 +08:00
parent 0b771ad8ae
commit e79975f2f5
18 changed files with 5562 additions and 1 deletions

39
client/src/api.js Normal file
View File

@@ -0,0 +1,39 @@
const BASE = '/api';
export async function checkAuth() {
const res = await fetch(`${BASE}/check-auth`);
if (res.status === 401) return false;
const data = await res.json();
return data.success;
}
export async function login(username, password) {
const res = await fetch(`${BASE}/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
});
return res.json();
}
export async function logout() {
await fetch(`${BASE}/logout`, { method: 'POST' });
}
export async function fetchCurrent() {
const res = await fetch(`${BASE}/current`);
if (res.status === 401) throw new Error('未登录');
return res.json();
}
export async function fetchHistory() {
const res = await fetch(`${BASE}/history`);
if (res.status === 401) throw new Error('未登录');
return res.json();
}
export async function triggerCollect() {
const res = await fetch(`${BASE}/trigger-collect`);
if (res.status === 401) throw new Error('未登录');
return res.json();
}