({
glowIntensity: 5,
setGlow: (value) => set({ glowIntensity: value })
}));
```
- **局部状态**:`useReducer` + Context
#### 3.3 组件契约
```typescript
interface GlowButtonProps {
intensity: 1 | 2 | 3; // 发光强度等级
onGlowStart?: () => void; // 发光开始事件
glowColor?: string; // 可选自定义色
}
```
---
### 4. 性能优化
#### 4.1 加载优化
- **代码分割**:基于路由的`React.lazy`
```javascript
const SkinAnalysis = lazy(() => import('./domains/skin/Analysis'));
```
- **图片策略**:
- WebP格式优先
- CDN动态裁剪:`?width=400&format=webp`
#### 4.2 渲染性能
- **虚拟化列表**:`react-window`用于产品库
- **记忆化**:`React.memo` + `useCallback`
- **GPU加速**:CSS `will-change: transform;`
#### 4.3 包体积控制
```bash
# 构建分析
npx source-map-explorer build/static/js/*.js
```
- 目标:主包 ≤ 150KB
- 策略:按需引入`@mui/icons-material`
---
### 5. 测试标准
#### 5.1 测试金字塔
| 层级 | 工具 | 覆盖率目标 |
|------|------|------------|
| 单元 | Jest | 核心逻辑100% |
| 集成 | React Testing Library | 组件85% |
| E2E | Cypress | 关键路径100% |
#### 5.2 特殊测试场景
```javascript
// 发光效果测试用例
test('GlowButton should emit light on hover', () => {
render();
fireEvent.mouseEnter(screen.getByRole('button'));
expect(screen.getByTestId('glow-effect')).toHaveStyle('opacity: 1');
});
```
---
### 6. 构建与部署
#### 6.1 工作流
```mermaid
graph LR
A[开发] -->|Commit| B(ESLint/Prettier)
B --> C[单元测试]
C --> D[MR请求]
D --> E[CI流水线]
E --> F[预发布验证]
```
#### 6.2 环境配置
```env
# .env.production
REACT_APP_API_ENDPOINT=https://api.youbeauty.com/v2
REACT_APP_GLOW_EFFECT_LEVEL=pro
```
#### 6.3 部署策略
- **蓝绿部署**:通过CloudFront路由切换
- **渐进式发布**:Feature Flags控制新功能
- **回滚机制**:5分钟内可回退至上一版本
> **扩展性设计**:
> 1. 设计系统版本独立发布(npm私库)
> 2. 微前端准备:通过`module-federation`支持未来子产品线接入
> 3. 性能监控集成:Sentry + Lighthouse CI
本指南将持续更新于YOU项目的`frontend-wiki`仓库,所有变更需通过架构评审委员会批准。
--- AI Generated Technical Documentation (Frontend Guideline Document) ---
### **Frontend Development Guideline Document for YOU Project**
*(YOUR OWN UNIQUE - Inclusive Beauty Products)*
---
#### **1. Development Standards**
**1.1 Code Style & Formatting**
- **Tools**: ESLint (Airbnb config), Prettier
- **Rules**:
- 2-space indentation, LF line endings
- Max line length: 100 characters
- Semicolons enforced
- Single quotes for JS, double quotes for JSX
- **Automation**: Pre-commit hooks (Husky + lint-staged)
**1.2 Naming Conventions**
- **Variables**: `camelCase` (e.g., `userProfile`)
- **Components**: `PascalCase` (e.g., `GlowButton.vue`)
- **Constants**: `UPPER_SNAKE_CASE` (e.g., `MAX_RETRY_COUNT`)
- **Files/Folders**: `kebab-case` (e.g., `product-card/`)
**1.3 File & Folder Organization**
```plaintext
src/
├── assets/ # Static assets (SVGs, images)
├── components/ # Reusable components
│ ├── common/ # Generic UI (Button, Card)
│ └── domain/ # Domain-specific (SkinAnalysisTool)
├── composables/ # Vue Composition API logic
├── layouts/ # App-wide layouts
├── router/ # Vue Router configurations
├── store/ # Pinia state modules
├── styles/ # Global SCSS variables/mixins
├── utils/ # Helper functions
└── views/ # Page-level components
```
**1.4 Documentation Requirements**
- **Components**: JSDoc for props, events, and slots (e.g., `@prop {String} skinTone`).
- **Functions**: TypeScript interfaces for arguments/return types.
- **README.md** per module folder explaining purpose and usage.
---
#### **2. UI/UX Guidelines**
**2.1 Design System**
- **Tools**: Figma integration via [Storybook](https://storybook.js.org/).
- **Tokens**: CSS variables for colors, spacing, typography (e.g., `--glow-primary: #FF6B9D;`).
- **Component Library**: Atomic design (Atoms → Molecules → Organisms).
**2.2 Responsive Design**
- **Breakpoints**:
- Mobile: < 768px
- Tablet: 768px – 1024px
- Desktop: > 1024px
- **Approach**: Mobile-first CSS, `flex/grid` layouts, relative units (`rem`, `%`).
**2.3 Accessibility (WCAG 2.1 AA)**
- **Semantic HTML**: ARIA labels for icons, `alt` text for images.
- **Contrast**: Minimum 4.5:1 text/background ratio (verified via axe-core).
- **Keyboard Navigation**: Focus management for interactive elements.
**2.4 Interaction Patterns**
- **Animations**: Subtle transitions (Framer Motion) for feedback (e.g., button hover).
- **Loading States**: Skeleton loaders for async data.
- **Error Handling**: Toast notifications with actionable messages.
---
#### **3. Component Architecture**
**3.1 Design Patterns**
- **Stateless Components**: Pure UI elements (e.g., `GlowBadge`).
- **Stateful Containers**: Fetches data and passes props (e.g., `SkinHealthDashboard`).
- **Compound Components**: Context API for related components (e.g., `TabGroup` + `TabItem`).
**3.2 State Management**
- **Global State**: Pinia stores for cross-component data (e.g., user preferences).
- **Local State**: Vue `ref`/`reactive` for component-specific state.
- **Data Fetching**: Composables with `useFetch` abstraction (axios + error handling).
**3.3 Props & Events**
- **Props**:
- Type-checked with TypeScript/Vue PropTypes.
- Default values for optional props.
- **Events**: Emit custom events (e.g., `@glow-effect-applied`).
**3.4 Reusable Components**
- **Props API**: Minimize required props; use slots for content injection.
- **Theming**: Support `theme` prop (light/dark) via CSS variables.
- **Documentation**: Storybook stories for visual testing.
---
#### **4. Performance Guidelines**
**4.1 Code Splitting & Lazy Loading**
- **Routes**: Vue Router lazy imports (`() => import('./SkinAnalysis.vue')`).
- **Components**: `defineAsyncComponent` for heavy non-critical UIs.
**4.2 Bundle Optimization**
- **Tree Shaking**: ES Module imports (e.g., `import { Button } from 'ui-library'`).
- **Compression**: Brotli/Gzip via Vite build.
- **Vendor Chunks**: Separate `node_modules` into `vendor-[hash].js`.
**4.3 Rendering Performance**
- **Virtualization**: `vue-virtual-scroller` for large lists.
- **Memoization**: `computed` properties and `v-once` for static content.
- **Debouncing**: Input handlers (e.g., search with Lodash `debounce`).
**4.4 Memory Management**
- **Event Listeners**: Remove in `onUnmounted()` lifecycle hook.
- **Large Data**: Web Workers for CPU-intensive tasks (e.g., image processing).
---
#### **5. Testing Standards**
**5.1 Unit Testing**
- **Tools**: Vitest + Vue Test Utils.
- **Coverage**: > 80% for core logic (business rules, utils).
- **Patterns**: Mock API calls (MSW), snapshot testing for components.
**5.2 Integration Testing**
- **Scope**: Component interactions (e.g., form validation flows).
- **Tools**: Testing Library (`render`, `fireEvent`).
**5.3 E2E Testing**
- **Tool**: Cypress with Percy visual regression.
- **Critical Paths**: User onboarding, product customization, checkout.
**5.4 Testing Tools**
```json
"devDependencies": {
"vitest": "^1.0.0",
"@testing-library/vue": "^7.0.0",
"cypress": "^12.0.0",
"@percy/cypress": "^3.0.0"
}
```
---
#### **6. Build and Deployment**
**6.1 Development Workflow**
- **Branching**: GitFlow (main → develop → feature branches).
- **CI/CD**: GitHub Actions for lint/test on PR; auto-deploy on merge to `main`.
**6.2 Build Optimization**
- **Vite Config**:
- Minify CSS/JS (`cssnano`, `terser`).
- PWA support via `vite-plugin-pwa`.
- **Asset Handling**: Inline assets < 10KB; hash filenames for caching.
**6.3 Environment Configuration**
- **Env Variables**: `.env.[mode]` files (e.g., `.env.staging`, `.env.production`).
- **Security**: Prefix sensitive keys with `VITE_` for Vite exposure.
**6.4 Deployment Strategies**
- **Static Hosting**: Vercel/Netlify for CDN distribution.
- **Blue/Green**: Zero-downtime releases via cloud provider (AWS/Azure).
- **Rollback**: Automated on E2E failure (monitored via Sentry).
---
**Revision Log**: Maintain in `CHANGELOG.md`; review quarterly for tech debt.
**Ownership**: Frontend Guild oversees updates; deviations require RFC.
--- 生成时间: 6/19/2025, 9:06:00 PM ---">
({
glowIntensity: 5,
setGlow: (value) => set({ glowIntensity: value })
}));
```
- **局部状态**:`useReducer` + Context
#### 3.3 组件契约
```typescript
interface GlowButtonProps {
intensity: 1 | 2 | 3; // 发光强度等级
onGlowStart?: () => void; // 发光开始事件
glowColor?: string; // 可选自定义色
}
```
---
### 4. 性能优化
#### 4.1 加载优化
- **代码分割**:基于路由的`React.lazy`
```javascript
const SkinAnalysis = lazy(() => import('./domains/skin/Analysis'));
```
- **图片策略**:
- WebP格式优先
- CDN动态裁剪:`?width=400&format=webp`
#### 4.2 渲染性能
- **虚拟化列表**:`react-window`用于产品库
- **记忆化**:`React.memo` + `useCallback`
- **GPU加速**:CSS `will-change: transform;`
#### 4.3 包体积控制
```bash
# 构建分析
npx source-map-explorer build/static/js/*.js
```
- 目标:主包 ≤ 150KB
- 策略:按需引入`@mui/icons-material`
---
### 5. 测试标准
#### 5.1 测试金字塔
| 层级 | 工具 | 覆盖率目标 |
|------|------|------------|
| 单元 | Jest | 核心逻辑100% |
| 集成 | React Testing Library | 组件85% |
| E2E | Cypress | 关键路径100% |
#### 5.2 特殊测试场景
```javascript
// 发光效果测试用例
test('GlowButton should emit light on hover', () => {
render();
fireEvent.mouseEnter(screen.getByRole('button'));
expect(screen.getByTestId('glow-effect')).toHaveStyle('opacity: 1');
});
```
---
### 6. 构建与部署
#### 6.1 工作流
```mermaid
graph LR
A[开发] -->|Commit| B(ESLint/Prettier)
B --> C[单元测试]
C --> D[MR请求]
D --> E[CI流水线]
E --> F[预发布验证]
```
#### 6.2 环境配置
```env
# .env.production
REACT_APP_API_ENDPOINT=https://api.youbeauty.com/v2
REACT_APP_GLOW_EFFECT_LEVEL=pro
```
#### 6.3 部署策略
- **蓝绿部署**:通过CloudFront路由切换
- **渐进式发布**:Feature Flags控制新功能
- **回滚机制**:5分钟内可回退至上一版本
> **扩展性设计**:
> 1. 设计系统版本独立发布(npm私库)
> 2. 微前端准备:通过`module-federation`支持未来子产品线接入
> 3. 性能监控集成:Sentry + Lighthouse CI
本指南将持续更新于YOU项目的`frontend-wiki`仓库,所有变更需通过架构评审委员会批准。
--- AI Generated Technical Documentation (Frontend Guideline Document) ---
### **Frontend Development Guideline Document for YOU Project**
*(YOUR OWN UNIQUE - Inclusive Beauty Products)*
---
#### **1. Development Standards**
**1.1 Code Style & Formatting**
- **Tools**: ESLint (Airbnb config), Prettier
- **Rules**:
- 2-space indentation, LF line endings
- Max line length: 100 characters
- Semicolons enforced
- Single quotes for JS, double quotes for JSX
- **Automation**: Pre-commit hooks (Husky + lint-staged)
**1.2 Naming Conventions**
- **Variables**: `camelCase` (e.g., `userProfile`)
- **Components**: `PascalCase` (e.g., `GlowButton.vue`)
- **Constants**: `UPPER_SNAKE_CASE` (e.g., `MAX_RETRY_COUNT`)
- **Files/Folders**: `kebab-case` (e.g., `product-card/`)
**1.3 File & Folder Organization**
```plaintext
src/
├── assets/ # Static assets (SVGs, images)
├── components/ # Reusable components
│ ├── common/ # Generic UI (Button, Card)
│ └── domain/ # Domain-specific (SkinAnalysisTool)
├── composables/ # Vue Composition API logic
├── layouts/ # App-wide layouts
├── router/ # Vue Router configurations
├── store/ # Pinia state modules
├── styles/ # Global SCSS variables/mixins
├── utils/ # Helper functions
└── views/ # Page-level components
```
**1.4 Documentation Requirements**
- **Components**: JSDoc for props, events, and slots (e.g., `@prop {String} skinTone`).
- **Functions**: TypeScript interfaces for arguments/return types.
- **README.md** per module folder explaining purpose and usage.
---
#### **2. UI/UX Guidelines**
**2.1 Design System**
- **Tools**: Figma integration via [Storybook](https://storybook.js.org/).
- **Tokens**: CSS variables for colors, spacing, typography (e.g., `--glow-primary: #FF6B9D;`).
- **Component Library**: Atomic design (Atoms → Molecules → Organisms).
**2.2 Responsive Design**
- **Breakpoints**:
- Mobile: < 768px
- Tablet: 768px – 1024px
- Desktop: > 1024px
- **Approach**: Mobile-first CSS, `flex/grid` layouts, relative units (`rem`, `%`).
**2.3 Accessibility (WCAG 2.1 AA)**
- **Semantic HTML**: ARIA labels for icons, `alt` text for images.
- **Contrast**: Minimum 4.5:1 text/background ratio (verified via axe-core).
- **Keyboard Navigation**: Focus management for interactive elements.
**2.4 Interaction Patterns**
- **Animations**: Subtle transitions (Framer Motion) for feedback (e.g., button hover).
- **Loading States**: Skeleton loaders for async data.
- **Error Handling**: Toast notifications with actionable messages.
---
#### **3. Component Architecture**
**3.1 Design Patterns**
- **Stateless Components**: Pure UI elements (e.g., `GlowBadge`).
- **Stateful Containers**: Fetches data and passes props (e.g., `SkinHealthDashboard`).
- **Compound Components**: Context API for related components (e.g., `TabGroup` + `TabItem`).
**3.2 State Management**
- **Global State**: Pinia stores for cross-component data (e.g., user preferences).
- **Local State**: Vue `ref`/`reactive` for component-specific state.
- **Data Fetching**: Composables with `useFetch` abstraction (axios + error handling).
**3.3 Props & Events**
- **Props**:
- Type-checked with TypeScript/Vue PropTypes.
- Default values for optional props.
- **Events**: Emit custom events (e.g., `@glow-effect-applied`).
**3.4 Reusable Components**
- **Props API**: Minimize required props; use slots for content injection.
- **Theming**: Support `theme` prop (light/dark) via CSS variables.
- **Documentation**: Storybook stories for visual testing.
---
#### **4. Performance Guidelines**
**4.1 Code Splitting & Lazy Loading**
- **Routes**: Vue Router lazy imports (`() => import('./SkinAnalysis.vue')`).
- **Components**: `defineAsyncComponent` for heavy non-critical UIs.
**4.2 Bundle Optimization**
- **Tree Shaking**: ES Module imports (e.g., `import { Button } from 'ui-library'`).
- **Compression**: Brotli/Gzip via Vite build.
- **Vendor Chunks**: Separate `node_modules` into `vendor-[hash].js`.
**4.3 Rendering Performance**
- **Virtualization**: `vue-virtual-scroller` for large lists.
- **Memoization**: `computed` properties and `v-once` for static content.
- **Debouncing**: Input handlers (e.g., search with Lodash `debounce`).
**4.4 Memory Management**
- **Event Listeners**: Remove in `onUnmounted()` lifecycle hook.
- **Large Data**: Web Workers for CPU-intensive tasks (e.g., image processing).
---
#### **5. Testing Standards**
**5.1 Unit Testing**
- **Tools**: Vitest + Vue Test Utils.
- **Coverage**: > 80% for core logic (business rules, utils).
- **Patterns**: Mock API calls (MSW), snapshot testing for components.
**5.2 Integration Testing**
- **Scope**: Component interactions (e.g., form validation flows).
- **Tools**: Testing Library (`render`, `fireEvent`).
**5.3 E2E Testing**
- **Tool**: Cypress with Percy visual regression.
- **Critical Paths**: User onboarding, product customization, checkout.
**5.4 Testing Tools**
```json
"devDependencies": {
"vitest": "^1.0.0",
"@testing-library/vue": "^7.0.0",
"cypress": "^12.0.0",
"@percy/cypress": "^3.0.0"
}
```
---
#### **6. Build and Deployment**
**6.1 Development Workflow**
- **Branching**: GitFlow (main → develop → feature branches).
- **CI/CD**: GitHub Actions for lint/test on PR; auto-deploy on merge to `main`.
**6.2 Build Optimization**
- **Vite Config**:
- Minify CSS/JS (`cssnano`, `terser`).
- PWA support via `vite-plugin-pwa`.
- **Asset Handling**: Inline assets < 10KB; hash filenames for caching.
**6.3 Environment Configuration**
- **Env Variables**: `.env.[mode]` files (e.g., `.env.staging`, `.env.production`).
- **Security**: Prefix sensitive keys with `VITE_` for Vite exposure.
**6.4 Deployment Strategies**
- **Static Hosting**: Vercel/Netlify for CDN distribution.
- **Blue/Green**: Zero-downtime releases via cloud provider (AWS/Azure).
- **Rollback**: Automated on E2E failure (monitored via Sentry).
---
**Revision Log**: Maintain in `CHANGELOG.md`; review quarterly for tech debt.
**Ownership**: Frontend Guild oversees updates; deviations require RFC.
--- 生成时间: 6/19/2025, 9:06:00 PM ---">
Mermaid流程图\数据流转说明\接口定义...