Browse Source

refactor: Implement comprehensive TypeScript types for merchant store and related components, and add development guidelines.

FanLide 1 week ago
parent
commit
28a69fa981

+ 52 - 0
.agent/skills/codereview/SKILL.md

@@ -0,0 +1,52 @@
+---
+name: Code Review
+description: A comprehensive guide and checklist for performing code reviews on Vue 3 + TypeScript projects.
+---
+
+# Code Review Skill
+
+Use this skill when the user asks you to "review code", "check for bugs", or "perform a code review". This skill ensures consistency and depth in your reviews.
+
+## Review Checklist
+
+### 1. Functional Correctness
+
+- [ ] **Requirements**: Does the code meet the user's requirements?
+- [ ] **Logic**: Are there logical errors, off-by-one errors, or incorrect conditions?
+- [ ] **Edge Cases**: Are edge cases handled (e.g., empty lists, null values, network failures)?
+
+### 2. TypeScript & Type Safety
+
+- [ ] **No `any`**: Avoid using `any` unless absolutely necessary.
+- [ ] **Interfaces/Types**: Are interfaces and types defined clearly?
+- [ ] **Strictness**: Does it satisfy strict null checks?
+
+### 3. Vue 3 Best Practices
+
+- [ ] **Composition API**: proper usage of `ref`, `reactive`, `computed`, and `watch`.
+- [ ] **Reactivity**: Are reactive dependencies lost (e.g., destructuring props without `toRef`)?
+- [ ] **Components**: Component structure, prop definitions, and event emissions.
+- [ ] **Vant UI**: Correct usage of Vant UI components.
+
+### 4. Code Quality & Style
+
+- [ ] **Readability**: Is the code easy to understand?
+- [ ] **Naming**: Are variables/functions named descriptively?
+- [ ] **Modularity**: Is the code broken down into small, reusable functions/components?
+- [ ] **Comments**: Are complex logic parts commented?
+
+### 5. Performance & Security
+
+- [ ] **Performance**: potential bottlenecks (unnecessary re-renders, heavy computations).
+- [ ] **Security**: XSS, input validation, sensitive data exposure.
+
+## Workflow
+
+1.  **Analyze**: Read the files provided by the user or identified in the task.
+2.  **Evaluate**: check the code against the checklist above.
+3.  **Report**:
+    - **Summary**: A high-level overview of the code quality.
+    - **Issues**: List specific issues found, grouped by severity (Critical, Major, Minor). Include line numbers.
+      - _Example_: `src/views/Home.vue:45` - Destructuring `props` causes loss of reactivity. Use `props.propName` or `toRefs(props)`.
+    - **Suggestions**: Improvement suggestions (refactoring, better approaches).
+4.  **Fix (Optional)**: If the user requests, apply the fixes based on the review.

+ 267 - 0
.agent/workflows/ui-ux-pro-max.md

@@ -0,0 +1,267 @@
+---
+description: Plan and implement UI
+auto_execution_mode: 3
+---
+
+# ui-ux-pro-max
+
+Comprehensive design guide for web and mobile applications. Contains 50+ styles, 97 color palettes, 57 font pairings, 99 UX guidelines, and 25 chart types across 9 technology stacks. Searchable database with priority-based recommendations.
+
+## Prerequisites
+
+Check if Python is installed:
+
+```bash
+python3 --version || python --version
+```
+
+If Python is not installed, install it based on user's OS:
+
+**macOS:**
+```bash
+brew install python3
+```
+
+**Ubuntu/Debian:**
+```bash
+sudo apt update && sudo apt install python3
+```
+
+**Windows:**
+```powershell
+winget install Python.Python.3.12
+```
+
+---
+
+## How to Use This Workflow
+
+When user requests UI/UX work (design, build, create, implement, review, fix, improve), follow this workflow:
+
+### Step 1: Analyze User Requirements
+
+Extract key information from user request:
+- **Product type**: SaaS, e-commerce, portfolio, dashboard, landing page, etc.
+- **Style keywords**: minimal, playful, professional, elegant, dark mode, etc.
+- **Industry**: healthcare, fintech, gaming, education, etc.
+- **Stack**: React, Vue, Next.js, or default to `html-tailwind`
+
+### Step 2: Generate Design System (REQUIRED)
+
+**Always start with `--design-system`** to get comprehensive recommendations with reasoning:
+
+```bash
+python3 .shared/ui-ux-pro-max/scripts/search.py "<product_type> <industry> <keywords>" --design-system [-p "Project Name"]
+```
+
+This command:
+1. Searches 5 domains in parallel (product, style, color, landing, typography)
+2. Applies reasoning rules from `ui-reasoning.csv` to select best matches
+3. Returns complete design system: pattern, style, colors, typography, effects
+4. Includes anti-patterns to avoid
+
+**Example:**
+```bash
+python3 .shared/ui-ux-pro-max/scripts/search.py "beauty spa wellness service" --design-system -p "Serenity Spa"
+```
+
+### Step 3: Supplement with Detailed Searches (as needed)
+
+After getting the design system, use domain searches to get additional details:
+
+```bash
+python3 .shared/ui-ux-pro-max/scripts/search.py "<keyword>" --domain <domain> [-n <max_results>]
+```
+
+**When to use detailed searches:**
+
+| Need | Domain | Example |
+|------|--------|---------|
+| More style options | `style` | `--domain style "glassmorphism dark"` |
+| Chart recommendations | `chart` | `--domain chart "real-time dashboard"` |
+| UX best practices | `ux` | `--domain ux "animation accessibility"` |
+| Alternative fonts | `typography` | `--domain typography "elegant luxury"` |
+| Landing structure | `landing` | `--domain landing "hero social-proof"` |
+
+### Step 4: Stack Guidelines (Default: html-tailwind)
+
+Get implementation-specific best practices. If user doesn't specify a stack, **default to `html-tailwind`**.
+
+```bash
+python3 .shared/ui-ux-pro-max/scripts/search.py "<keyword>" --stack html-tailwind
+```
+
+Available stacks: `html-tailwind`, `react`, `nextjs`, `vue`, `svelte`, `swiftui`, `react-native`, `flutter`, `shadcn`
+
+---
+
+## Search Reference
+
+### Available Domains
+
+| Domain | Use For | Example Keywords |
+|--------|---------|------------------|
+| `product` | Product type recommendations | SaaS, e-commerce, portfolio, healthcare, beauty, service |
+| `style` | UI styles, colors, effects | glassmorphism, minimalism, dark mode, brutalism |
+| `typography` | Font pairings, Google Fonts | elegant, playful, professional, modern |
+| `color` | Color palettes by product type | saas, ecommerce, healthcare, beauty, fintech, service |
+| `landing` | Page structure, CTA strategies | hero, hero-centric, testimonial, pricing, social-proof |
+| `chart` | Chart types, library recommendations | trend, comparison, timeline, funnel, pie |
+| `ux` | Best practices, anti-patterns | animation, accessibility, z-index, loading |
+| `react` | React/Next.js performance | waterfall, bundle, suspense, memo, rerender, cache |
+| `web` | Web interface guidelines | aria, focus, keyboard, semantic, virtualize |
+| `prompt` | AI prompts, CSS keywords | (style name) |
+
+### Available Stacks
+
+| Stack | Focus |
+|-------|-------|
+| `html-tailwind` | Tailwind utilities, responsive, a11y (DEFAULT) |
+| `react` | State, hooks, performance, patterns |
+| `nextjs` | SSR, routing, images, API routes |
+| `vue` | Composition API, Pinia, Vue Router |
+| `svelte` | Runes, stores, SvelteKit |
+| `swiftui` | Views, State, Navigation, Animation |
+| `react-native` | Components, Navigation, Lists |
+| `flutter` | Widgets, State, Layout, Theming |
+| `shadcn` | shadcn/ui components, theming, forms, patterns |
+
+---
+
+## Example Workflow
+
+**User request:** "Làm landing page cho dịch vụ chăm sóc da chuyên nghiệp"
+
+### Step 1: Analyze Requirements
+- Product type: Beauty/Spa service
+- Style keywords: elegant, professional, soft
+- Industry: Beauty/Wellness
+- Stack: html-tailwind (default)
+
+### Step 2: Generate Design System (REQUIRED)
+
+```bash
+python3 .shared/ui-ux-pro-max/scripts/search.py "beauty spa wellness service elegant" --design-system -p "Serenity Spa"
+```
+
+**Output:** Complete design system with pattern, style, colors, typography, effects, and anti-patterns.
+
+### Step 3: Supplement with Detailed Searches (as needed)
+
+```bash
+# Get UX guidelines for animation and accessibility
+python3 .shared/ui-ux-pro-max/scripts/search.py "animation accessibility" --domain ux
+
+# Get alternative typography options if needed
+python3 .shared/ui-ux-pro-max/scripts/search.py "elegant luxury serif" --domain typography
+```
+
+### Step 4: Stack Guidelines
+
+```bash
+python3 .shared/ui-ux-pro-max/scripts/search.py "layout responsive form" --stack html-tailwind
+```
+
+**Then:** Synthesize design system + detailed searches and implement the design.
+
+---
+
+## Output Formats
+
+The `--design-system` flag supports two output formats:
+
+```bash
+# ASCII box (default) - best for terminal display
+python3 .shared/ui-ux-pro-max/scripts/search.py "fintech crypto" --design-system
+
+# Markdown - best for documentation
+python3 .shared/ui-ux-pro-max/scripts/search.py "fintech crypto" --design-system -f markdown
+```
+
+---
+
+## Tips for Better Results
+
+1. **Be specific with keywords** - "healthcare SaaS dashboard" > "app"
+2. **Search multiple times** - Different keywords reveal different insights
+3. **Combine domains** - Style + Typography + Color = Complete design system
+4. **Always check UX** - Search "animation", "z-index", "accessibility" for common issues
+5. **Use stack flag** - Get implementation-specific best practices
+6. **Iterate** - If first search doesn't match, try different keywords
+
+---
+
+## Common Rules for Professional UI
+
+These are frequently overlooked issues that make UI look unprofessional:
+
+### Icons & Visual Elements
+
+| Rule | Do | Don't |
+|------|----|----- |
+| **No emoji icons** | Use SVG icons (Heroicons, Lucide, Simple Icons) | Use emojis like 🎨 🚀 ⚙️ as UI icons |
+| **Stable hover states** | Use color/opacity transitions on hover | Use scale transforms that shift layout |
+| **Correct brand logos** | Research official SVG from Simple Icons | Guess or use incorrect logo paths |
+| **Consistent icon sizing** | Use fixed viewBox (24x24) with w-6 h-6 | Mix different icon sizes randomly |
+
+### Interaction & Cursor
+
+| Rule | Do | Don't |
+|------|----|----- |
+| **Cursor pointer** | Add `cursor-pointer` to all clickable/hoverable cards | Leave default cursor on interactive elements |
+| **Hover feedback** | Provide visual feedback (color, shadow, border) | No indication element is interactive |
+| **Smooth transitions** | Use `transition-colors duration-200` | Instant state changes or too slow (>500ms) |
+
+### Light/Dark Mode Contrast
+
+| Rule | Do | Don't |
+|------|----|----- |
+| **Glass card light mode** | Use `bg-white/80` or higher opacity | Use `bg-white/10` (too transparent) |
+| **Text contrast light** | Use `#0F172A` (slate-900) for text | Use `#94A3B8` (slate-400) for body text |
+| **Muted text light** | Use `#475569` (slate-600) minimum | Use gray-400 or lighter |
+| **Border visibility** | Use `border-gray-200` in light mode | Use `border-white/10` (invisible) |
+
+### Layout & Spacing
+
+| Rule | Do | Don't |
+|------|----|----- |
+| **Floating navbar** | Add `top-4 left-4 right-4` spacing | Stick navbar to `top-0 left-0 right-0` |
+| **Content padding** | Account for fixed navbar height | Let content hide behind fixed elements |
+| **Consistent max-width** | Use same `max-w-6xl` or `max-w-7xl` | Mix different container widths |
+
+---
+
+## Pre-Delivery Checklist
+
+Before delivering UI code, verify these items:
+
+### Visual Quality
+- [ ] No emojis used as icons (use SVG instead)
+- [ ] All icons from consistent icon set (Heroicons/Lucide)
+- [ ] Brand logos are correct (verified from Simple Icons)
+- [ ] Hover states don't cause layout shift
+- [ ] Use theme colors directly (bg-primary) not var() wrapper
+
+### Interaction
+- [ ] All clickable elements have `cursor-pointer`
+- [ ] Hover states provide clear visual feedback
+- [ ] Transitions are smooth (150-300ms)
+- [ ] Focus states visible for keyboard navigation
+
+### Light/Dark Mode
+- [ ] Light mode text has sufficient contrast (4.5:1 minimum)
+- [ ] Glass/transparent elements visible in light mode
+- [ ] Borders visible in both modes
+- [ ] Test both modes before delivery
+
+### Layout
+- [ ] Floating elements have proper spacing from edges
+- [ ] No content hidden behind fixed navbars
+- [ ] Responsive at 375px, 768px, 1024px, 1440px
+- [ ] No horizontal scroll on mobile
+
+### Accessibility
+- [ ] All images have alt text
+- [ ] Form inputs have labels
+- [ ] Color is not the only indicator
+- [ ] `prefers-reduced-motion` respected

+ 33 - 0
.cursorrules

@@ -0,0 +1,33 @@
+# Customization Rules
+
+These rules are used to guide AI agents and developers to ensure code quality and consistency in this project.
+
+## 1. Pinia Persistence
+-   **Plugin**: Use `pinia-plugin-persistedstate`.
+-   **Syntax**: Use the `persist` option with `paths` array.
+-   **Avoid**: Do NOT use `strategies` (deprecated/wrong plugin syntax).
+    ```typescript
+    // Correct
+    persist: {
+      paths: ['key1', 'key2']
+    }
+    ```
+
+## 2. TypeScript & Type Safety
+-   **Strict Types**: Avoid `any` type whenever possible.
+-   **Interfaces**: Define interfaces in `src/types/` for entities used across multiple files.
+    -   Example: `Product`, `Order`.
+-   **Props**: Use `PropType<T>` for complex Vue component props.
+
+## 3. Internationalization (i18n)
+-   **Strict usage**: Do NOT use hardcoded strings in templates or scripts.
+-   **Function**: Always use `t('key')` or `$t('key')`.
+-   **Locale Files**: Ensure keys exist in `zh-Hans.json`, `en.json`, `ja.json`, and `zh-Hant.json`.
+
+## 4. Vue 3 Composition API
+-   **Setup**: Use `<script setup lang="ts">`.
+-   **Vant UI**: Use Vant UI 4.x components.
+
+## 5. Mock Data
+-   **Labeling**: Clearly mark mock data comments with `// Mock`.
+-   **Separation**: Keep mock generation logic isolated or easily replaceable.

+ 2 - 1
.gitignore

@@ -28,4 +28,5 @@ dist-ssr
 .env.*.local
 
 .env.local.example
-.env.local.backup
+.env.local.backup
+.shared/ui-ux-pro-max/*

+ 12 - 18
src/store/modules/merchant.ts

@@ -1,7 +1,8 @@
 import { defineStore } from 'pinia'
+import type { MerchantState, Product, Order } from '@/types/merchant'
 
 export const useMerchantStore = defineStore('merchant', {
-  state: () => ({
+  state: (): MerchantState => ({
     shopInfo: {
       name: '',
       isOpen: true,
@@ -20,8 +21,8 @@ export const useMerchantStore = defineStore('merchant', {
       completed: 0
     },
     pendingOrderCount: 0,
-    orders: [] as any[],
-    products: [] as any[]
+    orders: [],
+    products: []
   }),
 
   getters: {
@@ -62,9 +63,9 @@ export const useMerchantStore = defineStore('merchant', {
           createTime: '2024-01-01 12:30',
           amount: 128.5,
           status: 'pending',
-          items: [{ name: '招牌拉面', quantity: 2 }]
+          items: [{ name: '招牌拉面', quantity: 2, price: 64.25 }] // Adjusted to match OrderItem type
         }
-      ]
+      ] as Order[]
       return { list: this.orders, total: 1 }
     },
 
@@ -78,7 +79,6 @@ export const useMerchantStore = defineStore('merchant', {
             price: 38,
             category: '面食',
             description: '这是招牌拉面',
-            image: '',
             status: true,
             spec: '大碗'
           },
@@ -88,7 +88,6 @@ export const useMerchantStore = defineStore('merchant', {
             price: 28,
             category: '小吃',
             description: '酥脆炸猪排',
-            image: '',
             status: true,
             spec: ''
           }
@@ -97,8 +96,8 @@ export const useMerchantStore = defineStore('merchant', {
       return this.products
     },
 
-    async addProduct(product: any) {
-      const newProduct = {
+    async addProduct(product: Omit<Product, 'id'>) {
+      const newProduct: Product = {
         ...product,
         id: Date.now().toString(),
         status: true
@@ -107,24 +106,19 @@ export const useMerchantStore = defineStore('merchant', {
       return newProduct
     },
 
-    async updateProduct(id: string, product: any) {
-      const index = this.products.findIndex((p: any) => p.id === id)
+    async updateProduct(id: string, product: Partial<Product>) {
+      const index = this.products.findIndex((p) => p.id === id)
       if (index > -1) {
         this.products[index] = { ...this.products[index], ...product }
       }
     },
 
     async deleteProduct(id: string) {
-      this.products = this.products.filter((p: any) => p.id !== id)
+      this.products = this.products.filter((p) => p.id !== id)
     }
   },
 
   persist: {
-    strategies: [
-      {
-        storage: localStorage,
-        paths: ['shopInfo', 'products']
-      }
-    ]
+    paths: ['shopInfo', 'products']
   }
 })

+ 57 - 0
src/types/merchant.ts

@@ -0,0 +1,57 @@
+export interface Product {
+  id: string;
+  name: string;
+  price: number;
+  category: string;
+  description: string;
+  image?: string;
+  status: boolean;
+  spec?: string;
+}
+
+export interface OrderItem {
+    id?: string;
+    name: string;
+    spec?: string;
+    quantity: number;
+    price: number; // Added price to match component usage
+}
+
+export interface Order {
+    id: string;
+    orderNo: string;
+    tableName?: string; // Optional based on context
+    guestCount?: number;
+    createTime: string | number; // Support both format and timestamp
+    startTime?: number;
+    amount: number;
+    subtotal?: number;
+    serviceCharge?: number;
+    status: 'pending' | 'preparing' | 'delivering' | 'completed' | 'cancelled';
+    items: OrderItem[];
+}
+
+export interface ShopInfo {
+    name: string;
+    isOpen: boolean;
+    hours: string;
+}
+
+export interface MerchantState {
+    shopInfo: ShopInfo;
+    todayStats: {
+        revenue: number;
+        orderCount: number;
+        takeoutCount: number;
+        dineInCount: number;
+    };
+    orderStats: {
+        pending: number;
+        preparing: number;
+        delivering: number;
+        completed: number;
+    };
+    pendingOrderCount: number;
+    orders: Order[];
+    products: Product[];
+}

+ 4 - 3
src/views/merchant/products/edit.vue

@@ -105,6 +105,7 @@ import { useRoute, useRouter } from 'vue-router'
 import { showToast, showDialog } from 'vant'
 import { useMerchantStore } from '@/store/modules/merchant'
 import { useI18n } from 'vue-i18n'
+import type { Product } from '@/types/merchant'
 
 const { t } = useI18n()
 const route = useRoute()
@@ -120,10 +121,10 @@ const categories = [
   { text: '饮料', value: '饮料' }
 ]
 
-const form = ref({
+const form = ref<Product>({
   id: '',
   name: '',
-  price: '',
+  price: 0,
   category: '',
   description: '',
   status: true,
@@ -136,7 +137,7 @@ const isEdit = computed(() => !!route.params.id)
 onMounted(async () => {
   if (isEdit.value) {
     const products = await merchantStore.getProducts()
-    const product = products.find((p: any) => p.id === route.params.id)
+    const product = products.find((p) => p.id === route.params.id)
     if (product) {
       form.value = { ...product }
     } else {

+ 4 - 3
src/views/merchant/products/list.vue

@@ -50,12 +50,13 @@ import { useRouter } from 'vue-router'
 import { showToast, showDialog } from 'vant'
 import { useMerchantStore } from '@/store/modules/merchant'
 import { useI18n } from 'vue-i18n'
+import type { Product } from '@/types/merchant'
 
 const { t } = useI18n()
 const router = useRouter()
 const merchantStore = useMerchantStore()
 
-const list = ref<any[]>([])
+const list = ref<Product[]>([])
 const loading = ref(false)
 const finished = ref(false)
 const refreshing = ref(false)
@@ -87,11 +88,11 @@ const goToCreate = () => {
   router.push('/merchant/products/create')
 }
 
-const goToEdit = (item: any) => {
+const goToEdit = (item: Product) => {
   router.push(`/merchant/products/${item.id}/edit`)
 }
 
-const confirmDelete = (item: any) => {
+const confirmDelete = (item: Product) => {
   showDialog({
     title: t('merchant.product.confirmDelete'),
     message: t('merchant.product.confirmDeleteMessage', { name: item.name }),

+ 1 - 22
src/views/pos/order-detail.vue

@@ -95,32 +95,11 @@
 import { ref, onMounted } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
 import { showToast } from 'vant'
+import type { Order } from '@/types/merchant'
 
 const route = useRoute()
 const router = useRouter()
 
-interface OrderItem {
-  id: string
-  name: string
-  spec?: string
-  quantity: number
-  price: number
-}
-
-interface Order {
-  id: string
-  orderNo: string
-  tableName: string
-  guestCount: number
-  status: 'pending' | 'preparing' | 'completed' | 'cancelled'
-  amount: number
-  subtotal: number
-  serviceCharge?: number
-  createTime: number
-  startTime: number
-  items: OrderItem[]
-}
-
 const order = ref<Order>({
   id: route.params.id as string,
   orderNo: '2024011201',