diff --git a/daily_report/static/styles.css b/daily_report/static/styles.css index 6b80c51..f94f648 100644 --- a/daily_report/static/styles.css +++ b/daily_report/static/styles.css @@ -61,10 +61,53 @@ button { gap: 8px; } .item-group h2 { margin: 0; } +.item-group-head { + display: flex; + justify-content: space-between; + gap: 12px; + align-items: center; +} .item-group [data-list] { display: grid; gap: 8px; } +.item-row { + display: grid; + grid-template-columns: 32px minmax(0, 1fr) 36px; + gap: 8px; + align-items: center; +} +.item-index { + color: #5b6472; + text-align: right; +} +.add-item, .remove-item { + width: 36px; + height: 36px; + padding: 0; + display: inline-flex; + align-items: center; + justify-content: center; +} +.add-item { + border: 1px solid #2563eb; + background: #fff; + color: #2563eb; + font-size: 22px; + line-height: 1; +} +.remove-item { + border: 1px solid #e5e7eb; + background: #fff; + color: #6b7280; + font-size: 20px; + line-height: 1; +} +.remove-item:hover { + border-color: #fecaca; + color: #b91c1c; + background: #fef2f2; +} .previous-plan { display: grid; gap: 10px; diff --git a/daily_report/web.py b/daily_report/web.py index 45e3336..8b592fa 100644 --- a/daily_report/web.py +++ b/daily_report/web.py @@ -71,22 +71,18 @@ def submit_page(current_date: str, session: dict[str, str] | None = None) -> byt
-

今日完成

-
- - - - +
+

今日完成

+
+
-

明日计划

-
- - - - +
+

明日计划

+
+
@@ -136,15 +132,47 @@ function collectItems(name) {{ return values.map((value, index) => `${{index + 1}}. ${{value}}`).join("\\n"); }} +function renumberItems(name) {{ + Array.from(document.querySelectorAll(`[data-list="${{name}}"] .item-row`)).forEach((row, index) => {{ + row.querySelector(".item-index").textContent = `${{index + 1}}.`; + row.querySelector("input").placeholder = `第 ${{index + 1}} 条`; + }}); +}} + +function addItem(name, value = "") {{ + const list = document.querySelector(`[data-list="${{name}}"]`); + const row = document.createElement("div"); + row.className = "item-row"; + row.innerHTML = ` + + + + `; + row.querySelector(".remove-item").addEventListener("click", () => {{ + if (list.querySelectorAll(".item-row").length <= 1) {{ + row.querySelector("input").value = ""; + return; + }} + row.remove(); + renumberItems(name); + }}); + list.appendChild(row); + renumberItems(name); +}} + +function resetItems(name, values = []) {{ + const list = document.querySelector(`[data-list="${{name}}"]`); + list.innerHTML = ""; + const items = values.length ? values : ["", "", ""]; + items.forEach((value) => addItem(name, value)); +}} + function fillItemInputs(name, text) {{ - const inputs = Array.from(document.querySelectorAll(`[data-list="${{name}}"] input`)); const lines = String(text || "") .split(/\\n+/) .map((line) => line.replace(/^\\s*\\d+[\\.、)]\\s*/, "").trim()) .filter(Boolean); - inputs.forEach((input, index) => {{ - input.value = lines[index] || ""; - }}); + resetItems(name, lines); }} function renderHistory(data) {{ @@ -205,6 +233,11 @@ async function loadPreviousPlan() {{ document.querySelector("#load-history").addEventListener("click", loadHistory); document.querySelector("#report-date").addEventListener("change", loadPreviousPlan); +document.querySelectorAll("[data-add-list]").forEach((button) => {{ + button.addEventListener("click", () => {{ + addItem(button.dataset.addList); + }}); +}}); document.querySelector("#use-previous-plan").addEventListener("click", () => {{ fillItemInputs("today_done", document.querySelector("#previous-plan-content").textContent); }}); @@ -232,6 +265,8 @@ document.querySelector("#report-form").addEventListener("submit", async (event) }} }}); +resetItems("today_done"); +resetItems("tomorrow_plan"); loadHistory(); loadPreviousPlan(); """, diff --git a/tests/test_web.py b/tests/test_web.py index 1eaf2f1..f2e72b2 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -68,6 +68,8 @@ class WebTest(unittest.TestCase): self.assertIn("每日工作汇报", submit) self.assertIn("今日状态", submit) self.assertIn('data-list="today_done"', submit) + self.assertIn('data-add-list="today_done"', submit) + self.assertIn('resetItems("today_done")', submit) self.assertIn("我的历史日报", submit) db.upsert_employee(