fix:新增功能并优化

This commit is contained in:
Daniel
2026-04-02 11:15:21 +08:00
parent 0304805ce1
commit 8d69c0979c
13 changed files with 1283 additions and 214 deletions

View File

@@ -5,6 +5,15 @@ const codeInput = document.getElementById("code-input");
const saveBtn = document.getElementById("save-btn");
const exampleBtn = document.getElementById("example-btn");
const listEl = document.getElementById("list");
const listCountEl = document.getElementById("list-count");
function esc(s) {
return String(s)
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
}
const EXAMPLE = `void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
@@ -29,19 +38,26 @@ async function fetchList() {
function renderList(items) {
listEl.innerHTML = "";
if (listCountEl) {
listCountEl.textContent = items.length ? `${items.length}` : "";
}
if (!items.length) {
listEl.innerHTML = "<div>暂无数据</div>";
listEl.innerHTML =
'<div class="empty-state">暂无着色器,请在上方创建并保存。</div>';
return;
}
items.forEach((item) => {
const row = document.createElement("div");
row.className = "item";
row.innerHTML = `
<div>
<strong>${item.name}</strong>
<div style="font-size:12px;color:#9fb2df;">${item.author || "unknown"} · ${item.id}</div>
<div class="item-main">
<strong>${esc(item.name)}</strong>
<div class="item-meta">${esc(item.author || "unknown")} · ${esc(item.id)}</div>
</div>
<div class="item-actions">
<a class="btn btn-dl" href="${API_BASE}/${encodeURIComponent(item.id)}/download" download>下载 .glsl</a>
<button type="button" class="btn btn-danger">删除</button>
</div>
<button>删除</button>
`;
row.querySelector("button").addEventListener("click", async () => {
await fetch(`${API_BASE}/${encodeURIComponent(item.id)}`, { method: "DELETE" });