| | |
| | | }); |
| | | const body = res && res.data; |
| | | if (body && body.code === 200) { |
| | | // 只保留相对路径:后端返回的 url 带 host(如 http://10.136.58.73:7003/profile/...), |
| | | // 手机经端口转发或外网访问时该 host 不通,必须用 /profile/... 相对路径 |
| | | let path = body.fileName || body.url || ""; |
| | | if (/^https?:\/\//i.test(path)) { |
| | | try { |
| | | path = new URL(path).pathname; |
| | | } catch (e) { |
| | | // 解析失败就保持原值 |
| | | } |
| | | // 后端返回值有两个坑: |
| | | // fileName = "upload/2026/10/27/x.jpg"(相对 profile 目录,缺 /profile 前缀) |
| | | // url = "http://10.136.58.73upload/..."(IP 后连斜杠都没有,是坏的) |
| | | // 所以这里统一规范成 /profile/upload/... 形式:相对路径,手机经端口转发也能访问 |
| | | let path = String(body.fileName || "").replace(/^\/+/, ""); |
| | | if (path && !path.startsWith("profile/")) { |
| | | path = "profile/" + path; |
| | | } |
| | | path = path ? "/" + path : ""; |
| | | emit("update:modelValue", path); |
| | | ElMessage.success("上传成功"); |
| | | } else { |