重构共享逻辑并修复值班提醒回执去重
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""邮件链接落地页:一键参加活动与邮件按钮测试。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from html import escape
|
||||
|
||||
|
||||
JOIN_PAGE = """\
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>一键参加 · WorkLog</title>
|
||||
<style>
|
||||
body {{ margin:0; min-height:100vh; display:flex; align-items:center; justify-content:center;
|
||||
background:#f3f4f6; font-family:'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif; }}
|
||||
.card {{ max-width:420px; margin:24px; background:#fff; border-radius:14px; padding:36px 32px;
|
||||
text-align:center; box-shadow:0 4px 24px rgba(0,0,0,.08); }}
|
||||
h1 {{ margin:0 0 10px; font-size:20px; color:#111827; }}
|
||||
p {{ margin:0 0 6px; font-size:14px; color:#6b7280; line-height:1.6; }}
|
||||
.btn {{ display:inline-block; margin-top:18px; background:#2563eb; color:#fff; text-decoration:none;
|
||||
font-size:15px; font-weight:600; padding:11px 30px; border-radius:8px; }}
|
||||
.ok {{ color:#059669; }} .err {{ color:#dc2626; }}
|
||||
</style>
|
||||
</head>
|
||||
<body><div class="card"><div id="box"><p>正在处理…</p></div></div></body>
|
||||
</html>"""
|
||||
|
||||
|
||||
def join_page(message: str, state: str, activity_title: str = "", extra: str = "") -> str:
|
||||
icon = "✓" if state == "ok" else ("?" if state == "confirm" else "✕")
|
||||
button = '<a class="btn" href="/">打开 WorkLog</a>' if state == "ok" else ""
|
||||
title_html = (
|
||||
f'<p style="font-size:16px;color:#111827;font-weight:600;">{escape(activity_title)}</p>'
|
||||
if activity_title
|
||||
else ""
|
||||
)
|
||||
heading = {"ok": "记录成功", "confirm": "确认参加", "err": "无法完成"}[state]
|
||||
return JOIN_PAGE.replace(
|
||||
'<div id="box"><p>正在处理…</p></div>',
|
||||
f'<div id="box"><div class="{state}" style="font-size:40px;line-height:1;">{icon}</div>'
|
||||
f"<h1>{heading}</h1>{title_html}"
|
||||
f"<p>{escape(str(message))}</p>{button}{extra}</div>",
|
||||
)
|
||||
|
||||
|
||||
def confirmation_page(message: str, nonce: str | None = None, title: str = '值班邮件确认', button_label: str = '确认已知晓值班安排') -> str:
|
||||
form = (
|
||||
f'<form method="post"><input type="hidden" name="confirmation_token" value="{escape(nonce, quote=True)}">'
|
||||
f'<button type="submit">{escape(button_label)}</button></form>'
|
||||
if nonce
|
||||
else ""
|
||||
)
|
||||
return (
|
||||
f'<!doctype html><html lang="zh-CN"><meta charset="utf-8">'
|
||||
f'<meta name="viewport" content="width=device-width,initial-scale=1"><title>{escape(title)} · WorkLog</title>'
|
||||
f"<style>body{{font:16px/1.8 system-ui,sans-serif;background:#f5f7f5;color:#263c35;margin:0;padding:32px 20px}}"
|
||||
f"main{{max-width:480px;margin:8vh auto;background:white;border:1px solid #e1e8e3;border-radius:16px;padding:28px}}"
|
||||
f"h1{{font-size:24px}}button{{background:#28664f;color:white;border:0;border-radius:8px;padding:12px 20px;"
|
||||
f"font:inherit;cursor:pointer}}p{{overflow-wrap:anywhere}}</style>"
|
||||
f"<main><h1>{escape(title)}</h1><p>{escape(message)}</p>{form}</main></html>"
|
||||
)
|
||||
Reference in New Issue
Block a user