feat: 初始化智能电量监控系统项目
该提交完成了完整的电费监控系统项目初始化,包含: 1. 后端Node.js+Express服务,支持定时采集、登录认证、数据API 2. React前端界面,包含登录页和数据仪表盘 3. Docker容器化配置和docker-compose部署文件 4. 环境变量示例和gitignore、dockerignore配置 5. 完整的项目文档README
This commit is contained in:
39
client/src/api.js
Normal file
39
client/src/api.js
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user