fix:新增功能并优化
This commit is contained in:
26
admin.js
26
admin.js
@@ -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, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """);
|
||||
}
|
||||
|
||||
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" });
|
||||
|
||||
Reference in New Issue
Block a user