This repository is a Vue 3 + Element Plus admin dashboard inspired by V2Board. This guide gives agentic contributors the commands they need, a quick architectural map, and the implicit style expectations that keep the UI consistent and reliable.
npm install(orbun install/pnpm installonce their lockfiles exist) to install dependencies listed inpackage.json.- Re-run install whenever
package.json,package-lock.json, orbun.lockchanges.
npm run devstarts Vite with HMR on the default port (5173). Add-- --host 0.0.0.0 --port <port>to bind elsewhere.- Pass
VITE_API_BASE_URL/VITE_DASHBOARD_SECURE_PATHvia.envorenvprefix when hitting a real backend; defaults point tohttps://example.invalid.
npm run buildproduces the optimized bundle insidedist/.npm run previewserves the production build for local verification.- Inspect
dist/assetsafter building to ensure hashed JS/CSS files ship expected size and there are no missing chunks.
- No lint/test scripts are defined yet. When tests arrive, run
npx vitest run path/to/file.test.js(orvitest run) to target a single spec. - Consider
vitest --watchfor iterative development andvitest --runInBandfor deterministic execution. - Add linting (ESLint + Prettier) before expanding the codebase; keep rules compatible with Vue 3 and script setup syntax.
- Entry:
src/main.jswires Vue, Pinia, Element Plus, and the router before mounting to#root. - Router:
src/router/index.jsdefines the login route plus the admin shell (AdminLayout.vue) with child pages (DashboardPage,UsersPage, etc.). - Layout:
AdminLayout.vuerenders the sidebar/navigation cards with computed menu items. - Services:
src/services/*compose API URLs (buildDashboardApiUrl,buildCommonApiUrl), addtquery stamps, and centralize fetch logic. - Stores: Pinia stores under
src/stores(admin, auth) manage state, call services, and expose reactive refs for pages and components. - Components: Organized under
src/components/dashboard,src/components/settings, andsrc/components/commonby concern, each focusing on a single dashboard card or shared widget.
- Stick to ESM syntax (
import ... from ...). External libs (Vue/Pinia/Element Plus) appear first, then internal services/stores, and finally local components. - Prefer relative paths that climb at most two levels when possible; avoid deep
../../../chains by reorganizing directories or creating index files. - Keep
importorder alphabetical within each group for readability.
- Use two spaces for indentation in
.vue,.js, and.cssfiles. - Use single quotes in scripts unless the string contains an apostrophe; templates may use double quotes for attributes for legibility.
- Keep template attributes wrapped across lines once there are three or more props/events; align the continuation for each attribute (same column indentation).
- Break up long method chains (filters, computed maps) with line breaks after each chained call.
- Vue components/pages: PascalCase (e.g.,
DashboardPage,IncomeOverviewCard). File names match the component names. - Stores/composables:
useXyzStore(e.g.,useAdminStore,useAuthStore). - Reactive refs, methods, helpers: camelCase (
dashboardStatsLoading,formatDateValue). - Props/events in templates: kebab-case (
@change-range,:overview). - Constants that truly never change outside module scope may stay
UPPER_SNAKE_CASE(e.g.,DEFAULT_API_ORIGIN).
- Prefer
<script setup>whenever the component can be expressed declaratively; only fall back todefineComponentwhen you need to expose options. - Call Pinia stores at the top of
<script setup>(const adminStore = useAdminStore()) and avoid referencing them directly inside template logic (prefer computed helpers if necessary). - Keep templates lean by offloading rich logic to components or composables; use slots for repeating structures (e.g., cards with alerts).
- Wrap every async call in
try/catch; set dedicated error refs (e.g.,dashboardStatsError.value) and showel-alertmessages when an error string exists. - Inspect response status before parsing JSON and throw informative
Errorinstances when things fail (throw new Error('登录失败,请检查邮箱或密码')). - Default to safe placeholder data via helper factories (
createEmptyIncomeOverview,createEmptyQueueStats) so components never renderundefined. - When a response returns
{ status, message }, consider bothstatus !== 'success'and numericcode !== 0before accepting the payload.
- Use
constfor values that never reassign (presets, static navigation arrays, plan samples) andletonly when reassignment is needed (e.g., temporary formatting variables). - Represent repeated UI structures through data arrays/objects rather than duplicating markup; templates loop over the data and render cards.
- Keep helper functions pure and referentially transparent; prefer parameterized factories over shared mutable state.
- Global styles live in
src/styles.css; local component styles (when needed) should use<style scoped>to prevent bleeding. - Favor CSS custom properties for theming (define colors/spacing once and reuse). Keep layout consistent: grid/stack classes (
page-stack,hero-grid). - When adding new cards, maintain the same class names and Element Plus variants (
el-alert,el-card,el-table) already used.
- When adding new data tables, build dedicated services that return normalized data and expose loading/error refs from Pinia stores.
- Enhance existing cards by creating single-responsibility components and wiring props/events explicitly (no implicit global state).
- Always validate new API endpoints with Postman/cURL and reflect required headers (authorization) in the service helpers.
- Keep translations or copy in plain text for now but consider centralizing into a future
i18nsolution.
- There are no
.cursoror.cursorrulesfiles in this repo, and no.github/copilot-instructions.mdexists at the moment. Follow general repository conventions until specific cursor/Copilot guidance is supplied.
- Run the dev server, explore each view, and identify gaps where more tests or validation would help.
- When introducing shared logic (e.g., new service functions), ensure their formatting/naming align with the guidelines above.
- Consider augmenting this guide if new architectural patterns are introduced.