request.ts 860 Bytes
const BASE = '/api';

export async function request<T>(path: string, init?: RequestInit): Promise<T> {
  const res = await fetch(`${BASE}${path}`, {
    headers: { 'Content-Type': 'application/json' },
    ...init,
  });
  if (!res.ok) throw new Error(`请求失败: ${res.status}`);
  return res.json() as Promise<T>;
}

// 门店上架 Excel 导入:前端仅上传文件,
// 解析与《【优加】门店上架模版-V1.0.1.xlsx》模板版本一致性校验由后端完成。
export async function uploadStoreTemplate(file: File): Promise<{ taskId: string }> {
  const form = new FormData();
  form.append('file', file);
  form.append('templateVersion', 'V1.0.1');
  const res = await fetch(`${BASE}/store-import`, { method: 'POST', body: form });
  if (!res.ok) throw new Error('导入失败,请检查文件与模板版本');
  return res.json();
}