/** * 文件 URL 处理 * 将后端返回的相对路径转为通过代理访问的 URL */ /** 文件代理基础路径 */ export function useFileUrl() { const _config = useRuntimeConfig() /** * 将文件路径转为可访问的 URL * - 完整 URL(http/https)直接返回 * - 相对路径通过 /api/file/ 代理 */ function fileUrl(path?: string | null): string { if (!path) return '' // 完整 URL 直接返回 if (path.startsWith('http://') || path.startsWith('https://')) { return path } // 相对路径通过代理 const cleanPath = path.startsWith('/') ? path.slice(1) : path return `/api/file/${cleanPath}` } return { fileUrl } }