前端优化

This commit is contained in:
Zzzz
2026-04-28 19:26:08 +08:00
parent 36db197e75
commit 0a386b81f9
10 changed files with 607 additions and 424 deletions
@@ -45,6 +45,9 @@ image-first design and preserve the Servlet/JSP layered architecture.
- Do not implement UI only from text descriptions when an approved image
reference exists.
- Do not put SQL, DAO calls, or business workflows in JSP pages.
- Do not hard-code operational dashboard/report metrics, sample people, fixed
borrow dates, or fake table rows in JSP pages; use Servlet-provided request
attributes and empty states.
- Do not rely only on browser validation for protected workflows.
---
@@ -36,6 +36,100 @@ changes the frontend architecture.
---
## Scenario: Dashboard Workbench Request Contract
### 1. Scope / Trigger
- Trigger: the authenticated workbench spans Servlet request attributes,
service-derived report/catalog/borrowing data, and role-specific JSP display.
- Route: `GET /dashboard`.
- JSP path: `WEB-INF/jsp/dashboard.jsp`.
### 2. Signatures
- Servlet: `DashboardServlet.doGet(HttpServletRequest, HttpServletResponse)`.
- Services used for page data:
- `BookService.listCategories()`.
- `BookService.searchBooks(new BookSearchCriteria())`.
- `ReaderService.searchReaders(new ReaderSearchCriteria())` for staff reader
totals.
- `ReportService.loadReportCenter(AuthenticatedUser actor)` for
administrator/librarian users.
- `BorrowingService.searchRecords(actor, new BorrowRecordSearchCriteria())`
for administrator/librarian users.
- Request attributes:
- `currentUser: AuthenticatedUser`.
- `categories: List<BookCategory>`.
- `dashboardBooks: List<Book>`.
- `dashboardMetrics: List<DashboardMetric>`.
- `reportCenter: ReportCenter` for staff users when report loading succeeds.
- `dashboardBorrowRecords: List<BorrowRecord>` for staff users.
- `errorMessage: String` when a service returns a safe failure.
### 3. Contracts
- Workbench values must come from request attributes populated by the Servlet;
JSP must not embed operational sample rows, fixed dates, or fake totals.
- Staff metrics use `ReportCenter` values derived from `books` and
`borrow_records`, plus reader totals from `ReaderService`; reader fallback
metrics may derive from `dashboardBooks`.
- Popular ranking, overdue rows, and borrowing rows render only real service
results and show empty states when lists are empty.
- Category filters render from `categories`, the same source used by catalog and
book-management pages.
- Role-gated sections stay in JSP conditionals based on `sessionScope.userRole`;
staff-only data is not requested for reader users.
### 4. Validation & Error Matrix
- Category load failure -> `categories` is an empty list and `errorMessage` is
set.
- Book search failure -> `dashboardBooks` is an empty list and `errorMessage`
is set.
- Reader total load failure -> staff metrics fall back to another real
service-derived metric and `errorMessage` is set.
- Staff report load failure -> report-backed sections show empty states and
`errorMessage` is set.
- Staff borrowing search failure -> `dashboardBorrowRecords` is an empty list
and `errorMessage` is set.
- Empty service result -> render a stable empty state, not hard-coded fallback
sample data.
### 5. Good/Base/Bad Cases
- Good: a librarian opens `/dashboard` and sees report-backed metrics, current
borrowing rows, overdue rows, popular ranking, and real book rows.
- Base: no borrow records exist; the workbench keeps the layout and shows empty
states for ranking, borrowing, and overdue panels.
- Bad: `dashboard.jsp` contains names, book IDs, 2024 dates, or counts that do
not come from request attributes.
### 6. Tests Required
- Run Maven compile/test for Servlet and JavaBean contract checks.
- Run standalone service checks covering report, borrowing, catalog/book, and
permission policy behavior when available.
- Scan `dashboard.jsp` for static sample names, fixed dates, and decorative
sample-only values after dashboard changes.
- Verify staff and reader role conditionals still show only the intended
sections.
### 7. Wrong vs Correct
#### Wrong
```text
dashboard.jsp -> hard-coded metric "12,586" and fixed rows like "L20240521001"
```
#### Correct
```text
dashboard.jsp <- DashboardServlet <- ReportService/BookService/ReaderService/BorrowingService
```
---
## Page Scripts
Small JavaScript can improve interaction, such as confirm dialogs or local form
@@ -0,0 +1,5 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
{"file": ".trellis/spec/frontend/index.md", "reason": "Verify frontend work follows JSP/CSS conventions"}
{"file": ".trellis/spec/frontend/quality-guidelines.md", "reason": "Verify responsive UI and simplified authenticated shell"}
{"file": ".trellis/spec/backend/quality-guidelines.md", "reason": "Verify backend layering and no static data regressions"}
{"file": ".trellis/spec/backend/database-guidelines.md", "reason": "Verify dashboard uses existing derived report data correctly"}
@@ -0,0 +1,8 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
{"file": ".trellis/spec/frontend/index.md", "reason": "Frontend JSP/CSS conventions for authenticated shell and dashboard UI"}
{"file": ".trellis/spec/backend/index.md", "reason": "Backend Servlet/service/DAO layering for dashboard real data"}
{"file": ".trellis/spec/frontend/component-guidelines.md", "reason": "JSP fragments, cards, tables, and reusable presentation rules"}
{"file": ".trellis/spec/frontend/state-management.md", "reason": "Server-rendered request/session state conventions"}
{"file": ".trellis/spec/frontend/quality-guidelines.md", "reason": "UI quality checks for JSP/CSS changes"}
{"file": ".trellis/spec/backend/database-guidelines.md", "reason": "Existing report data contracts and database-derived summary rules"}
{"file": ".trellis/spec/backend/error-handling.md", "reason": "ServiceResult and servlet error handling conventions"}
@@ -0,0 +1,54 @@
# Fix Frontend Workbench Display
## Goal
Make the authenticated workbench reflect real application data and simplify the navigation-heavy UI so it does not duplicate the sidebar.
## What I Already Know
- The user reported that the frontend workbench data does not match actual data.
- The current `dashboard.jsp` hard-codes metric values, popular book ranking rows, borrowing rows, overdue rows, and book rows.
- The workbench shortcut cards for 读者管理, 报表中心, 借阅流通, and 系统日志 duplicate links already present in the sidebar.
- The UI uses circular single-character markers beside text in metrics, shortcut cards, sidebar links, role chips, and topbar user summary.
- The sidebar is fixed on desktop, but responsive CSS changes `.app-sidebar` and `.app-topbar` to static layout under 960px, effectively removing the persistent sidebar behavior.
- Existing report infrastructure already exposes actual inventory summary, borrowing summary, overdue rows, and popular books through `ReportService.loadReportCenter(...)`.
## Assumptions
- "UI text beside an unnecessary circle with one character" applies to decorative single-character icon circles in the authenticated shell and workbench, not to plain text labels or table status pills.
- The workbench should reuse existing server-rendered JSP/Servlet patterns rather than introducing client-side state.
- When a specific real data source does not yet exist, prefer showing an existing real metric over keeping a static fake metric.
## Requirements
- Replace hard-coded workbench summary metrics with real data.
- Replace the hard-coded popular book ranking with real ranking data.
- Replace hard-coded borrowing/overdue/book table samples with real data or remove the fake sample rows in favor of empty states.
- Keep the workbench catalog search category selector populated from real categories.
- Remove the workbench shortcut entry block containing 读者管理, 报表中心, 借阅流通, and 系统日志.
- Remove the decorative circular single-character UI markers around text in the authenticated shell/workbench where they are not functionally necessary.
- Ensure the sidebar cannot be hidden or collapsed by responsive layout rules.
- Keep role-based visibility and permissions intact for administrator, librarian, and reader users.
## Acceptance Criteria
- [ ] Workbench metrics are rendered from request attributes populated by backend services, not hard-coded numbers.
- [ ] Popular ranking and table content no longer contain static sample records such as 张晓明, 活着, 三体, or fixed 2024 dates unless those values come from the database.
- [ ] The workbench no longer shows shortcut cards for 读者管理, 报表中心, 借阅流通, or 系统日志.
- [ ] Decorative single-character circles next to UI text are removed or restyled as plain text/spacing without circular badges.
- [ ] Sidebar remains visible and occupies its sidebar column across responsive breakpoints.
- [ ] Existing navigation links still work and remain role-aware.
- [ ] Project lint/type-check or the closest available Java build/test command passes.
## Out Of Scope
- Adding new major dashboard modules beyond the current workbench content.
- Redesigning unrelated pages outside the shared authenticated shell and workbench.
- Changing database schema unless necessary to replace static workbench data.
## Technical Notes
- Likely files: `src/main/java/com/mzh/library/controller/DashboardServlet.java`, `src/main/webapp/WEB-INF/jsp/dashboard.jsp`, `src/main/webapp/WEB-INF/jsp/common/header.jspf`, and `src/main/webapp/static/css/app.css`.
- Existing actual report data: `ReportServiceImpl`, `JdbcReportDao`, `ReportCenter`, `InventorySummary`, `BorrowingSummary`, `OverdueReportRow`, and `PopularBookReportRow`.
- Existing category/book patterns: `BookServiceImpl`, `JdbcBookDao`, and `BookCatalogServlet`.
- Existing borrowing list pattern: `BorrowingServiceImpl.searchRecords(...)` and `BorrowingManagementServlet`.
@@ -0,0 +1,26 @@
{
"id": "frontend-workbench-display-fix",
"name": "frontend-workbench-display-fix",
"title": "修复前端工作台展示",
"description": "",
"status": "in_progress",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "Zzzz",
"assignee": "Zzzz",
"createdAt": "2026-04-28",
"completedAt": null,
"branch": null,
"base_branch": "master",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": null,
"relatedFiles": [],
"notes": "",
"meta": {}
}