1. 页面与样式:一个页面装下整条流程 #
2. 页面分区 #
┌──────────────────────────── 顶栏:logo · 模型徽章 · 查看图 ────────────────────────────┐
├──────────────┬──────────────────────────────────────────────────────────────────────┤
│ 新建报销单 │ 工单列表(点一行看详情) │
│ 工号下拉 ├──────────────────────────────────────────────────────────────────────┤
│ 说明 textarea│ 详情:草稿 / 风险备注 / 审计轨迹 │
│ 明细行 ×N │ 人工审批(暂停时才显示) │
│ 提交按钮 │ 实时事件流 / 检查点历史 │
└──────────────┴──────────────────────────────────────────────────────────────────────┘左栏只负责"造单",右栏负责"看单"。整个交互是同一件事: 提交 → 看流 → 做决定 → 再看流。
3. Jinja2 只做三件事 #
模板里出现的 Jinja2 语法只有 {% for %}、{{ }}、{% if %},没有逻辑计算:
<select id="employee">
{% for e in employees %}
<option value="{{ e.id }}"{% if e.default %} selected{% endif %}>
{{ e.id }} · {{ e.level }}(住宿上限 {{ e.limit }})
</option>
{% endfor %}
</select>这些数据全部来自第 15 节的 employee_options()。
护栏提示也一样:
<p class="hint">
提交后会实时看到 intake → 并行核查 → gate → Agent 起草,然后停在审批。
当前护栏:改稿上限 {{ max_revisions }} 次,自动通过线 {{ auto_limit }} 元,
硬上限 {{ hard_limit }} 元。
</p>页面上不出现任何一个写死的业务数字。 改 config.py,刷新,提示就变。
4. 静态资源的引用方式 #
<link rel="stylesheet" href="{{ url_for('static', filename='css/app.css') }}">
...
<script src="{{ url_for('static', filename='js/app.js') }}"></script>用 url_for 而不是 "/static/css/app.css":Flask 支持给应用挂前缀
(比如部署在 /claim/ 下),url_for 会自动带上,硬编码路径就会 404。
5. 那些"看起来奇怪"的细节 #
① 审批区默认 hidden。
<div id="reviewBox" hidden style="margin-top:14px">只有图真的停在 review 时才显示(第 18 节 renderDetail 里 hidden = !data.paused)。
这样页面上永远不会出现"点了批准但其实没在等审批"的死按钮。
② 三按钮的颜色就是语义。
<button class="btn ok" onclick="decide('approve')">批准付款</button>
<button class="btn warn" onclick="decide('revise')">要求改稿</button>
<button class="btn err" onclick="decide('reject')">驳回</button>绿/橙/红,和 action 一一对应,也和后面状态徽章的配色一致
(paid 绿、等待审批 橙、rejected 红)。
③ 补正输入框放在审批区里。
因为 update_state 只能在暂停期间用(第 16 节),放在审批区表达了这个约束:
没暂停就没有补正。
④ 图抽屉是个覆盖层。
<div class="drawer" id="graphPanel" hidden onclick="if(event.target===this) toggleGraph()">点遮罩关掉,点内容不关——event.target === this 判断的就是"点的是不是遮罩本身"。
6. CSS 的四个要点 #
① 变量集中。
:root{
--bg:#f4f5fb; --card:#ffffff; --ink:#101828; --muted:#667085; --line:#e4e7ec;
--brand:#4f46e5; --ok:#039855; --warn:#dc6803; --err:#d92d20;
--radius:14px; --shadow:0 1px 2px rgba(16,24,40,.06),0 8px 24px rgba(16,24,40,.06);
}状态色只在这里定义一次,徽章、按钮、审计点全部引用它。 换主题只需要改八行。
② 徽章按状态配色。
.badge.ok{background:var(--ok-weak); color:var(--ok)}
.badge.warn{background:var(--warn-weak); color:var(--warn)}
.badge.err{background:var(--err-weak); color:var(--err)}
.badge.mute{background:#f2f4f7; color:var(--muted)}JS 里只负责选 cls(ok / warn / err / mute),不负责选颜色。
样式归 CSS,判断归 JS。
③ 响应式两栏。
.layout{display:grid; grid-template-columns:352px minmax(0,1fr); gap:16px; ...}
@media (max-width:980px){.layout{grid-template-columns:1fr}}minmax(0,1fr) 而不是 1fr:右侧含有可滚动的 pre,
1fr 会让 flex/grid 子项按内容撑开,长日志就把布局顶破。
④ 事件流是深色日志区。
.log{background:#0b1020; color:#cbd5e1; font-family:ui-monospace,Menlo,Consolas,monospace;}这一块是演示时最抓眼球的地方:黑底 + 等宽字体 + 逐行滚动,一眼看出"真的在跑"。
7. 明细行的布局 #
.item-row{display:grid; grid-template-columns:96px 1fr 1fr 30px; gap:6px; margin-bottom:6px}四列:类型 / 金额 / 发票号 / 删除按钮。用 grid 固定第一列宽度, 所以每行的金额框上下对齐,不像 float 布局那样参差。
8. 本节验证 #
set DEEPSEEK_API_KEY=sk-test
uv run claim --port 5000打开 http://127.0.0.1:5000,此时应该看到:
- 顶栏有模型徽章(
deepseek:deepseek-v4-flash); - 左栏有工号下拉(E1002 默认选中)和两行明细;
- 右栏还没有工单,提示"还没有工单";
- 点"提交"暂时没反应或报错——JS 还没写(下一节)。
浏览器控制台会报 toggleGraph is not defined,这是预期的:
按钮已经在那了,函数在下一节和第 19 节补上。
9. 常见坑 #
| 现象 | 原因 |
|---|---|
| 页面没样式 | url_for('static', ...) 路径写错,或 static/ 目录层级不对 |
| 刷新后看不到改动 | 浏览器缓存 CSS,Ctrl+F5 |
| 审批区一直显示 | hidden 属性被 CSS display:flex 覆盖,需要 .drawer[hidden]{display:none} 这类重置 |
| 右侧布局被长日志顶破 | grid-template-columns 用了 1fr 而不是 minmax(0,1fr) |
| 徽章颜色和状态不匹配 | JS 传了中文状态而不是 cls 类名 |
10. 这一节留下的东西 #
一个结构完整、样式到位、但还没有行为的页面。 下一节把表单、列表、详情和流式消费全部接上。
11.代码 #
11.1. app.css #
claim/static/css/app.css
/* 差旅报销审批台样式 */
:root {
--bg: #f4f5fb;
--card: #ffffff;
--ink: #101828;
--muted: #667085;
--line: #e4e7ec;
--brand: #4f46e5;
--brand-weak: #eef2ff;
--ok: #039855;
--ok-weak: #ecfdf3;
--warn: #dc6803;
--warn-weak: #fffaeb;
--err: #d92d20;
--err-weak: #fef3f2;
--radius: 14px;
--shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}
* {
box-sizing: border-box
}
body {
margin: 0;
color: var(--ink);
background:
radial-gradient(900px 420px at 8% -10%, #e8ecff 0%, transparent 60%),
radial-gradient(700px 380px at 100% 0%, #f3e8ff 0%, transparent 55%), var(--bg);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
font-size: 14px;
line-height: 1.55;
}
h1,
h2,
h3 {
margin: 0;
font-weight: 650
}
h1 {
font-size: 17px
}
h2 {
font-size: 15px
}
h3 {
font-size: 13px;
color: var(--muted);
font-weight: 600;
letter-spacing: .02em
}
p {
margin: 0
}
button {
font: inherit;
cursor: pointer;
border-radius: 10px;
border: 1px solid transparent;
transition: .15s
}
button:disabled {
opacity: .5;
cursor: not-allowed
}
.top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 16px 22px;
background: rgba(255, 255, 255, .75);
backdrop-filter: blur(8px);
border-bottom: 1px solid var(--line);
position: sticky;
top: 0;
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 12px
}
.logo {
width: 38px;
height: 38px;
border-radius: 11px;
display: grid;
place-items: center;
background: linear-gradient(135deg, var(--brand), #8b5cf6);
color: #fff;
font-weight: 700;
letter-spacing: -.5px;
box-shadow: 0 6px 16px rgba(79, 70, 229, .28);
}
.brand small {
display: block;
color: var(--muted);
font-size: 12px;
margin-top: 1px
}
.top-actions {
display: flex;
align-items: center;
gap: 10px
}
.layout {
display: grid;
grid-template-columns: 352px minmax(0, 1fr);
gap: 16px;
max-width: 1280px;
margin: 18px auto 60px;
padding: 0 20px
}
@media (max-width:980px) {
.layout {
grid-template-columns: 1fr
}
}
.card {
background: var(--card);
border: 1px solid var(--line);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 16px
}
.card+.card {
margin-top: 16px
}
.card-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px
}
label {
display: block;
font-size: 12px;
color: var(--muted);
margin: 10px 0 5px
}
input,
select,
textarea {
width: 100%;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: #fff;
color: var(--ink);
font: inherit;
outline: none;
transition: .15s;
}
input:focus,
select:focus,
textarea:focus {
border-color: #a5b4fc;
box-shadow: 0 0 0 3px rgba(99, 102, 241, .14)
}
textarea {
resize: vertical;
min-height: 74px
}
.row {
display: flex;
gap: 8px
}
.row>* {
min-width: 0
}
.btn {
background: var(--brand);
color: #fff;
padding: 9px 14px;
font-weight: 600
}
.btn:hover {
background: #4338ca
}
.btn.ghost {
background: #fff;
color: var(--ink);
border-color: var(--line)
}
.btn.ghost:hover {
background: #f9fafb
}
.btn.small {
padding: 5px 10px;
font-size: 12px
}
.btn.ok {
background: var(--ok)
}
.btn.ok:hover {
background: #027a48
}
.btn.warn {
background: var(--warn)
}
.btn.warn:hover {
background: #b54708
}
.btn.err {
background: var(--err)
}
.btn.err:hover {
background: #b42318
}
.badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 3px 9px;
border-radius: 999px;
font-size: 12px;
font-weight: 600;
background: var(--brand-weak);
color: var(--brand)
}
.badge.ok {
background: var(--ok-weak);
color: var(--ok)
}
.badge.warn {
background: var(--warn-weak);
color: var(--warn)
}
.badge.err {
background: var(--err-weak);
color: var(--err)
}
.badge.mute {
background: #f2f4f7;
color: var(--muted)
}
.item-row {
display: grid;
grid-template-columns: 96px 1fr 1fr 30px;
gap: 6px;
margin-bottom: 6px
}
.item-row button {
background: #fff;
border: 1px solid var(--line);
color: var(--muted);
border-radius: 9px
}
.hint {
color: var(--muted);
font-size: 12px
}
.list {
display: flex;
flex-direction: column;
gap: 8px;
max-height: 300px;
overflow: auto
}
.claim {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 12px;
cursor: pointer;
background: #fff;
}
.claim:hover {
border-color: #c7d2fe;
background: #fbfbff
}
.claim.active {
border-color: var(--brand);
box-shadow: 0 0 0 3px rgba(99, 102, 241, .12)
}
.claim .cid {
font-weight: 650;
font-size: 13px
}
.claim .sub {
color: var(--muted);
font-size: 12px
}
.detail-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px
}
.detail-grid {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
gap: 14px
}
@media (max-width:760px) {
.detail-grid {
grid-template-columns: 1fr
}
}
.box {
border: 1px solid var(--line);
border-radius: 12px;
padding: 12px;
background: #fcfcfd
}
.draft {
white-space: pre-wrap;
word-break: break-word;
min-height: 70px
}
.audit {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: 6px;
max-height: 280px;
overflow: auto
}
.audit li {
position: relative;
padding-left: 14px;
font-size: 12.5px;
color: #344054
}
.audit li::before {
content: "";
position: absolute;
left: 0;
top: 7px;
width: 6px;
height: 6px;
border-radius: 50%;
background: #a5b4fc
}
.log {
margin: 0;
padding: 10px 12px;
background: #0b1020;
color: #cbd5e1;
border-radius: 12px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
line-height: 1.6;
max-height: 230px;
overflow: auto;
white-space: pre-wrap;
word-break: break-word;
}
.log .t {
color: #93c5fd
}
.hist {
list-style: none;
padding: 0;
margin: 0;
font-family: ui-monospace, Menlo, Consolas, monospace;
font-size: 12px;
color: #475467
}
.hist li {
padding: 4px 0;
border-bottom: 1px dashed var(--line)
}
.hist li:last-child {
border-bottom: 0
}
.drawer {
position: fixed;
inset: 0;
background: rgba(16, 24, 40, .45);
display: grid;
place-items: center;
z-index: 50;
padding: 20px
}
.drawer[hidden] {
display: none
}
.drawer .panel {
background: #fff;
border-radius: 16px;
width: min(900px, 100%);
max-height: 86vh;
overflow: auto;
padding: 18px
}
.diagram {
margin-top: 10px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: #fff;
overflow: auto;
max-height: 62vh;
}
.diagram svg {
max-width: 100%;
height: auto;
display: block;
margin: 0 auto
}
.toast {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 60;
background: #101828;
color: #fff;
padding: 10px 14px;
border-radius: 12px;
box-shadow: 0 12px 30px rgba(16, 24, 40, .3);
font-size: 13px;
}
.toast[hidden] {
display: none
}
.toast.err {
background: #b42318
}
.toast.ok {
background: #027a48
}
.spin {
display: inline-block;
width: 12px;
height: 12px;
border: 2px solid rgba(255, 255, 255, .4);
border-top-color: #fff;
border-radius: 50%;
animation: sp .7s linear infinite;
vertical-align: -2px
}
@keyframes sp {
to {
transform: rotate(360deg)
}
}11.2. index.html #
claim/templates/index.html
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+<title>差旅报销审批台</title>
+<link rel="stylesheet" href="{{ url_for('static', filename='css/app.css') }}">
</head>
<body>
+ <header class="top">
+ <div class="brand">
+ <div class="logo">LG</div>
+ <div>
+ <h1>差旅报销审批台</h1>
+ </div>
+ </div>
+ <div class="top-actions">
+ <span id="modelBadge" class="badge mute">{{ model_name }}</span>
+ <button class="btn ghost small" onclick="toggleGraph()">查看图</button>
+ </div>
+ </header>
+ <main class="layout">
+ <section>
+ <div class="card">
+ <div class="card-head">
+ <h2>新建报销单</h2><button class="btn ghost small" onclick="fillDemo()">填示例</button>
+ </div>
+ <form id="claimForm">
+ <label>员工工号</label>
+ <select id="employee">
+ {% for e in employees %}
+ <option value="{{ e.id }}" {% if e.default %} selected{% endif %}>{{ e.id }} · {{ e.level
+ }}(住宿上限 {{ e.limit }})</option>
+ {% endfor %}
+ </select>
+ <label>报销说明(含手机号会被确定性节点脱敏)</label>
+ <textarea id="note" placeholder="{{ default_note }}">{{ default_note }}</textarea>
+ <label>费用明细</label>
+ <div id="items"></div>
+ <button type="button" class="btn ghost small" onclick="addItem()">+ 添加明细</button>
+ <div style="margin-top:14px; display:flex; gap:8px">
+ <button class="btn" type="submit" style="flex:1">提交并跑流程</button>
+ </div>
+ <p class="hint" style="margin-top:8px">提交后会实时看到 intake → 并行核查 → gate → Agent 起草,然后停在审批。当前护栏:改稿上限 {{
+ max_revisions }} 次,自动通过线 {{ auto_limit }} 元,硬上限 {{ hard_limit }} 元。</p>
+ </form>
+ </div>
+ </section>
+ <section>
+ <div class="card">
+ <div class="card-head">
+ <h2>工单列表</h2><button class="btn ghost small" onclick="refreshClaims()">刷新</button>
+ </div>
+ <div id="claims" class="list"></div>
+ </div>
+ <div class="card" id="detailCard" hidden>
+ <div class="detail-head">
+ <div>
+ <h2 id="dTitle">—</h2>
+ <p class="hint" id="dMeta">—</p>
+ </div>
+ <span id="dStatus" class="badge mute">—</span>
+ </div>
+ <div class="detail-grid">
+ <div>
+ <h3>草稿</h3>
+ <div class="box draft" id="draftBox">—</div>
+ <h3 style="margin-top:12px">风险备注</h3>
+ <div class="box" id="riskNote">—</div>
+ </div>
+ <div>
+ <h3>审计轨迹</h3>
+ <ol class="audit" id="auditList"></ol>
+ </div>
+ </div>
+ <div id="reviewBox" hidden style="margin-top:14px">
+ <h3>人工审批(interrupt 暂停在这里)</h3>
+ <div class="box">
+ <div class="row">
+ <div style="flex:2"><label>审批人</label><input id="approver" value="财务张三"></div>
+ <div style="flex:3"><label>改稿意见(选填)</label><input id="feedback" placeholder="例如:请写明依据的政策条款">
+ </div>
+ </div>
+ <div class="row" style="margin-top:10px">
+ <button class="btn ok" onclick="decide('approve')" style="flex:1">批准付款</button>
+ <button class="btn warn" onclick="decide('revise')" style="flex:1">要求改稿</button>
+ <button class="btn err" onclick="decide('reject')" style="flex:1">驳回</button>
+ </div>
+ <div class="row" style="margin-top:10px">
+ <input id="patchInput" placeholder="补正备注(演示 update_state,不动审批决定)">
+ <button class="btn ghost" onclick="patchNote()">补正</button>
+ </div>
+ </div>
+ </div>
+ <div style="margin-top:14px">
+ <div class="card-head">
+ <h3>实时事件流</h3><span class="hint" id="liveHint"></span>
+ </div>
+ <pre class="log" id="live"></pre>
+ </div>
+ <div style="margin-top:14px">
+ <h3>检查点历史</h3>
+ <ul class="hist" id="histList"></ul>
+ </div>
+ </div>
+ </section>
+ </main>
+ <div class="drawer" id="graphPanel" hidden onclick="if(event.target===this) toggleGraph()">
+ <div class="panel">
+ <div class="card-head">
+ <h2>图的结构(xray=1,子图已展开)</h2>
+ <button class="btn ghost small" onclick="toggleGraph()">关闭</button>
+ </div>
+ <p class="hint" id="guardLine"></p>
+ <div class="diagram" id="diagram">
+ <p class="hint">正在渲染…</p>
+ </div>
+ <pre class="log" id="mermaidText" hidden style="max-height:none"></pre>
+ <p class="hint" id="renderHint" hidden>mermaid 渲染失败,已回退成源码(通常是没联网加载 CDN)。</p>
+ </div>
+ </div>
+ <div class="toast" id="toast" hidden></div>
+ <script src="{{ url_for('static', filename='js/app.js') }}"></script>
</body>
</html>