f382c27200
后台新增「数据概览」(商品/合格/按状态/品牌/分类/待审核) 与「操作日志」(全局审计分页);商品列表支持多选批量改状态/分类。公开首页标题改为「天工」并展示合格档案数;新增公开接口 /api/v1/stats 与后台 /api/stats、/api/audit、/api/products/bulk。合格口径=quality_score≥0.6 且在用。 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import type { Category, Product, ProductSummary, SubmissionInput } from "./types";
|
|
|
|
async function req<T>(path: string, init?: RequestInit): Promise<T> {
|
|
const res = await fetch(path, {
|
|
...init,
|
|
headers: { "Content-Type": "application/json", ...(init?.headers || {}) },
|
|
});
|
|
if (!res.ok) {
|
|
let msg = `请求失败 (${res.status})`;
|
|
try {
|
|
const body = await res.json();
|
|
if (body?.error?.message) msg = body.error.message;
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
throw new Error(msg);
|
|
}
|
|
return res.json() as Promise<T>;
|
|
}
|
|
|
|
export interface SearchResult {
|
|
items: ProductSummary[];
|
|
page: number;
|
|
size: number;
|
|
total: number;
|
|
}
|
|
|
|
export interface SearchFilters {
|
|
brand?: string;
|
|
country?: string;
|
|
}
|
|
|
|
export interface Stats {
|
|
total: number;
|
|
qualified: number;
|
|
min_score: number;
|
|
}
|
|
|
|
export const api = {
|
|
stats: () => req<Stats>(`/api/v1/stats`),
|
|
search: (q: string, page = 1, size = 20, filters: SearchFilters = {}) => {
|
|
const params = new URLSearchParams({
|
|
q,
|
|
page: String(page),
|
|
size: String(size),
|
|
});
|
|
if (filters.brand) params.set("brand", filters.brand);
|
|
if (filters.country) params.set("country", filters.country);
|
|
return req<SearchResult>(`/api/v1/products/search?${params.toString()}`);
|
|
},
|
|
product: (id: string) => req<Product>(`/api/v1/products/${id}`),
|
|
categories: () => req<{ items: Category[] }>(`/api/v1/categories`),
|
|
submit: (input: SubmissionInput) =>
|
|
req<{ id: string; status: string }>(`/api/public/submissions`, {
|
|
method: "POST",
|
|
body: JSON.stringify(input),
|
|
}),
|
|
};
|