691 lines
20 KiB
HTML
691 lines
20 KiB
HTML
<!doctype html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>电费计算器 · 功能工具箱</title>
|
|
<link rel="icon" href="assets/favicon.svg" type="image/svg+xml" />
|
|
<link rel="stylesheet" href="assets/styles.css" />
|
|
<script src="assets/common.js"></script>
|
|
<style>
|
|
.mode-row {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 12px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.mode-row .hint {
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.field-group-title {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 7px;
|
|
margin: 4px 0 12px;
|
|
font-size: 0.78rem;
|
|
font-weight: 700;
|
|
letter-spacing: 0.06em;
|
|
color: var(--text-muted);
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
.field-group-title::after {
|
|
content: "";
|
|
flex: 1;
|
|
height: 1px;
|
|
background: var(--border);
|
|
}
|
|
|
|
.dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
flex: none;
|
|
display: inline-block;
|
|
}
|
|
|
|
.dot--peak {
|
|
background: #ef4444;
|
|
box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.14);
|
|
}
|
|
|
|
.dot--valley {
|
|
background: #10b981;
|
|
box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.14);
|
|
}
|
|
|
|
.breakdown {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 12px;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.breakdown .stat {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.breakdown .stat .stat-body {
|
|
min-width: 0;
|
|
}
|
|
|
|
.result-hero {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: flex-end;
|
|
justify-content: space-between;
|
|
gap: 10px;
|
|
padding: 18px 20px;
|
|
border-radius: 14px;
|
|
background:
|
|
radial-gradient(
|
|
420px 180px at 0% 0%,
|
|
rgba(99, 102, 241, 0.18),
|
|
transparent 70%
|
|
),
|
|
var(--accent-soft);
|
|
margin-bottom: 14px;
|
|
}
|
|
|
|
.result-hero .label {
|
|
font-size: 0.8rem;
|
|
color: var(--text-secondary);
|
|
margin-bottom: 2px;
|
|
}
|
|
|
|
.result-hero .value {
|
|
font-size: clamp(1.9rem, 4vw, 2.5rem);
|
|
font-weight: 750;
|
|
letter-spacing: -0.035em;
|
|
line-height: 1.1;
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
|
|
.result-hero .value small {
|
|
font-size: 0.95rem;
|
|
font-weight: 500;
|
|
color: var(--text-secondary);
|
|
margin-left: 3px;
|
|
}
|
|
|
|
.result-hero .side {
|
|
font-size: 0.8rem;
|
|
color: var(--text-secondary);
|
|
text-align: right;
|
|
line-height: 1.7;
|
|
}
|
|
|
|
.result-hero .side b {
|
|
color: var(--text);
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
|
|
.consumption-line {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 16px;
|
|
padding: 12px 2px 0;
|
|
border-top: 1px solid var(--border);
|
|
margin-top: 14px;
|
|
font-size: 0.8rem;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.consumption-line b {
|
|
color: var(--text-secondary);
|
|
font-variant-numeric: tabular-nums;
|
|
font-weight: 650;
|
|
}
|
|
|
|
#errorBox {
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
@media (max-width: 560px) {
|
|
.breakdown {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.result-hero .side {
|
|
text-align: left;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="tool-page tool-page--narrow">
|
|
<header class="tool-header">
|
|
<div class="tool-icon">
|
|
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
<path d="M13 2 4.5 13.5H11l-1 8.5L19.5 10H13l1-8Z" />
|
|
</svg>
|
|
</div>
|
|
<div>
|
|
<h1>电费计算器</h1>
|
|
<p>根据设备功率、使用时长与电价,快速估算用电成本。</p>
|
|
</div>
|
|
<div class="header-actions">
|
|
<button class="btn btn--ghost btn--sm" id="resetBtn" title="恢复默认值">
|
|
重置
|
|
</button>
|
|
<button
|
|
class="btn btn--icon btn--ghost"
|
|
data-theme-toggle
|
|
title="切换主题"
|
|
aria-label="切换主题"
|
|
>
|
|
<svg class="icon-moon" viewBox="0 0 24 24" aria-hidden="true">
|
|
<path d="M21 12.8A8.5 8.5 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z" />
|
|
</svg>
|
|
<svg class="icon-sun" viewBox="0 0 24 24" aria-hidden="true">
|
|
<circle cx="12" cy="12" r="4" />
|
|
<path
|
|
d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"
|
|
/>
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
</header>
|
|
|
|
<section class="card" aria-label="计算参数">
|
|
<div class="mode-row">
|
|
<div class="segmented" role="radiogroup" aria-label="计费模式">
|
|
<label class="seg">
|
|
<input type="radio" name="mode" value="single" checked />
|
|
<span>单一电价</span>
|
|
</label>
|
|
<label class="seg">
|
|
<input type="radio" name="mode" value="peak" />
|
|
<span>峰谷电价</span>
|
|
</label>
|
|
</div>
|
|
<span class="hint">输入后自动计算</span>
|
|
</div>
|
|
|
|
<!-- 单一电价 -->
|
|
<div id="singleFields">
|
|
<div class="form-grid">
|
|
<div class="field">
|
|
<label for="power">设备功耗</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="power"
|
|
value="100"
|
|
min="0"
|
|
step="1"
|
|
inputmode="decimal"
|
|
/>
|
|
<span class="hint">瓦 (W)</span>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="hours">每日使用时长</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="hours"
|
|
value="8"
|
|
min="0"
|
|
max="24"
|
|
step="0.5"
|
|
inputmode="decimal"
|
|
/>
|
|
<span class="hint">小时</span>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="price">电价</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="price"
|
|
value="0.6"
|
|
min="0"
|
|
step="0.01"
|
|
inputmode="decimal"
|
|
/>
|
|
<span class="hint">元 / 度</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 峰谷电价 -->
|
|
<div id="peakFields" hidden>
|
|
<div class="form-grid">
|
|
<div class="field">
|
|
<label for="peakPower">设备功耗</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="peakPower"
|
|
value="100"
|
|
min="0"
|
|
step="1"
|
|
inputmode="decimal"
|
|
/>
|
|
<span class="hint">瓦 (W)</span>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="peakHours">高峰时段使用</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="peakHours"
|
|
value="14"
|
|
min="0"
|
|
max="24"
|
|
step="0.5"
|
|
inputmode="decimal"
|
|
/>
|
|
<span class="hint">小时</span>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="valleyHours">低谷时段使用</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="valleyHours"
|
|
value="10"
|
|
min="0"
|
|
max="24"
|
|
step="0.5"
|
|
inputmode="decimal"
|
|
/>
|
|
<span class="hint">小时</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="divider"></div>
|
|
|
|
<div class="field-group-title">峰谷时段</div>
|
|
<div class="form-grid">
|
|
<div class="field">
|
|
<label for="peakStart">高峰开始时间</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="peakStart"
|
|
value="8"
|
|
min="0"
|
|
max="23"
|
|
step="1"
|
|
/>
|
|
<span class="hint">时</span>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="peakEnd">高峰结束时间</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="peakEnd"
|
|
value="22"
|
|
min="0"
|
|
max="23"
|
|
step="1"
|
|
/>
|
|
<span class="hint">时</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="divider"></div>
|
|
|
|
<div class="field-group-title">峰谷电价</div>
|
|
<div class="form-grid">
|
|
<div class="field">
|
|
<label for="peakPrice">
|
|
<span class="dot dot--peak"></span>
|
|
高峰电价
|
|
</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="peakPrice"
|
|
value="0.568"
|
|
min="0"
|
|
step="0.001"
|
|
inputmode="decimal"
|
|
/>
|
|
<span class="hint">元 / 度</span>
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label for="valleyPrice">
|
|
<span class="dot dot--valley"></span>
|
|
低谷电价
|
|
</label>
|
|
<div class="input-row">
|
|
<input
|
|
type="number"
|
|
id="valleyPrice"
|
|
value="0.288"
|
|
min="0"
|
|
step="0.001"
|
|
inputmode="decimal"
|
|
/>
|
|
<span class="hint">元 / 度</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="card" aria-live="polite" aria-label="计算结果">
|
|
<div class="card-head">
|
|
<h2>计算结果</h2>
|
|
<span class="spacer"></span>
|
|
<span class="badge badge--accent">实时估算</span>
|
|
</div>
|
|
|
|
<div class="alert alert--error hidden" id="errorBox" role="alert">
|
|
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
<circle cx="12" cy="12" r="9" />
|
|
<path d="M12 8v5M12 16.5v.01" />
|
|
</svg>
|
|
<span id="errorText"></span>
|
|
</div>
|
|
|
|
<!-- 单一电价结果 -->
|
|
<div id="singleResults">
|
|
<div class="result-hero">
|
|
<div>
|
|
<div class="label">每日电费</div>
|
|
<div class="value">
|
|
<span id="dailyCost">0.00</span><small>元</small>
|
|
</div>
|
|
</div>
|
|
<div class="side">
|
|
每日用电 <b id="dailyKwhSingle">0.00</b> 度<br />
|
|
每度电约 <b id="effectivePrice">0.60</b> 元
|
|
</div>
|
|
</div>
|
|
|
|
<div class="stat-grid">
|
|
<div class="stat">
|
|
<div class="stat-label">每周电费</div>
|
|
<div class="stat-value">
|
|
<span id="weeklyCost">0.00</span
|
|
><span class="unit">元</span>
|
|
</div>
|
|
</div>
|
|
<div class="stat">
|
|
<div class="stat-label">每月电费 · 30 天</div>
|
|
<div class="stat-value">
|
|
<span id="monthlyCost">0.00</span
|
|
><span class="unit">元</span>
|
|
</div>
|
|
</div>
|
|
<div class="stat">
|
|
<div class="stat-label">每年电费 · 365 天</div>
|
|
<div class="stat-value">
|
|
<span id="yearlyCost">0.00</span
|
|
><span class="unit">元</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 峰谷电价结果 -->
|
|
<div id="peakResults" hidden>
|
|
<div class="breakdown">
|
|
<div class="stat">
|
|
<span class="dot dot--peak"></span>
|
|
<div class="stat-body">
|
|
<div class="stat-label">每日高峰电费</div>
|
|
<div class="stat-value">
|
|
<span id="dailyPeakCost">0.00</span
|
|
><span class="unit">元</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="stat">
|
|
<span class="dot dot--valley"></span>
|
|
<div class="stat-body">
|
|
<div class="stat-label">每日低谷电费</div>
|
|
<div class="stat-value">
|
|
<span id="dailyValleyCost">0.00</span
|
|
><span class="unit">元</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="result-hero">
|
|
<div>
|
|
<div class="label">每日总电费</div>
|
|
<div class="value">
|
|
<span id="dailyTotalCost">0.00</span><small>元</small>
|
|
</div>
|
|
</div>
|
|
<div class="side">
|
|
高峰 <b id="peakKwh">0.00</b> 度 · 低谷
|
|
<b id="valleyKwh">0.00</b> 度<br />
|
|
合计 <b id="totalKwh">0.00</b> 度 / 天
|
|
</div>
|
|
</div>
|
|
|
|
<div class="stat-grid">
|
|
<div class="stat">
|
|
<div class="stat-label">每周电费</div>
|
|
<div class="stat-value">
|
|
<span id="weeklyPeakCost">0.00</span
|
|
><span class="unit">元</span>
|
|
</div>
|
|
</div>
|
|
<div class="stat">
|
|
<div class="stat-label">每月电费 · 30 天</div>
|
|
<div class="stat-value">
|
|
<span id="monthlyPeakCost">0.00</span
|
|
><span class="unit">元</span>
|
|
</div>
|
|
</div>
|
|
<div class="stat">
|
|
<div class="stat-label">每年电费 · 365 天</div>
|
|
<div class="stat-value">
|
|
<span id="yearlyPeakCost">0.00</span
|
|
><span class="unit">元</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="consumption-line">
|
|
<span>计算公式:功率 (kW) × 时长 (h) × 电价 (元/度)</span>
|
|
<span class="spacer"></span>
|
|
<span>仅供估算,实际以电表与账单为准</span>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<script>
|
|
(function () {
|
|
"use strict";
|
|
|
|
var DEFAULTS = {
|
|
power: "100",
|
|
hours: "8",
|
|
price: "0.6",
|
|
peakPower: "100",
|
|
peakHours: "14",
|
|
valleyHours: "10",
|
|
peakStart: "8",
|
|
peakEnd: "22",
|
|
peakPrice: "0.568",
|
|
valleyPrice: "0.288",
|
|
};
|
|
|
|
var $ = function (id) {
|
|
return document.getElementById(id);
|
|
};
|
|
|
|
function mode() {
|
|
return document.querySelector('input[name="mode"]:checked').value;
|
|
}
|
|
|
|
function num(id) {
|
|
return parseFloat($(id).value);
|
|
}
|
|
|
|
function setText(id, value) {
|
|
$(id).textContent = value;
|
|
}
|
|
|
|
function showError(message) {
|
|
$("errorText").textContent = message;
|
|
$("errorBox").classList.remove("hidden");
|
|
}
|
|
|
|
function clearError() {
|
|
$("errorBox").classList.add("hidden");
|
|
}
|
|
|
|
function toggleMode() {
|
|
var isSingle = mode() === "single";
|
|
$("singleFields").hidden = !isSingle;
|
|
$("peakFields").hidden = isSingle;
|
|
$("singleResults").hidden = !isSingle;
|
|
$("peakResults").hidden = isSingle;
|
|
calculate();
|
|
}
|
|
|
|
function calculateSingle() {
|
|
var power = num("power");
|
|
var hours = num("hours");
|
|
var price = num("price");
|
|
|
|
if (
|
|
isNaN(power) ||
|
|
isNaN(hours) ||
|
|
isNaN(price) ||
|
|
power < 0 ||
|
|
hours < 0 ||
|
|
price < 0
|
|
) {
|
|
showError("请输入有效的非负数字。");
|
|
return false;
|
|
}
|
|
|
|
if (hours > 24) {
|
|
showError("每日使用时长不能超过 24 小时。");
|
|
return false;
|
|
}
|
|
|
|
clearError();
|
|
|
|
var dailyKwh = (power / 1000) * hours;
|
|
var daily = dailyKwh * price;
|
|
|
|
setText("dailyCost", daily.toFixed(2));
|
|
setText("weeklyCost", (daily * 7).toFixed(2));
|
|
setText("monthlyCost", (daily * 30).toFixed(2));
|
|
setText("yearlyCost", (daily * 365).toFixed(2));
|
|
setText("dailyKwhSingle", dailyKwh.toFixed(2));
|
|
setText("effectivePrice", price.toFixed(2));
|
|
return true;
|
|
}
|
|
|
|
function calculatePeak() {
|
|
var power = num("peakPower");
|
|
var peakHours = num("peakHours");
|
|
var valleyHours = num("valleyHours");
|
|
var peakPrice = num("peakPrice");
|
|
var valleyPrice = num("valleyPrice");
|
|
var peakStart = num("peakStart");
|
|
var peakEnd = num("peakEnd");
|
|
|
|
var values = [
|
|
power,
|
|
peakHours,
|
|
valleyHours,
|
|
peakPrice,
|
|
valleyPrice,
|
|
peakStart,
|
|
peakEnd,
|
|
];
|
|
|
|
if (
|
|
values.some(function (value) {
|
|
return isNaN(value) || value < 0;
|
|
})
|
|
) {
|
|
showError("请输入有效的非负数字。");
|
|
return false;
|
|
}
|
|
|
|
if (peakHours + valleyHours > 24) {
|
|
showError("高峰与低谷使用时长之和不能超过 24 小时。");
|
|
return false;
|
|
}
|
|
|
|
if (peakStart > 23 || peakEnd > 23) {
|
|
showError("高峰时段时间需在 0–23 时之间。");
|
|
return false;
|
|
}
|
|
|
|
clearError();
|
|
|
|
var peakKwh = (power / 1000) * peakHours;
|
|
var valleyKwh = (power / 1000) * valleyHours;
|
|
var peakCost = peakKwh * peakPrice;
|
|
var valleyCost = valleyKwh * valleyPrice;
|
|
var daily = peakCost + valleyCost;
|
|
|
|
setText("dailyPeakCost", peakCost.toFixed(2));
|
|
setText("dailyValleyCost", valleyCost.toFixed(2));
|
|
setText("dailyTotalCost", daily.toFixed(2));
|
|
setText("weeklyPeakCost", (daily * 7).toFixed(2));
|
|
setText("monthlyPeakCost", (daily * 30).toFixed(2));
|
|
setText("yearlyPeakCost", (daily * 365).toFixed(2));
|
|
setText("peakKwh", peakKwh.toFixed(2));
|
|
setText("valleyKwh", valleyKwh.toFixed(2));
|
|
setText("totalKwh", (peakKwh + valleyKwh).toFixed(2));
|
|
return true;
|
|
}
|
|
|
|
function calculate() {
|
|
if (mode() === "single") {
|
|
calculateSingle();
|
|
} else {
|
|
calculatePeak();
|
|
}
|
|
}
|
|
|
|
// 事件绑定
|
|
document.querySelectorAll('input[name="mode"]').forEach(function (radio) {
|
|
radio.addEventListener("change", toggleMode);
|
|
});
|
|
|
|
document.querySelectorAll("input[type='number']").forEach(function (input) {
|
|
input.addEventListener("input", calculate);
|
|
input.addEventListener("change", calculate);
|
|
});
|
|
|
|
$("resetBtn").addEventListener("click", function () {
|
|
Object.keys(DEFAULTS).forEach(function (id) {
|
|
$(id).value = DEFAULTS[id];
|
|
});
|
|
document.querySelector('input[name="mode"][value="single"]').checked =
|
|
true;
|
|
toggleMode();
|
|
Toolbox.toast("已恢复默认参数", "success");
|
|
});
|
|
|
|
// 初始化
|
|
toggleMode();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|