From e4116d7ec41dd166a8f61aeaad2936984f6b92fc Mon Sep 17 00:00:00 2001 From: Sunwuyuan Date: Sat, 23 May 2026 19:17:14 +0800 Subject: [PATCH] refactor: improve code formatting and structure across multiple components - Updated Vue components in `src/pages/list/index.vue`, `src/pages/settings.vue`, and `src/pages/socket-debugger.vue` for better readability by adjusting indentation and line breaks. - Enhanced the `dataProvider.js` utility to streamline server and local data handling, including the introduction of a sync queue for offline write buffering. - Incremented the local database version in `kvLocalProvider.js` to accommodate new sync queue features. - Added a new `CLAUDE.md` file to provide project overview and development guidelines. - Commented out the Sentry vendor chunk in `vite.config.mjs` for potential future use. --- CLAUDE.md | 72 +++ src/App.vue | 10 +- src/components/AppHeader.vue | 4 +- src/components/CacheManager.vue | 69 ++- src/components/ExamConfigEditor.vue | 433 ++++++++++----- src/components/FloatingToolbar.vue | 19 +- src/components/GlobalMessage.vue | 22 +- src/components/HelloWorld.vue | 19 +- src/components/HitokotoSettings.vue | 236 ++++++-- src/components/HomeworkEditDialog.vue | 64 ++- src/components/MessageLog.vue | 37 +- src/components/NoiseMonitorCard.vue | 25 +- src/components/PwaInstallCard.vue | 49 +- src/components/RandomPicker.vue | 87 ++- src/components/RateLimitModal.vue | 42 +- src/components/ReadOnlyTokenWarning.vue | 2 +- src/components/SettingsCard.vue | 18 +- src/components/SettingsLinkGenerator.vue | 227 +++++--- src/components/StudentNameManager.vue | 2 - src/components/TimeCard.vue | 5 +- src/components/UrgentNotification.vue | 29 +- src/components/UrgentTestDialog.vue | 120 ++-- .../attendance/AttendanceManagementDialog.vue | 61 ++- .../attendance/AttendanceSidebar.vue | 15 +- src/components/auth/AlternativeCodeDialog.vue | 2 +- src/components/auth/DeviceAuthDialog.vue | 10 +- src/components/auth/FirstTimeGuide.vue | 4 +- .../auth/ProgressiveRegisterPage.vue | 14 +- src/components/auth/TokenInputDialog.vue | 2 +- .../common/AsyncLoadingPlaceholder.vue | 12 +- src/components/common/HomeSkeleton.vue | 5 +- src/components/error/404.vue | 33 +- src/components/home/ConciseExamCard.vue | 30 +- src/components/home/ExamScheduleCard.vue | 88 ++- src/components/home/HomeActions.vue | 16 +- src/components/home/HomeworkGrid.vue | 158 ++++-- src/components/settings/AboutCard.vue | 163 ++++-- .../settings/CloudMigrationDialog.vue | 80 ++- .../settings/NotificationSoundSettings.vue | 31 +- src/components/settings/SettingGroup.vue | 18 +- src/components/settings/SettingItem.vue | 52 +- src/components/settings/SettingsExplorer.vue | 40 +- src/components/settings/StudentListCard.vue | 51 +- src/components/settings/TeacherListCard.vue | 71 ++- .../settings/cards/CloudNamespaceInfoCard.vue | 16 +- .../cards/DataProviderSettingsCard.vue | 82 ++- .../settings/cards/DisplaySettingsCard.vue | 70 ++- .../settings/cards/EchoChamberCard.vue | 25 +- .../settings/cards/EditSettingsCard.vue | 28 +- .../settings/cards/HomeworkTemplateCard.vue | 120 +++- .../settings/cards/KvDatabaseCard.vue | 254 +++++++-- .../settings/cards/RandomPickerCard.vue | 29 +- .../settings/cards/RefreshSettingsCard.vue | 18 +- .../settings/cards/SubjectManagementCard.vue | 14 +- .../settings/cards/ThemeSettingsCard.vue | 30 +- src/main.js | 16 +- src/pages/404.vue | 2 +- src/pages/CacheManagement.vue | 69 ++- src/pages/authorize.vue | 27 +- src/pages/cses2wakeup.vue | 515 +++++++++++++----- src/pages/debug-init.vue | 2 +- src/pages/debug-socket.vue | 18 +- src/pages/debug.vue | 10 +- src/pages/exam-editor/[id].vue | 2 +- src/pages/examschedule.vue | 206 +++++-- src/pages/index.vue | 241 ++++++-- src/pages/list/[id].vue | 154 ++++-- src/pages/list/index.vue | 80 ++- src/pages/settings.vue | 158 ++++-- src/pages/socket-debugger.vue | 131 ++++- src/utils/dataProvider.js | 252 ++++----- src/utils/providers/kvLocalProvider.js | 45 +- vite.config.mjs | 2 +- 73 files changed, 3769 insertions(+), 1394 deletions(-) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..61f8229 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,72 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +Classworks (作业板) is a homework board widget for classroom large screens. It's a Vue 3 + Vuetify 3 PWA with real-time sync via Socket.IO. The UI is in Chinese. + +## Commands + +```bash +pnpm install # Install dependencies +pnpm run dev # Dev server at localhost:3031 (network-accessible) +pnpm run build # Production build (auto-runs prebuild to regenerate sound list) +pnpm run preview # Preview production build +pnpm run lint # ESLint with auto-fix +``` + +## Tech Stack + +- **Framework**: Vue 3 (Composition API + Options API mixed), JavaScript (no TypeScript) +- **UI**: Vuetify 3 (Material Design 3), `@mdi/font` icons, SCSS +- **State**: Pinia 3 +- **Routing**: Vue Router 4 with file-based routes (`unplugin-vue-router` + `vite-plugin-vue-layouts`) +- **Build**: Vite 5, pnpm +- **Real-time**: Socket.IO client (singleton in `src/utils/socketClient.js`) +- **Data**: Pluggable KV provider abstraction (`src/utils/dataProvider.js`) with IndexedDB local and HTTP server backends +- **PWA**: `vite-plugin-pwa` with Workbox service worker + +## Architecture + +### Data Layer + +`src/utils/dataProvider.js` abstracts data operations. It routes to either: +- `src/utils/providers/kvLocalProvider.js` — IndexedDB via `idb` +- `src/utils/providers/kvServerProvider.js` — HTTP API via axios + +Server failover is handled by `src/utils/serverRotation.js`. + +### Real-time Layer + +`src/utils/socketClient.js` — Socket.IO singleton with room-based token join/leave for live updates. + +### Settings Layer + +`src/utils/settings.js` — Comprehensive localStorage-based settings with typed definitions, defaults, and legacy migration. ~600 lines. + +### UI Layer + +File-based routing: each `.vue` in `src/pages/` becomes a route. Layouts in `src/layouts/`. The main dashboard is `src/pages/index.vue` (78KB — the core view composing homework grid, time card, noise monitor, random picker, exam schedule, etc.). + +Components are organized by feature: +- `src/components/home/` — Home page components +- `src/components/settings/` — Settings cards +- `src/components/auth/` — Authentication flow +- `src/components/attendance/` — Attendance management +- `src/components/common/` — Shared components + +### Key Utilities + +- `src/axios/axios.js` — Axios instance with auth interceptors and rate limit handling +- `src/utils/api.js` — API helpers, namespace info, server rotation +- `src/utils/visitorId.js` — FingerprintJS device identification +- `src/utils/soundList.js` — Auto-generated from `public/sounds/` by `scripts/generate-sound-list.js` (runs as `prebuild`) + +## Code Style + +- 2-space indent, trim trailing whitespace (`.editorconfig`) +- Path alias: `@/` maps to `src/` (`jsconfig.json`) +- ESLint flat config (ESLint 9) with Vue recommended rules (`eslint.config.js`) +- Mixed Composition API and Options API usage +- No TypeScript diff --git a/src/App.vue b/src/App.vue index cd7b1bb..6118c99 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,8 +2,14 @@ - - + + diff --git a/src/components/AppHeader.vue b/src/components/AppHeader.vue index 6a62425..7e625f6 100644 --- a/src/components/AppHeader.vue +++ b/src/components/AppHeader.vue @@ -1,7 +1,7 @@