feat(backend): implement task creation and admin web

This commit is contained in:
QiuSW
2026-07-26 14:03:32 +08:00
parent 2b265c92fc
commit c5d3b215ff
58 changed files with 8773 additions and 83 deletions
@@ -0,0 +1,863 @@
* {
box-sizing: border-box;
}
:root {
color-scheme: light;
--canvas: #f3f5f4;
--surface: #ffffff;
--surface-soft: #f8faf9;
--ink: #18201d;
--muted: #5b6862;
--line: #cfd7d3;
--line-strong: #9eaaa4;
--brand: #0b6b50;
--brand-dark: #07513d;
--danger: #9b3030;
--danger-dark: #762222;
--danger-soft: #fff1f1;
--info: #185b8f;
--info-soft: #eef7fd;
--warn: #76520d;
--warn-soft: #fff8e5;
--success: #07513d;
--success-soft: #eaf7f1;
--focus: #1a73b8;
}
html {
min-width: 280px;
}
body {
margin: 0;
min-width: 280px;
color: var(--ink);
background: var(--canvas);
font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
letter-spacing: 0;
}
button,
input,
select,
textarea {
font: inherit;
}
button,
input,
select {
min-height: 44px;
}
a,
button,
input,
select,
textarea,
summary {
outline-offset: 2px;
}
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
outline: 3px solid rgba(26, 115, 184, 0.3);
}
a {
color: var(--brand-dark);
}
.skip-link {
position: fixed;
top: 8px;
left: 8px;
z-index: 100;
padding: 8px 12px;
color: #fff;
background: #18201d;
transform: translateY(-150%);
}
.skip-link:focus {
transform: translateY(0);
}
.site-header {
min-height: 60px;
display: flex;
align-items: center;
gap: 28px;
padding: 0 clamp(16px, 4vw, 40px);
border-bottom: 1px solid var(--line);
background: var(--surface);
}
.brand {
display: inline-flex;
min-height: 44px;
align-items: center;
gap: 10px;
color: var(--ink);
text-decoration: none;
font-size: 16px;
font-weight: 750;
white-space: nowrap;
}
.brand-mark {
width: 28px;
height: 28px;
display: grid;
flex: 0 0 auto;
place-items: center;
border-radius: 5px;
color: #fff;
background: var(--brand);
font-size: 13px;
}
.main-nav {
align-self: stretch;
display: flex;
gap: 4px;
}
.main-nav a {
min-height: 44px;
display: grid;
place-items: center;
padding: 0 13px;
border-bottom: 3px solid transparent;
color: #3d4b45;
text-decoration: none;
}
.main-nav a[aria-current="page"] {
border-color: var(--brand);
color: var(--brand-dark);
font-weight: 700;
}
.page {
width: min(calc(100% - 32px), 1180px);
margin: 0 auto;
padding: 28px 0 60px;
}
.narrow-page {
max-width: 720px;
}
.title-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
margin-bottom: 20px;
}
h1,
h2,
p {
overflow-wrap: anywhere;
}
h1 {
margin: 0;
font-size: 26px;
line-height: 1.3;
}
h2 {
margin: 0 0 8px;
font-size: 18px;
line-height: 1.35;
}
.subtitle,
.section-note,
.secondary,
.field-help {
color: var(--muted);
}
.subtitle {
margin: 4px 0 0;
}
.button {
min-height: 44px;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 8px 14px;
border: 1px solid var(--line-strong);
border-radius: 5px;
color: #26352f;
background: var(--surface);
cursor: pointer;
text-decoration: none;
font-weight: 650;
}
.button:hover {
border-color: #68766f;
background: var(--surface-soft);
}
.button:disabled {
cursor: wait;
opacity: 0.68;
}
.button.primary {
border-color: var(--brand);
color: #fff;
background: var(--brand);
}
.button.primary:hover {
background: var(--brand-dark);
}
.button.danger {
border-color: var(--danger);
color: #fff;
background: var(--danger);
}
.button.danger:hover {
background: var(--danger-dark);
}
.button.danger-outline {
border-color: #c78484;
color: var(--danger-dark);
}
.filters {
display: grid;
grid-template-columns: minmax(200px, 1fr) 220px auto;
align-items: end;
gap: 12px;
padding: 16px;
border: 1px solid var(--line);
border-bottom: 0;
border-radius: 8px 8px 0 0;
background: var(--surface);
}
.filter-button {
min-width: 112px;
}
.field label {
display: block;
margin-bottom: 6px;
font-weight: 700;
}
.field.compact label {
color: #45534d;
font-size: 13px;
}
input,
select,
textarea {
width: 100%;
padding: 9px 11px;
border: 1px solid var(--line-strong);
border-radius: 5px;
color: var(--ink);
background: var(--surface);
}
textarea {
min-height: 112px;
resize: vertical;
}
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
border-color: var(--danger);
box-shadow: inset 0 0 0 1px var(--danger);
}
.table-region {
border: 1px solid var(--line);
border-radius: 0 0 8px 8px;
background: var(--surface);
overflow: hidden;
}
table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
th,
td {
padding: 13px 12px;
border-bottom: 1px solid #e1e6e3;
text-align: left;
vertical-align: middle;
overflow-wrap: anywhere;
}
th {
color: #45534d;
background: var(--surface-soft);
font-size: 13px;
font-weight: 700;
}
th:first-child {
width: 32%;
}
th:nth-child(2) {
width: 16%;
}
th:nth-child(3) {
width: 16%;
}
th:nth-child(4) {
width: 22%;
}
th:last-child {
width: 14%;
}
tbody tr:hover {
background: #f8fbfa;
}
tbody tr:last-child td {
border-bottom: 0;
}
.task-title,
.secondary {
display: block;
}
.task-title {
margin-bottom: 2px;
}
.secondary {
font-size: 12px;
}
.status {
min-height: 28px;
display: inline-flex;
align-items: center;
padding: 3px 8px;
border: 1px solid var(--line-strong);
border-radius: 5px;
background: var(--surface-soft);
font-size: 12px;
font-weight: 700;
}
.status-warn {
border-color: #d6b970;
color: var(--warn);
background: var(--warn-soft);
}
.status-info {
border-color: #8eb7d4;
color: var(--info);
background: var(--info-soft);
}
.status-success {
border-color: #7db6a3;
color: var(--success);
background: var(--success-soft);
}
.status-danger {
border-color: #d99c9c;
color: var(--danger-dark);
background: var(--danger-soft);
}
.detail-link {
min-height: 44px;
display: inline-flex;
align-items: center;
font-weight: 700;
}
.empty-state {
min-height: 260px;
display: grid;
place-items: center;
align-content: center;
padding: 36px 20px;
text-align: center;
}
.empty-state p {
margin: 0 0 18px;
color: var(--muted);
}
.pagination {
display: flex;
justify-content: flex-end;
margin-top: 16px;
}
.notice {
margin: 0 0 18px;
padding: 12px 14px;
border-left: 4px solid var(--info);
background: var(--info-soft);
}
.notice p {
margin: 0;
}
.notice p + p {
margin-top: 5px;
}
.notice-error {
border-color: var(--danger);
color: var(--danger-dark);
background: var(--danger-soft);
}
.task-form {
display: grid;
gap: 18px;
}
.form-section,
.content-section {
padding: 22px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--surface);
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 15px 18px;
}
.span-2 {
grid-column: 1 / -1;
}
.required-text {
color: var(--danger-dark);
font-size: 12px;
}
.field-help,
.field-error {
min-height: 20px;
margin: 4px 0 0;
font-size: 13px;
}
.field-error {
color: var(--danger-dark);
}
.upload-layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 240px;
gap: 22px;
align-items: start;
}
.image-preview {
margin: 0;
}
.image-placeholder,
.image-preview img {
width: 100%;
aspect-ratio: 4 / 3;
border: 1px dashed var(--line-strong);
border-radius: 5px;
background: var(--surface-soft);
}
.image-placeholder {
display: grid;
place-items: center;
padding: 16px;
color: var(--muted);
text-align: center;
}
.image-preview img {
display: block;
object-fit: contain;
}
.image-preview figcaption {
margin-top: 6px;
color: var(--muted);
font-size: 12px;
overflow-wrap: anywhere;
}
.retained-file {
margin: 0;
padding: 10px 12px;
border: 1px solid #7db6a3;
border-radius: 5px;
background: var(--success-soft);
overflow-wrap: anywhere;
}
.form-actions {
display: flex;
justify-content: flex-end;
gap: 10px;
}
.back-link {
min-height: 44px;
display: inline-flex;
align-items: center;
margin-bottom: 10px;
font-weight: 700;
}
.detail-title {
align-items: flex-start;
}
.title-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 10px;
}
.success-banner {
display: flex;
gap: 13px;
align-items: center;
margin-bottom: 18px;
padding: 16px 18px;
border-left: 5px solid var(--success);
background: var(--success-soft);
}
.success-banner h2,
.success-banner p {
margin: 0;
}
.success-mark {
width: 34px;
height: 34px;
display: grid;
flex: 0 0 auto;
place-items: center;
border-radius: 50%;
color: #fff;
background: var(--success);
font-weight: 800;
}
.detail-layout {
display: grid;
grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
gap: 18px;
align-items: start;
}
.section-note {
margin: 0 0 16px;
}
.requirement-layout {
display: grid;
grid-template-columns: minmax(170px, 220px) minmax(0, 1fr);
gap: 20px;
}
.reference-figure {
margin: 0;
}
.reference-image {
width: 100%;
aspect-ratio: 4 / 3;
display: block;
object-fit: contain;
border: 1px solid var(--line-strong);
border-radius: 5px;
background: var(--surface-soft);
}
.reference-figure figcaption {
margin-top: 6px;
color: var(--muted);
font-size: 12px;
text-align: center;
}
.definition-list {
display: grid;
grid-template-columns: minmax(100px, auto) minmax(0, 1fr);
gap: 10px 16px;
margin: 0;
}
.definition-list dt {
color: var(--muted);
font-weight: 650;
}
.definition-list dd {
margin: 0;
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.error-page {
margin-top: 50px;
padding: 28px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--surface);
}
.error-page p {
margin: 8px 0 22px;
color: var(--muted);
}
.confirm-dialog {
width: min(calc(100% - 32px), 480px);
padding: 22px;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--ink);
background: var(--surface);
}
.confirm-dialog::backdrop {
background: rgba(24, 32, 29, 0.45);
}
.confirm-dialog p {
color: var(--muted);
}
.dialog-actions {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 20px;
}
.dialog-actions form {
margin: 0;
}
.noscript-cancel {
margin-top: 18px;
padding: 18px;
border: 1px solid #d99c9c;
background: var(--danger-soft);
}
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
[aria-busy="true"] {
cursor: wait;
}
@media (max-width: 760px) {
.page {
width: min(calc(100% - 20px), 1180px);
padding-top: 20px;
}
.filters {
grid-template-columns: minmax(0, 1fr) minmax(160px, 0.6fr);
}
.filter-button {
grid-column: 1 / -1;
}
table,
tbody {
display: block;
}
thead {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
}
tr {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
padding: 12px;
border-bottom: 1px solid var(--line);
}
tbody tr:last-child {
border-bottom: 0;
}
td {
display: block;
padding: 6px;
border: 0;
}
td::before {
content: attr(data-label);
display: block;
margin-bottom: 2px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
td:first-child,
td:last-child {
grid-column: 1 / -1;
}
.upload-layout,
.detail-layout,
.requirement-layout {
grid-template-columns: 1fr;
}
.image-preview {
max-width: 320px;
}
}
@media (max-width: 520px) {
.site-header {
gap: 8px;
padding-inline: 10px;
}
.brand {
font-size: 14px;
}
.brand-mark {
display: none;
}
.main-nav {
margin-left: auto;
}
.main-nav a {
padding-inline: 8px;
font-size: 13px;
}
.title-row,
.detail-title {
align-items: stretch;
flex-direction: column;
}
.title-row > .button {
width: 100%;
}
.title-actions {
justify-content: flex-start;
flex-wrap: wrap;
}
.filters,
.form-grid {
grid-template-columns: 1fr;
}
.filter-button,
.span-2 {
grid-column: auto;
}
tr {
grid-template-columns: 1fr;
}
td,
td:first-child,
td:last-child {
grid-column: auto;
}
.form-section,
.content-section {
padding: 18px 14px;
}
.form-actions,
.dialog-actions {
flex-direction: column-reverse;
}
.form-actions .button,
.dialog-actions .button,
.dialog-actions form {
width: 100%;
}
.dialog-actions form .button {
width: 100%;
}
.definition-list {
grid-template-columns: 1fr;
gap: 3px;
}
.definition-list dd {
margin-bottom: 10px;
}
}
@@ -0,0 +1,109 @@
(() => {
"use strict";
const focusError = document.querySelector("[data-error-field]");
if (focusError) {
focusError.focus();
} else {
const summary = document.querySelector("[data-error-summary]");
if (summary) summary.focus();
}
document.querySelectorAll("[data-loading-form]").forEach((form) => {
form.addEventListener("submit", () => {
form.setAttribute("aria-busy", "true");
const button = form.querySelector("button[type='submit']");
if (!button) return;
button.disabled = true;
button.textContent = button.dataset.loadingLabel || "正在加载…";
});
});
document.querySelectorAll("[data-submit-form]").forEach((form) => {
form.addEventListener("submit", () => {
form.dataset.submitting = "true";
const button = form.querySelector("[data-submit-button]");
if (!button) return;
button.disabled = true;
button.textContent = button.dataset.loadingLabel || "正在提交…";
});
});
const fileInput = document.querySelector("input[type='file'][name='image']");
const image = document.querySelector("[data-image-preview]");
const placeholder = document.querySelector("[data-image-placeholder]");
const imageName = document.querySelector("[data-image-name]");
let previewURL = "";
if (fileInput && image && placeholder && imageName) {
fileInput.addEventListener("change", () => {
if (previewURL) URL.revokeObjectURL(previewURL);
const file = fileInput.files && fileInput.files[0];
if (!file) {
image.hidden = true;
placeholder.hidden = false;
imageName.textContent = "选择后在本地预览";
return;
}
previewURL = URL.createObjectURL(file);
image.src = previewURL;
image.hidden = false;
placeholder.hidden = true;
imageName.textContent = `${file.name} · ${(file.size / 1024).toFixed(1)} KB`;
});
window.addEventListener("pagehide", () => {
if (previewURL) URL.revokeObjectURL(previewURL);
});
}
const dirtyForm = document.querySelector("[data-dirty-form]");
const leaveDialog = document.querySelector("[data-leave-dialog]");
let dirty = false;
let destination = "";
if (dirtyForm && leaveDialog) {
dirtyForm.addEventListener("input", () => {
dirty = true;
});
dirtyForm.addEventListener("change", () => {
dirty = true;
});
dirtyForm.addEventListener("submit", () => {
dirty = false;
});
document.querySelectorAll("a[href]").forEach((link) => {
link.addEventListener("click", (event) => {
if (!dirty || link.hasAttribute("data-discard")) return;
const target = new URL(link.href, window.location.href);
if (target.origin !== window.location.origin) return;
event.preventDefault();
destination = target.href;
leaveDialog.showModal();
leaveDialog.querySelector("[data-stay]").focus();
});
});
leaveDialog.querySelector("[data-stay]").addEventListener("click", () => {
leaveDialog.close();
});
leaveDialog.querySelector("[data-discard]").addEventListener("click", (event) => {
event.preventDefault();
dirty = false;
window.location.assign(destination || "/tasks");
});
}
const openCancel = document.querySelector("[data-open-cancel]");
const cancelDialog = document.querySelector("[data-cancel-dialog]");
if (openCancel && cancelDialog) {
openCancel.addEventListener("click", () => {
cancelDialog.showModal();
cancelDialog.querySelector("[data-keep-task]").focus();
});
cancelDialog.querySelector("[data-keep-task]").addEventListener("click", () => {
cancelDialog.close();
openCancel.focus();
});
}
})();