供应商画像直接展示后端统一计算的基础分、频次风险系数和供应商得分;对齐对话卡片数据;未归类品类固定灰色展示并保留待补标记录;隐藏无推荐数据的代工厂模块;增加页面缓存、资源预加载、接口缓存和重复请求去重。
72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
import {
|
|
createStandard,
|
|
fetchStandard,
|
|
fetchStandards,
|
|
updateStandard,
|
|
} from "@/api/standards";
|
|
import type {
|
|
StandardRuleCreate,
|
|
StandardRuleDetail,
|
|
StandardRuleListData,
|
|
StandardRuleUpdate,
|
|
} from "@/types/standards";
|
|
|
|
const CACHE_TTL_MS = 30_000;
|
|
const cache = new Map<string, { data: StandardRuleListData; at: number }>();
|
|
const pending = new Map<string, Promise<StandardRuleListData>>();
|
|
|
|
export async function getStandards(params: {
|
|
keyword?: string;
|
|
category?: string;
|
|
status?: string;
|
|
page?: number;
|
|
pageSize?: number;
|
|
}): Promise<StandardRuleListData> {
|
|
const key = JSON.stringify(params);
|
|
const cached = cache.get(key);
|
|
if (cached && Date.now() - cached.at < CACHE_TTL_MS) return cached.data;
|
|
const running = pending.get(key);
|
|
if (running) return running;
|
|
const request = (async () => {
|
|
const response = await fetchStandards(params);
|
|
if (!response.data.data) throw new Error("标准库响应为空");
|
|
cache.set(key, { data: response.data.data, at: Date.now() });
|
|
return response.data.data;
|
|
})();
|
|
pending.set(key, request);
|
|
try {
|
|
return await request;
|
|
} finally {
|
|
pending.delete(key);
|
|
}
|
|
}
|
|
|
|
export function clearStandardsCache() {
|
|
cache.clear();
|
|
}
|
|
|
|
export async function getStandard(ruleId: number): Promise<StandardRuleDetail> {
|
|
const response = await fetchStandard(ruleId);
|
|
if (!response.data.data) throw new Error("标准详情响应为空");
|
|
return response.data.data;
|
|
}
|
|
|
|
export async function addStandard(
|
|
payload: StandardRuleCreate,
|
|
): Promise<StandardRuleDetail> {
|
|
const response = await createStandard(payload);
|
|
if (!response.data.data) throw new Error("新增标准响应为空");
|
|
clearStandardsCache();
|
|
return response.data.data;
|
|
}
|
|
|
|
export async function editStandard(
|
|
ruleId: number,
|
|
payload: StandardRuleUpdate,
|
|
): Promise<StandardRuleDetail> {
|
|
const response = await updateStandard(ruleId, payload);
|
|
if (!response.data.data) throw new Error("修改标准响应为空");
|
|
clearStandardsCache();
|
|
return response.data.data;
|
|
}
|