JewelryMall/miniprogram/api/product.ts
2026-03-02 23:35:11 +08:00

23 lines
1003 B
TypeScript

import { get, post } from '../utils/request'
import type { Product, Category, DetailParameterConfig, SpecData } from '../types'
/** 获取商品列表 */
export const getProducts = (params?: { categoryId?: number; page?: number; pageSize?: number; keyword?: string }) =>
get<{ list: Product[]; total: number }>('/api/products', params as Record<string, unknown>)
/** 获取商品详情 */
export const getProductDetail = (id: number) =>
get<Product>(`/api/products/${id}`)
/** 获取商品详细参数选项 */
export const getProductSpecs = (id: number) =>
get<DetailParameterConfig>(`/api/products/${id}/specs`)
/** 根据参数组合获取规格数据列表 */
export const getSpecDataList = (id: number, params?: { fineness?: string; mainStone?: string; ringSize?: string }) =>
post<SpecData[]>(`/api/products/${id}/spec-data`, (params || {}) as unknown as Record<string, unknown>)
/** 获取商品分类列表 */
export const getCategories = () =>
get<Category[]>('/api/categories')