| | |
| | | import { request } from '@umijs/max'; |
| | | import { decryptData } from '@/utils/utils'; |
| | | |
| | | export async function exportAgents(params: Record<string, string | number | undefined>) { |
| | | const query = new URLSearchParams(); |
| | | Object.entries(params).forEach(([key, value]) => { |
| | | if (value !== undefined && value !== '') query.append(key, String(value)); |
| | | }); |
| | | const response = await fetch(`${BASE_URL}/provincial-agents/export?${query.toString()}`, { |
| | | headers: { Authorization: decryptData(localStorage.getItem('token')) || '' }, |
| | | }); |
| | | // 鉴权失败可能返回 HTTP 200 的 JSON,不能误下载为 Excel。 |
| | | if (response.headers.get('content-type')?.includes('application/json')) { |
| | | const result = await response.json(); |
| | | throw new Error(result.msg || '导出失败,请检查登录状态和权限'); |
| | | } |
| | | if (!response.ok) throw new Error('导出失败,请稍后重试'); |
| | | return response.blob(); |
| | | } |
| | | |
| | | export const getAgentPage=(params:any)=>request('/provincial-agents',{method:'GET',params}); |
| | | export const getAgentDetail=(id:number|string)=>request(`/provincial-agents/${id}`,{method:'GET'}); |
| | | export const createAgent=(data:any)=>request('/provincial-agents',{method:'POST',data}); |