yyb
2026-04-28 6ff219555c53c37d4daae0747751043ea103af1e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import config from "@/config.js";
 
// 统一文件预览地址转换(对齐 inspectionUpload 的 normalizeFileUrl 规则)
export const normalizeFileUrl = (rawUrl = "") => {
  let fileUrl = rawUrl || "";
  if (typeof fileUrl === "string") {
    fileUrl = fileUrl.trim().replace(/^['"]|['"]$/g, "");
  }
  const javaApi = config.fileUrl || config.baseUrl || "";
  const localPrefixes = ["wxfile://", "file://", "content://", "blob:", "data:"];
 
  if (localPrefixes.some(prefix => String(fileUrl).startsWith(prefix))) {
    return fileUrl;
  }
 
  if (fileUrl && String(fileUrl).indexOf("\\") > -1) {
    const lowerPath = String(fileUrl).toLowerCase();
    const uploadPathIndex = lowerPath.indexOf("uploadpath");
    const prodIndex = lowerPath.indexOf("\\prod\\");
    const tempIndex = lowerPath.indexOf("\\temp\\");
 
    if (uploadPathIndex > -1) {
      fileUrl = String(fileUrl).substring(uploadPathIndex).replace(/\\/g, "/");
    } else if (prodIndex > -1) {
      const relative = String(fileUrl)
        .substring(prodIndex + "\\prod\\".length)
        .replace(/\\/g, "/");
      fileUrl = `/profile/prod/${relative}`;
    } else if (tempIndex > -1) {
      const relative = String(fileUrl)
        .substring(tempIndex + "\\temp\\".length)
        .replace(/\\/g, "/");
      fileUrl = `/profile/temp/${relative}`;
    } else {
      fileUrl = String(fileUrl).replace(/\\/g, "/");
    }
  }
 
  // /javaWork/.../file/prod/xxx -> /profile/prod/xxx
  const normalizedLower = String(fileUrl).toLowerCase();
  const fileProdIdx = normalizedLower.indexOf("/file/prod/");
  if (fileProdIdx > -1) {
    fileUrl = `/profile/prod/${String(fileUrl).substring(
      fileProdIdx + "/file/prod/".length
    )}`;
  }
 
  // /javaWork/.../file/temp/xxx -> /profile/temp/xxx
  const fileTempIdx = normalizedLower.indexOf("/file/temp/");
  if (fileTempIdx > -1) {
    fileUrl = `/profile/temp/${String(fileUrl).substring(
      fileTempIdx + "/file/temp/".length
    )}`;
  }
 
  if (/^\/?uploadPath/i.test(String(fileUrl))) {
    fileUrl = String(fileUrl).replace(/^\/?uploadPath/i, "/profile");
  }
 
  if (fileUrl && !String(fileUrl).startsWith("http")) {
    if (!String(fileUrl).startsWith("/")) fileUrl = "/" + fileUrl;
    fileUrl = javaApi + fileUrl;
  }
 
  return fileUrl;
};