refactor: 清理冗余代码与废弃功能
1. 移除全局css变量中多余的定义 2. 简化通知发送函数参数与逻辑 3. 删除测试通知接口与前端按钮 4. 修复图表容器盒模型样式问题
This commit is contained in:
@@ -16,13 +16,7 @@ const cssVars = `
|
|||||||
--text-primary: #1a1a1a;
|
--text-primary: #1a1a1a;
|
||||||
--text-secondary: #666;
|
--text-secondary: #666;
|
||||||
--text-tertiary: #999;
|
--text-tertiary: #999;
|
||||||
--text-placeholder: #999;
|
|
||||||
--border-light: #e8e8e8;
|
--border-light: #e8e8e8;
|
||||||
--shadow-card: 0 2px 8px rgba(0,0,0,0.08);
|
|
||||||
--color-blue: #4a90e2;
|
|
||||||
--color-orange: #f39c12;
|
|
||||||
--color-purple: #9b59b6;
|
|
||||||
--color-green: #27ae60;
|
|
||||||
--tab-bg: #f0f2f5;
|
--tab-bg: #f0f2f5;
|
||||||
--tab-bg-active: #333;
|
--tab-bg-active: #333;
|
||||||
--tab-text: #666;
|
--tab-text: #666;
|
||||||
@@ -41,7 +35,6 @@ const cssVars = `
|
|||||||
--text-secondary: #a0a0a0;
|
--text-secondary: #a0a0a0;
|
||||||
--text-tertiary: #808080;
|
--text-tertiary: #808080;
|
||||||
--border-light: #333;
|
--border-light: #333;
|
||||||
--shadow-card: none;
|
|
||||||
--tab-bg: #2a2a2a;
|
--tab-bg: #2a2a2a;
|
||||||
--tab-bg-active: #4a90e2;
|
--tab-bg-active: #4a90e2;
|
||||||
--tab-text: #808080;
|
--tab-text: #808080;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||||
import { Button, Spin, message, DatePicker } from 'antd';
|
import { Button, Spin, message, DatePicker } from 'antd';
|
||||||
import { LogoutOutlined, ReloadOutlined, BugOutlined } from '@ant-design/icons';
|
import { LogoutOutlined, ReloadOutlined } from '@ant-design/icons';
|
||||||
import { Lightning, ChartLine, ChartHistogram, Timer } from '@icon-park/react';
|
import { Lightning, ChartLine, ChartHistogram, Timer } from '@icon-park/react';
|
||||||
import { Chart, registerables } from 'chart.js';
|
import { Chart, registerables } from 'chart.js';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
@@ -108,20 +108,6 @@ export default function Dashboard({ onLogout }) {
|
|||||||
onLogout();
|
onLogout();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTestNotify = async () => {
|
|
||||||
try {
|
|
||||||
const res = await fetch('/api/test-notify');
|
|
||||||
const data = await res.json();
|
|
||||||
if (data.success) {
|
|
||||||
message.success('测试消息已发送,请检查通知渠道');
|
|
||||||
} else {
|
|
||||||
message.error('发送失败');
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
message.error('发送失败');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSendReport = async () => {
|
const handleSendReport = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/send-report');
|
const res = await fetch('/api/send-report');
|
||||||
@@ -362,19 +348,6 @@ body { margin: 0; }
|
|||||||
>
|
>
|
||||||
手动获取
|
手动获取
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
|
||||||
icon={<BugOutlined />}
|
|
||||||
onClick={handleTestNotify}
|
|
||||||
size="small"
|
|
||||||
style={{
|
|
||||||
border: '1px solid var(--border-light)',
|
|
||||||
borderRadius: 20,
|
|
||||||
color: 'var(--text-secondary)',
|
|
||||||
fontSize: 13,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
测试通知
|
|
||||||
</Button>
|
|
||||||
<Button
|
<Button
|
||||||
onClick={handleSendReport}
|
onClick={handleSendReport}
|
||||||
size="small"
|
size="small"
|
||||||
@@ -450,7 +423,7 @@ body { margin: 0; }
|
|||||||
<div className="d-chart" style={{ position: 'relative', height: 280, background: 'var(--bg-chart)', borderRadius: 8 }}>
|
<div className="d-chart" style={{ position: 'relative', height: 280, background: 'var(--bg-chart)', borderRadius: 8 }}>
|
||||||
{(!isToday && (!dateRecords || dateRecords.length === 0)) || (isToday && (!currentData?.todayRecords || currentData.todayRecords.length === 0)) ? (
|
{(!isToday && (!dateRecords || dateRecords.length === 0)) || (isToday && (!currentData?.todayRecords || currentData.todayRecords.length === 0)) ? (
|
||||||
<div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--text-tertiary)' }}>暂无数据</div>
|
<div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--text-tertiary)' }}>暂无数据</div>
|
||||||
) : <div style={{ padding: 20, height: '100%' }}><canvas ref={hourlyChartRef} /></div>}
|
) : <div style={{ padding: 20, height: '100%', boxSizing: 'border-box' }}><canvas ref={hourlyChartRef} /></div>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -484,7 +457,7 @@ body { margin: 0; }
|
|||||||
<div className="d-chart" style={{ position: 'relative', height: 280, background: 'var(--bg-chart)', borderRadius: 8 }}>
|
<div className="d-chart" style={{ position: 'relative', height: 280, background: 'var(--bg-chart)', borderRadius: 8 }}>
|
||||||
{(!historyData?.dailyRecords || historyData.dailyRecords.length === 0) ? (
|
{(!historyData?.dailyRecords || historyData.dailyRecords.length === 0) ? (
|
||||||
<div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--text-tertiary)' }}>暂无历史数据</div>
|
<div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--text-tertiary)' }}>暂无历史数据</div>
|
||||||
) : <div style={{ padding: 20, height: '100%' }}><canvas ref={trendChartRef} /></div>}
|
) : <div style={{ padding: 20, height: '100%', boxSizing: 'border-box' }}><canvas ref={trendChartRef} /></div>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
17
server.js
17
server.js
@@ -136,10 +136,10 @@ async function sendTelegramNotification(text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendAllNotifications(markdownContent, plainText) {
|
async function sendAllNotifications(markdownContent) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
sendWecomNotification(markdownContent),
|
sendWecomNotification(markdownContent),
|
||||||
sendTelegramNotification(plainText || markdownContent),
|
sendTelegramNotification(markdownContent),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ async function checkThresholdAndAlert(amount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function calculateDailyUsage(records) {
|
function calculateDailyUsage(records) {
|
||||||
if (records.length < 2) return { dailyUsage: 0, todayUsage: 0, todayCost: 0, dailyRecords: [] };
|
if (records.length < 2) return { dailyRecords: [] };
|
||||||
|
|
||||||
const dailyMap = {};
|
const dailyMap = {};
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ function calculateDailyUsage(records) {
|
|||||||
prevLastSurplus = lastSurplus;
|
prevLastSurplus = lastSurplus;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { dailyUsage: 0, todayUsage: 0, todayCost: 0, dailyRecords };
|
return { dailyRecords };
|
||||||
}
|
}
|
||||||
|
|
||||||
const CLIENT_DIR = path.join(__dirname, 'client', 'dist');
|
const CLIENT_DIR = path.join(__dirname, 'client', 'dist');
|
||||||
@@ -501,15 +501,6 @@ app.get('/api/trigger-collect', requireAuth, async (req, res) => {
|
|||||||
res.json({ success: true, message: '采集完成' });
|
res.json({ success: true, message: '采集完成' });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/test-notify', requireAuth, async (req, res) => {
|
|
||||||
await sendAllNotifications(
|
|
||||||
'## 电费监控测试消息\n\n' +
|
|
||||||
`> 时间:${new Date().toLocaleString('zh-CN')}\n\n` +
|
|
||||||
'如果收到此消息,说明推送通知配置正常。'
|
|
||||||
);
|
|
||||||
res.json({ success: true, message: '测试消息已发送,请检查通知渠道' });
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/api/send-report', requireAuth, async (req, res) => {
|
app.get('/api/send-report', requireAuth, async (req, res) => {
|
||||||
await sendDailyReport();
|
await sendDailyReport();
|
||||||
res.json({ success: true, message: '日报已发送' });
|
res.json({ success: true, message: '日报已发送' });
|
||||||
|
|||||||
Reference in New Issue
Block a user