240 lines
7.5 KiB
Rust
240 lines
7.5 KiB
Rust
use actix_web::{get, web, HttpResponse, Responder};
|
|
use sqlx::postgres::PgPool;
|
|
|
|
const HTML_TEMPLATE: &str = r#"<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>小明计算助手</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
'PingFang SC', 'Microsoft YaHei', sans-serif;
|
|
background: #f5f7fa;
|
|
min-height: 100vh;
|
|
color: #333;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
/* ===== Header ===== */
|
|
.hero {
|
|
background: linear-gradient(135deg, #07c160 0%, #06ad56 50%, #059c4c 100%);
|
|
padding: 60px 20px;
|
|
text-align: center;
|
|
color: #fff;
|
|
}
|
|
.hero h1 {
|
|
font-size: 32px;
|
|
font-weight: 700;
|
|
margin-bottom: 12px;
|
|
letter-spacing: 1px;
|
|
}
|
|
.hero p {
|
|
font-size: 16px;
|
|
opacity: 0.9;
|
|
max-width: 500px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
/* ===== Content ===== */
|
|
.content {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 40px 20px 60px;
|
|
}
|
|
|
|
.section {
|
|
background: #fff;
|
|
border-radius: 16px;
|
|
padding: 32px;
|
|
margin-bottom: 24px;
|
|
box-shadow: 0 2px 12px rgba(0,0,0,0.06);
|
|
}
|
|
.section h2 {
|
|
font-size: 22px;
|
|
color: #333;
|
|
margin-bottom: 16px;
|
|
padding-bottom: 12px;
|
|
border-bottom: 2px solid #07c160;
|
|
}
|
|
|
|
.feature-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 16px;
|
|
}
|
|
.feature-card {
|
|
background: #f8f9fa;
|
|
border-radius: 12px;
|
|
padding: 20px;
|
|
text-align: center;
|
|
}
|
|
.feature-card .icon {
|
|
font-size: 36px;
|
|
margin-bottom: 8px;
|
|
}
|
|
.feature-card h3 {
|
|
font-size: 16px;
|
|
color: #333;
|
|
margin-bottom: 6px;
|
|
}
|
|
.feature-card p {
|
|
font-size: 13px;
|
|
color: #999;
|
|
}
|
|
|
|
/* ===== Status Badge ===== */
|
|
.status-row {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
flex-wrap: wrap;
|
|
}
|
|
.status-badge {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
padding: 6px 16px;
|
|
border-radius: 20px;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
}
|
|
.status-ok { background: #e8f5e9; color: #2e7d32; }
|
|
.status-error { background: #fbe9e7; color: #c62828; }
|
|
|
|
.stat-item {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
font-size: 14px;
|
|
color: #666;
|
|
margin-right: 20px;
|
|
}
|
|
|
|
/* ===== Footer ===== */
|
|
.footer {
|
|
text-align: center;
|
|
padding: 32px 20px;
|
|
color: #999;
|
|
font-size: 13px;
|
|
}
|
|
|
|
/* ===== Responsive ===== */
|
|
@media (max-width: 480px) {
|
|
.hero { padding: 40px 16px; }
|
|
.hero h1 { font-size: 26px; }
|
|
.section { padding: 24px 16px; }
|
|
.feature-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
|
|
.feature-card { padding: 16px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Hero -->
|
|
<div class="hero">
|
|
<h1>🌤 小明计算助手</h1>
|
|
<p>环境监测领域的专业计算工具,快速判定大气稳定度等级,判断无组织排放监测适宜性</p>
|
|
</div>
|
|
|
|
<!-- Content -->
|
|
<div class="content">
|
|
|
|
<!-- Features -->
|
|
<div class="section">
|
|
<h2>功能介绍</h2>
|
|
<div class="feature-grid">
|
|
<div class="feature-card">
|
|
<div class="icon">☀️</div>
|
|
<h3>太阳高度角</h3>
|
|
<p>自动计算太阳倾角与高度角</p>
|
|
</div>
|
|
<div class="feature-card">
|
|
<div class="icon">☁️</div>
|
|
<h3>云量计算</h3>
|
|
<p>云量指数与太阳辐射等级</p>
|
|
</div>
|
|
<div class="feature-card">
|
|
<div class="icon">💨</div>
|
|
<h3>风速风向</h3>
|
|
<p>地面风速推算与风向适宜度</p>
|
|
</div>
|
|
<div class="feature-card">
|
|
<div class="icon">📊</div>
|
|
<h3>稳定度判定</h3>
|
|
<p>输出 A-F 稳定度等级与建议</p>
|
|
</div>
|
|
<div class="feature-card">
|
|
<div class="icon">📋</div>
|
|
<h3>数据管理</h3>
|
|
<p>保存、查看、导出检测记录</p>
|
|
</div>
|
|
<div class="feature-card">
|
|
<div class="icon">💳</div>
|
|
<h3>会员服务</h3>
|
|
<p>无限存储,随时续费</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Service Status -->
|
|
<div class="section">
|
|
<h2>服务状态</h2>
|
|
<div class="status-row">
|
|
<span class="status-badge {status_class}">{status_icon} {status_text}</span>
|
|
<span class="stat-item">📦 v{version}</span>
|
|
<span class="stat-item">🗄️ 数据库: {database}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Access -->
|
|
<div class="section">
|
|
<h2>访问方式</h2>
|
|
<div style="text-align:center; margin:20px 0;">
|
|
<p style="margin-bottom:16px; color:#666; font-size:15px;">
|
|
请在微信中搜索「小明计算助手」小程序,或扫描下方二维码打开。
|
|
</p>
|
|
<img src="/static/QR.jpg"
|
|
alt="微信小程序二维码"
|
|
style="width:200px; height:200px; border-radius:12px; box-shadow:0 2px 12px rgba(0,0,0,0.1);">
|
|
</div>
|
|
<p style="color:#999; font-size:13px;">
|
|
本页面为后端服务状态页,小程序功能请通过微信客户端访问。
|
|
</p>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p>小明计算助手 · v{version}</p>
|
|
<p style="margin-top:4px;"><a href="http://beian.miit.gov.cn/" target="_blank" style="color:#999;text-decoration:none;">浙ICP备2026052792号</a></p>
|
|
<p style="margin-top:4px;">如有问题请联系客服</p>
|
|
</div>
|
|
|
|
</body>
|
|
</html>"#;
|
|
|
|
#[get("/")]
|
|
pub async fn root(pool: web::Data<PgPool>) -> impl Responder {
|
|
let (status_class, status_icon, status_text, database) = match sqlx::query("SELECT 1")
|
|
.fetch_one(pool.get_ref())
|
|
.await
|
|
{
|
|
Ok(_) => ("status-ok", "✅", "服务正常", "已连接"),
|
|
Err(_) => ("status-error", "❌", "服务异常", "未连接"),
|
|
};
|
|
|
|
let html = HTML_TEMPLATE
|
|
.replace("{status_class}", status_class)
|
|
.replace("{status_icon}", status_icon)
|
|
.replace("{status_text}", status_text)
|
|
.replace("{database}", database)
|
|
.replace("{version}", env!("CARGO_PKG_VERSION"));
|
|
|
|
HttpResponse::Ok()
|
|
.content_type("text/html; charset=utf-8")
|
|
.body(html)
|
|
}
|