import { request } from '@/api'; // 引入你已封装的request /** * 图片上传接口(适配富文本编辑器) * @param file 要上传的文件对象 * @returns Promise<{ url: string }> 图片上传后的URL */ export const uploadImageApi = (file: File): Promise<{ url: string }> => { // 构建FormData(图片上传必须用FormData格式) const formData = new FormData(); formData.append('image', file); // 对应后端接收字段名image // 使用你已封装的post请求,禁用loading(富文本自身有状态提示) return request.post<{ url: string }>( '/upload/image', formData, { // 覆盖默认配置:图片上传需要特殊的请求头 headers: { 'Content-Type': 'multipart/form-data', // 表单上传必须的头 showLoading: false // 禁用全局loading,避免和编辑器loading冲突 }, timeout: 30 * 1000, // 图片上传超时时间30秒 noRetry: false // 允许重试(网络波动时自动重试) } ); };