feat(hub): fix archive quotes inline expand and mobile archive layout
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,10 +26,6 @@
|
||||
const elQuoteDate = document.getElementById("archive-quote-date");
|
||||
const elQuoteContent = document.getElementById("archive-quote-content");
|
||||
const elQuoteSubmit = document.getElementById("archive-quote-submit");
|
||||
const elQuoteDetail = document.getElementById("archive-quote-detail");
|
||||
const elQuoteDetailFull = document.getElementById("archive-quote-detail-full");
|
||||
const elQuoteEditBtn = document.getElementById("archive-quote-edit-btn");
|
||||
const elQuoteDelBtn = document.getElementById("archive-quote-del-btn");
|
||||
const elChartSection = document.getElementById("archive-chart-section");
|
||||
const elChartTitle = document.getElementById("archive-chart-title");
|
||||
const elTfTabs = document.getElementById("archive-tf-tabs");
|
||||
@@ -520,24 +516,13 @@
|
||||
}
|
||||
|
||||
function selectQuote(id) {
|
||||
if (editingQuoteId != null && String(id) !== String(editingQuoteId)) {
|
||||
const nextId = String(id);
|
||||
const same = selectedQuoteId != null && String(selectedQuoteId) === nextId;
|
||||
if (editingQuoteId != null && String(editingQuoteId) !== nextId) {
|
||||
resetQuoteForm();
|
||||
}
|
||||
selectedQuoteId = id;
|
||||
selectedQuoteId = same ? null : id;
|
||||
renderQuotes();
|
||||
renderQuoteDetail();
|
||||
}
|
||||
|
||||
function renderQuoteDetail() {
|
||||
if (!elQuoteDetail) return;
|
||||
const q = findQuote(selectedQuoteId);
|
||||
if (!q) {
|
||||
elQuoteDetail.hidden = true;
|
||||
if (elQuoteDetailFull) elQuoteDetailFull.textContent = "";
|
||||
return;
|
||||
}
|
||||
elQuoteDetail.hidden = false;
|
||||
if (elQuoteDetailFull) elQuoteDetailFull.textContent = q.content || "(空)";
|
||||
}
|
||||
|
||||
function renderQuotes() {
|
||||
@@ -547,13 +532,15 @@
|
||||
}
|
||||
if (!quotes.length) {
|
||||
elQuotesList.innerHTML = '<p class="archive-empty">暂无复盘语录,可在上方添加。</p>';
|
||||
if (elQuoteDetail) elQuoteDetail.hidden = true;
|
||||
return;
|
||||
}
|
||||
elQuotesList.innerHTML = quotes
|
||||
.map(function (q) {
|
||||
const selected = String(q.id) === String(selectedQuoteId);
|
||||
return (
|
||||
'<div class="archive-quote-block' +
|
||||
(selected ? " is-open" : "") +
|
||||
'">' +
|
||||
'<button type="button" class="archive-quote-item' +
|
||||
(selected ? " is-selected" : "") +
|
||||
'" data-id="' +
|
||||
@@ -565,7 +552,23 @@
|
||||
'<span class="archive-quote-preview">' +
|
||||
esc(quotePreview(q.content)) +
|
||||
"</span>" +
|
||||
"</button>"
|
||||
(selected ? "" : '<span class="archive-quote-open-hint">查看</span>') +
|
||||
"</button>" +
|
||||
(selected
|
||||
? '<div class="archive-quote-detail">' +
|
||||
'<div class="archive-quote-full">' +
|
||||
esc(q.content || "(空)") +
|
||||
"</div>" +
|
||||
'<div class="archive-quote-actions">' +
|
||||
'<button type="button" class="ghost archive-quote-edit-btn" data-id="' +
|
||||
q.id +
|
||||
'">修改</button>' +
|
||||
'<button type="button" class="archive-del-btn archive-quote-del-btn" data-id="' +
|
||||
q.id +
|
||||
'">删除</button>' +
|
||||
"</div></div>"
|
||||
: "") +
|
||||
"</div>"
|
||||
);
|
||||
})
|
||||
.join("");
|
||||
@@ -575,17 +578,27 @@
|
||||
selectQuote(btn.getAttribute("data-id"));
|
||||
});
|
||||
});
|
||||
renderQuoteDetail();
|
||||
elQuotesList.querySelectorAll(".archive-quote-edit-btn").forEach(function (btn) {
|
||||
btn.addEventListener("click", function (ev) {
|
||||
ev.stopPropagation();
|
||||
selectedQuoteId = btn.getAttribute("data-id");
|
||||
startEditQuote();
|
||||
});
|
||||
});
|
||||
elQuotesList.querySelectorAll(".archive-quote-del-btn").forEach(function (btn) {
|
||||
btn.addEventListener("click", function (ev) {
|
||||
ev.stopPropagation();
|
||||
void deleteQuote(btn.getAttribute("data-id"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function loadQuotes() {
|
||||
const r = await apiFetch("/api/archive/quotes");
|
||||
const j = await r.json();
|
||||
quotes = j.quotes || [];
|
||||
if (!quotes.length) {
|
||||
if (!findQuote(selectedQuoteId)) {
|
||||
selectedQuoteId = null;
|
||||
} else if (!findQuote(selectedQuoteId)) {
|
||||
selectedQuoteId = quotes[0].id;
|
||||
}
|
||||
renderQuotes();
|
||||
}
|
||||
@@ -610,8 +623,7 @@
|
||||
return;
|
||||
}
|
||||
resetQuoteForm();
|
||||
selectedQuoteId =
|
||||
j.quote && j.quote.id != null ? j.quote.id : selectedQuoteId;
|
||||
selectedQuoteId = null;
|
||||
await loadQuotes();
|
||||
setStatus("语录已添加");
|
||||
}
|
||||
@@ -627,9 +639,8 @@
|
||||
setStatus(j.detail || "保存失败");
|
||||
return;
|
||||
}
|
||||
const savedId = id;
|
||||
resetQuoteForm();
|
||||
selectedQuoteId = savedId;
|
||||
selectedQuoteId = null;
|
||||
await loadQuotes();
|
||||
setStatus("语录已保存");
|
||||
}
|
||||
@@ -1382,13 +1393,6 @@
|
||||
});
|
||||
}
|
||||
if (elQuoteForm) elQuoteForm.addEventListener("submit", submitQuoteForm);
|
||||
if (elQuoteEditBtn) elQuoteEditBtn.addEventListener("click", startEditQuote);
|
||||
if (elQuoteDelBtn) {
|
||||
elQuoteDelBtn.addEventListener("click", function () {
|
||||
if (!selectedQuoteId) return;
|
||||
void deleteQuote(selectedQuoteId);
|
||||
});
|
||||
}
|
||||
if (elTfTabs) {
|
||||
elTfTabs.addEventListener("click", function (ev) {
|
||||
const btn = ev.target.closest(".archive-tf-btn");
|
||||
|
||||
Reference in New Issue
Block a user