- 新增 PaymentCountdown、ProductImage 组件 - 完善 checkout/orders/orderDetail 订单支付链路与地址、商品、设计数据 - request 接口地址改为构建期注入并保留真实网络错误,默认兜底线上地址 - 同步重新构建 dist 产物
61 lines
3.0 KiB
TypeScript
61 lines
3.0 KiB
TypeScript
import http from '../request'
|
|
import type { DesignDataV1, DesignItem } from '../../types'
|
|
import { getProductIconImg } from '../productConfig'
|
|
|
|
type ServerEntry = { productId: string; productName: string; unitPrice: number; count: number; designData?: DesignDataV1 }
|
|
type ServerList = { id: string; title: string; items: ServerEntry[]; status: 'DRAFT' | 'SUBMITTED' | 'PROCESSING' | 'DONE'; orderId?: string; createdAt: string }
|
|
|
|
const statusToClient = (item: ServerList): DesignItem['status'] => {
|
|
if (item.orderId || item.status === 'DONE') return 'ordered'
|
|
if (item.status === 'PROCESSING') return 'processing'
|
|
if (item.status === 'DRAFT') return 'undesigned'
|
|
return 'designing'
|
|
}
|
|
|
|
const statusToServer = (status: DesignItem['status']) =>
|
|
status === 'undesigned' ? 'DRAFT' : status === 'designing' ? 'SUBMITTED' : status === 'processing' ? 'PROCESSING' : 'DONE'
|
|
|
|
const toClient = (list: ServerList): DesignItem => {
|
|
const item = list.items[0]
|
|
return {
|
|
id: list.id,
|
|
productId: item.productId,
|
|
productName: item.productName,
|
|
productIcon: getProductIconImg({ id: item.productId }),
|
|
unitPrice: Number(item.unitPrice),
|
|
count: item.count,
|
|
status: statusToClient(list),
|
|
designData: item.designData,
|
|
orderId: list.orderId,
|
|
createdAt: list.createdAt,
|
|
}
|
|
}
|
|
|
|
export async function fetchDesignList(): Promise<DesignItem[]> {
|
|
const rows = await http.get<ServerList[]>('/api/design-list')
|
|
return rows.filter(row => row.items?.length > 0).map(toClient)
|
|
}
|
|
|
|
export async function fetchDesign(id: string): Promise<DesignItem> {
|
|
return toClient(await http.get<ServerList>(`/api/design-list/${id}`))
|
|
}
|
|
|
|
export async function createDesign(item: Omit<DesignItem, 'id' | 'createdAt' | 'status' | 'productIcon'>): Promise<DesignItem> {
|
|
return toClient(await http.post<ServerList>('/api/design-list', { title: item.productName, items: [{ productId: item.productId, productName: item.productName, unitPrice: item.unitPrice, count: item.count, designData: item.designData }] }))
|
|
}
|
|
|
|
export async function updateDesign(id: string, patch: Partial<DesignItem>): Promise<DesignItem> {
|
|
const current = await fetchDesign(id)
|
|
const merged = { ...current, ...patch }
|
|
const data: Record<string, unknown> = {}
|
|
if (patch.designData !== undefined || patch.productId !== undefined || patch.productName !== undefined || patch.unitPrice !== undefined || patch.count !== undefined) {
|
|
data.items = [{ productId: merged.productId, productName: merged.productName, unitPrice: merged.unitPrice, count: merged.count, designData: merged.designData }]
|
|
}
|
|
if (patch.productName !== undefined) data.title = patch.productName
|
|
if (patch.status !== undefined) data.status = statusToServer(patch.status)
|
|
return toClient(await http.patch<ServerList>(`/api/design-list/${id}`, data))
|
|
}
|
|
|
|
export async function deleteDesign(id: string): Promise<void> { await http.del(`/api/design-list/${id}`) }
|
|
export async function deleteDesigns(ids: string[]): Promise<void> { await http.post('/api/design-list/batch-delete', { ids }) }
|