import axios from 'axios' const http = axios.create({ baseURL: import.meta.env.VITE_API_BASE || '', headers: { 'Content-Type': 'application/json' }, timeout: 120000, }) export async function post(path, body = {}, axiosConfig = {}) { const { data } = await http.post(path, body, axiosConfig) return data } export async function get(path, params = {}, axiosConfig = {}) { const { data } = await http.get(path, { ...axiosConfig, params }) return data } export function formatApiError(err, fallback = '请求失败') { const d = err?.response?.data if (typeof d?.message === 'string' && d.message.trim()) return d.message if (typeof d === 'string' && d.trim()) return d return err?.message || fallback } export default http