跳到内容
栏目
语言,当前是简体中文
Rastrillo 设计系统

路由

这些片段本身就是一整个响应,而不是响应里的一块。

每个示例都能真实操作,但其中的链接不会跳转到任何地方。 HTML 显示可复制的标记。

error-page

错误响应的整个主体:状态码、一句实话、一条回头的路,以及管理员用得上的 500 参考编号。

404:找不到

预览
<div rst-error>
  <p rst-error-status>404</p>
  <h1 rst-error-title>找不到该页面</h1>
  <p rst-error-body>链接可能已过期,或者页面已移动。请检查网址,或回到起始页面。</p>
  <p rst-error-cta>
    <a rst-btn="primary" href="/">起始页面</a>
  </p>
</div>
{{template "error-page" dict "Status" 404 "HomeHref" "/"}}

403:无权限

预览
<div rst-error>
  <p rst-error-status>403</p>
  <h1 rst-error-title>你没有权限查看这个页面</h1>
  <p rst-error-body>你的账户在这里没有访问权限。如果你认为应该有,请联系管理这个网站的人。</p>
  <p rst-error-cta>
    <a rst-btn="primary" href="/">起始页面</a>
    <a rst-btn href="/posts">返回</a>
  </p>
</div>
{{template "error-page" dict "Status" 403 "HomeHref" "/" "BackHref" "/posts"}}

422:无法处理

预览
<div rst-error>
  <p rst-error-status>422</p>
  <h1 rst-error-title>提交未成功</h1>
  <p rst-error-body>发送的内容中有些地方不正确。请返回重试;没有保存任何内容。</p>
  <p rst-error-cta>
    <a rst-btn="primary" href="/">起始页面</a>
    <a rst-btn href="/posts/1/edit">返回</a>
  </p>
</div>
{{template "error-page" dict
    "Status" 422
    "HomeHref" "/"
    "BackHref" "/posts/1/edit"}}

500:服务器错误

预览
<div rst-error>
  <p rst-error-status>500</p>
  <h1 rst-error-title>我们这边出了问题</h1>
  <p rst-error-body>这不是你的问题。问题已记录。请稍后重试;如果一直发生,请提供下方的参考编号。</p>
  <p rst-error-cta>
    <a rst-btn="primary" href="/">起始页面</a>
  </p>
  <p class="rst-mono" rst-error-ref dir="auto">参考编号:k3f9tq</p>
</div>
{{template "error-page" dict "Status" 500 "HomeHref" "/" "Ref" "k3f9tq"}}

500 是唯一带参考编号的状态:运维人员可以用它在日志里 grep。

503:暂时不可用

预览
<div rst-error>
  <p rst-error-status>503</p>
  <h1 rst-error-title>我们暂时无法提供服务</h1>
  <p rst-error-body>网站正在更新或者比较繁忙。请过一分钟再试。</p>
  <p rst-error-cta>
    <a rst-btn="primary" href="/">起始页面</a>
  </p>
</div>
{{template "error-page" dict "Status" 503 "HomeHref" "/"}}

其他任何情况:通用的一对

预览
<div rst-error>
  <p rst-error-status>418</p>
  <h1 rst-error-title>有些地方不对</h1>
  <p rst-error-body>该请求无法完成。请返回重试。</p>
  <p rst-error-cta>
    <a rst-btn="primary" href="/">起始页面</a>
  </p>
</div>
{{template "error-page" dict "Status" 418 "HomeHref" "/"}}

框架目录里写了五种状态的措辞。第六种会回退到通用的一对,而不是把一个缺失的键名摆到读者眼前。

back-nav

往上一级的返回链接,放在详情页或编辑页的上方。

返回一条记录

预览
<nav rst-back-nav>
  <a href="/orders/1">← 订单 AB3PX</a>
</nav>
{{template "back-nav" dict "Href" "/orders/1" "Label" "订单 AB3PX"}}

locale-menu

语言切换器:一个 details 菜单,里面是发往 /_locale 的单字段 POST 表单,这样选择会落进 locale cookie,而读者仍留在同一个路径上。

十二种语言,当前的一种被标出。

预览
<details rst-dropdown rst-locale name="rst-menus">
  <summary>
    语言
    <span rst-caret aria-hidden="true">
      <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg>
    </span>
  </summary>
  <div rst-dropdown-menu>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="en">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="en">English</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="ga">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="ga">Gaeilge</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="zh-Hans">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="zh-Hans" aria-current="true">简体中文</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="es">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="es">Español</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="hi">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="hi">हिन्दी</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="pt-PT">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="pt-PT">Português</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="bn">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="bn">বাংলা</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="ru">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="ru">Русский</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="ja">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="ja">日本語</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="yue">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="yue">廣東話</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="vi">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="vi">Tiếng Việt</button>
    </form>
    <form method="post" action="/_locale">
      <input type="hidden" name="locale" value="ar">
      <input type="hidden" name="return" value="/">
      <button type="submit" lang="ar">العربية</button>
    </form>
  </div>
</details>
{{template "locale-menu" dict "Items" .Locales "Return" "/"}}

这一个会 POST 到 /_locale,所以需要服务器。它的 Items 来自 rastrillo.LocaleItems(r)。本页页眉里的切换器是纯链接的版本。

scheme-menu

配色方案切换器:一个 details 菜单,由指向 /_theme 的单字段 POST 表单组成,分别是浅色、深色和跟随系统,这样选择会存入配色 cookie,读者仍停留在同一页面。

三个选项,当前为深色。

预览
<details rst-dropdown rst-scheme name="rst-menus">
  <summary>
    配色方案
    <span rst-caret aria-hidden="true">
      <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg>
    </span>
  </summary>
  <div rst-dropdown-menu role="group" aria-label="配色方案">
    <form method="post" action="/_theme">
      <input type="hidden" name="scheme" value="light">
      <input type="hidden" name="return" value="/">
      <button type="submit">浅色</button>
    </form>
    <form method="post" action="/_theme">
      <input type="hidden" name="scheme" value="dark">
      <input type="hidden" name="return" value="/">
      <button type="submit" aria-current="true">深色</button>
    </form>
    <form method="post" action="/_theme">
      <input type="hidden" name="scheme" value="system">
      <input type="hidden" name="return" value="/">
      <button type="submit">跟随系统</button>
    </form>
  </div>
</details>
{{template "scheme-menu" dict "Scheme" "dark" "Return" "/"}}

这一个会 POST 到 /_theme,所以需要服务器。它的 Scheme 来自 rastrillo.SchemeFrom(r),由 ui.ForRequest 携带。本页顶栏里的切换器是画廊自己的。

api-tokens

来自 apitoken 的 PageData 的令牌页面:一次性显示、创建表单、列表和撤销按钮。

四个令牌,其中两个有效

预览
<div rst-tokens>
  <section rst-box>
    <form rst-form method="post" action="/tokens">
      <div rst-field>
        <label rst-field-label for="agent">代理名称</label>
        <input rst-input type="text" id="agent" name="agent" maxlength="40">
      </div>
      <label rst-switch>
        <input type="checkbox" name="for_self" value="on">
        <span rst-switch-track aria-hidden="true"></span>
        这个令牌是给我自己的,不是给代理的
      </label>
      <fieldset rst-choice>
        <legend>权限</legend>
        <div rst-choice-cards>
          <label>
            <input type="radio" name="access" value="write" checked>
            <span>
              <span rst-choice-title>读写</span>
            </span>
          </label>
          <label>
            <input type="radio" name="access" value="read">
            <span>
              <span rst-choice-title>只读</span>
            </span>
          </label>
        </div>
      </fieldset>
      <div rst-field>
        <label rst-field-label for="expiry">有效期至</label>
        <select rst-input="short" id="expiry" name="expiry">
          <option value="30">30 天</option>
          <option value="90" selected>90 天</option>
          <option value="365">1 年</option>
          <option value="never">永不</option>
        </select>
      </div>
      <div rst-form-foot>
        <button rst-btn="primary lg" type="submit">创建令牌</button>
      </div>
    </form>
  </section>
  <div rst-card rst-tokens-list>
    <div rst-lrow="head">
      <span>令牌</span>
      <span class="rst-m-hide">权限</span>
      <span class="rst-m-hide">创建时间</span>
      <span class="rst-m-hide">上次使用</span>
      <span class="rst-m-hide">有效期至</span>
      <span></span>
      <span></span>
    </div>
    <div rst-lrow>
      <span class="rst-nm"><span rst-actor>Claude(代表 Grace Hopper)</span>
        <small>
          <code>k3Jx9QpL2mWa</code>
        </small>
      </span>
      <span rst-tokens-fact><span rst-tokens-fact-label>权限</span>读写</span>
      <span rst-tokens-fact><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>上次使用</span><time datetime="2026-08-11">2026-08-11</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>有效期至</span><time datetime="2026-10-31">2026-10-31</time></span>
      <span rst-tokens-state></span>
      <details rst-row-menu name="rst-menus">
        <summary aria-label="Claude(代表 Grace Hopper) 的操作">
          <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
        </summary>
        <div rst-row-menu-panel>
          <form method="post" action="/tokens/revoke">
            <input type="hidden" name="id" value="k3Jx9QpL2mWa">
            <button type="submit">撤销</button>
          </form>
        </div>
      </details>
    </div>
    <div rst-lrow>
      <span class="rst-nm"><span rst-actor>Grace Hopper</span>
        <small>
          <code>Qm2vR8sT4xYb</code>
        </small>
      </span>
      <span rst-tokens-fact><span rst-tokens-fact-label>权限</span>只读</span>
      <span rst-tokens-fact><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>有效期至</span>永不</span>
      <span rst-tokens-state></span>
      <details rst-row-menu name="rst-menus">
        <summary aria-label="Grace Hopper 的操作">
          <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
        </summary>
        <div rst-row-menu-panel>
          <form method="post" action="/tokens/revoke">
            <input type="hidden" name="id" value="Qm2vR8sT4xYb">
            <button type="submit">撤销</button>
          </form>
        </div>
      </details>
    </div>
    <div rst-lrow>
      <span class="rst-nm"><span rst-actor>Codex(代表 Grace Hopper)</span>
        <small>
          <code>Zp7wN1cH6kLd</code>
        </small>
      </span>
      <span rst-tokens-fact><span rst-tokens-fact-label>权限</span>读写</span>
      <span rst-tokens-fact><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>有效期至</span>永不</span>
      <span rst-tokens-state><span rst-status rst-tone="neutral">已撤销</span></span>
    </div>
    <div rst-lrow>
      <span class="rst-nm"><span rst-actor>Nightly import(代表 Grace Hopper)</span>
        <small>
          <code>Vb4tG9yK3nMe</code>
        </small>
      </span>
      <span rst-tokens-fact><span rst-tokens-fact-label>权限</span>只读</span>
      <span rst-tokens-fact><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>有效期至</span><time datetime="2026-08-11">2026-08-11</time></span>
      <span rst-tokens-state><span rst-status rst-tone="warning">已过期</span></span>
    </div>
  </div>
  <div rst-tokens-revoke>
    <form method="post" action="/tokens/revoke-agent">
      <input type="hidden" name="agent" value="Claude">
      <button rst-btn type="submit">撤销这个代理的全部令牌: Claude</button>
    </form>
    <form method="post" action="/tokens/revoke-all">
      <button rst-btn="danger" type="submit">撤销全部令牌</button>
    </form>
  </div>
</div>
{{template "api-tokens" dict "Page" .Page "Path" "/tokens"}}

把 Handlers 交给 Render 的内容作为 Page 传入,并把页面自己的路径作为 Path 传入。撤销表单提交到 Path/revoke、Path/revoke-agent 和 Path/revoke-all;要改其中一个,设置 RevokePath、RevokeAgentPath 或 RevokeAllPath。

刚创建:秘密只显示一次

预览
<div rst-tokens>
  <div rst-callout rst-tone="positive" tabindex="-1" autofocus>
    <span rst-callout-ic aria-hidden="true">
      <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>
    </span>
    <div rst-callout-body>
      <strong>现在就复制这个令牌。它不会再显示。</strong>
      <p>
        <code rst-tokens-secret>harbour_k3Jx9QpL2mWa_6bD2qK9xWz4rT8vN1mP3sL7yF5hJ0cG2aE4uB</code>
      </p>
    </div>
  </div>
  <section rst-box>
    <form rst-form method="post" action="/tokens">
      <div rst-field>
        <label rst-field-label for="agent">代理名称</label>
        <input rst-input type="text" id="agent" name="agent" maxlength="40">
      </div>
      <label rst-switch>
        <input type="checkbox" name="for_self" value="on">
        <span rst-switch-track aria-hidden="true"></span>
        这个令牌是给我自己的,不是给代理的
      </label>
      <fieldset rst-choice>
        <legend>权限</legend>
        <div rst-choice-cards>
          <label>
            <input type="radio" name="access" value="write" checked>
            <span>
              <span rst-choice-title>读写</span>
            </span>
          </label>
          <label>
            <input type="radio" name="access" value="read">
            <span>
              <span rst-choice-title>只读</span>
            </span>
          </label>
        </div>
      </fieldset>
      <div rst-field>
        <label rst-field-label for="expiry">有效期至</label>
        <select rst-input="short" id="expiry" name="expiry">
          <option value="30">30 天</option>
          <option value="90" selected>90 天</option>
          <option value="365">1 年</option>
          <option value="never">永不</option>
        </select>
      </div>
      <div rst-form-foot>
        <button rst-btn="primary lg" type="submit">创建令牌</button>
      </div>
    </form>
  </section>
  <div rst-card rst-tokens-list>
    <div rst-lrow="head">
      <span>令牌</span>
      <span class="rst-m-hide">权限</span>
      <span class="rst-m-hide">创建时间</span>
      <span class="rst-m-hide">上次使用</span>
      <span class="rst-m-hide">有效期至</span>
      <span></span>
      <span></span>
    </div>
    <div rst-lrow>
      <span class="rst-nm"><span rst-actor>Claude(代表 Grace Hopper)</span>
        <small>
          <code>k3Jx9QpL2mWa</code>
        </small>
      </span>
      <span rst-tokens-fact><span rst-tokens-fact-label>权限</span>读写</span>
      <span rst-tokens-fact><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>上次使用</span><time datetime="2026-08-11">2026-08-11</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>有效期至</span><time datetime="2026-10-31">2026-10-31</time></span>
      <span rst-tokens-state></span>
      <details rst-row-menu name="rst-menus">
        <summary aria-label="Claude(代表 Grace Hopper) 的操作">
          <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
        </summary>
        <div rst-row-menu-panel>
          <form method="post" action="/tokens/revoke">
            <input type="hidden" name="id" value="k3Jx9QpL2mWa">
            <button type="submit">撤销</button>
          </form>
        </div>
      </details>
    </div>
    <div rst-lrow>
      <span class="rst-nm"><span rst-actor>Grace Hopper</span>
        <small>
          <code>Qm2vR8sT4xYb</code>
        </small>
      </span>
      <span rst-tokens-fact><span rst-tokens-fact-label>权限</span>只读</span>
      <span rst-tokens-fact><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>有效期至</span>永不</span>
      <span rst-tokens-state></span>
      <details rst-row-menu name="rst-menus">
        <summary aria-label="Grace Hopper 的操作">
          <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
        </summary>
        <div rst-row-menu-panel>
          <form method="post" action="/tokens/revoke">
            <input type="hidden" name="id" value="Qm2vR8sT4xYb">
            <button type="submit">撤销</button>
          </form>
        </div>
      </details>
    </div>
    <div rst-lrow>
      <span class="rst-nm"><span rst-actor>Codex(代表 Grace Hopper)</span>
        <small>
          <code>Zp7wN1cH6kLd</code>
        </small>
      </span>
      <span rst-tokens-fact><span rst-tokens-fact-label>权限</span>读写</span>
      <span rst-tokens-fact><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>有效期至</span>永不</span>
      <span rst-tokens-state><span rst-status rst-tone="neutral">已撤销</span></span>
    </div>
    <div rst-lrow>
      <span class="rst-nm"><span rst-actor>Nightly import(代表 Grace Hopper)</span>
        <small>
          <code>Vb4tG9yK3nMe</code>
        </small>
      </span>
      <span rst-tokens-fact><span rst-tokens-fact-label>权限</span>只读</span>
      <span rst-tokens-fact><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact><span rst-tokens-fact-label>有效期至</span><time datetime="2026-08-11">2026-08-11</time></span>
      <span rst-tokens-state><span rst-status rst-tone="warning">已过期</span></span>
    </div>
  </div>
  <div rst-tokens-revoke>
    <form method="post" action="/tokens/revoke-agent">
      <input type="hidden" name="agent" value="Claude">
      <button rst-btn type="submit">撤销这个代理的全部令牌: Claude</button>
    </form>
    <form method="post" action="/tokens/revoke-all">
      <button rst-btn="danger" type="submit">撤销全部令牌</button>
    </form>
  </div>
</div>
{{template "api-tokens" dict "Page" .Page "Path" "/tokens"}}

渲染创建表单的响应时要带上 Created,并且不要重定向:秘密只在那个响应里,别处没有。

还没有令牌

预览
<div rst-tokens>
  <section rst-box>
    <form rst-form method="post" action="/tokens">
      <div rst-field>
        <label rst-field-label for="agent">代理名称</label>
        <input rst-input type="text" id="agent" name="agent" maxlength="40">
      </div>
      <label rst-switch>
        <input type="checkbox" name="for_self" value="on">
        <span rst-switch-track aria-hidden="true"></span>
        这个令牌是给我自己的,不是给代理的
      </label>
      <fieldset rst-choice>
        <legend>权限</legend>
        <div rst-choice-cards>
          <label>
            <input type="radio" name="access" value="write" checked>
            <span>
              <span rst-choice-title>读写</span>
            </span>
          </label>
          <label>
            <input type="radio" name="access" value="read">
            <span>
              <span rst-choice-title>只读</span>
            </span>
          </label>
        </div>
      </fieldset>
      <div rst-field>
        <label rst-field-label for="expiry">有效期至</label>
        <select rst-input="short" id="expiry" name="expiry">
          <option value="30">30 天</option>
          <option value="90" selected>90 天</option>
          <option value="365">1 年</option>
          <option value="never">永不</option>
        </select>
      </div>
      <div rst-form-foot>
        <button rst-btn="primary lg" type="submit">创建令牌</button>
      </div>
    </form>
  </section>
  <div rst-empty>
    <p rst-empty-body>还没有令牌。</p>
  </div>
</div>
{{template "api-tokens" dict "Page" .Page "Path" "/tokens"}}