refactor: 统一静态资源地址拼接为 utils/asset-url,解除更新模块对应用模块的反向依赖

This commit is contained in:
tongtong committed 2026-11-04 17:39:28 +08:00
1 parent 8c1e02e6d0
commit b8773a0e78
9 files changed
+47 -72

No files matched your search

+3 -15
View File
@@ -81,7 +81,7 @@
<el-table-column label="图标" width="100" align="center">
<template #default="scope">
<el-image
:src="resolveIconUrl(scope.row.iconUrl)"
:src="withBase(scope.row.iconUrl)"
fit="contain"
style="width: 48px; height: 48px; border-radius: 6px"
:preview-src-list="previewList"
@@ -236,6 +236,7 @@ import {
import { usePageTable } from "@/composables";
import AppIconAPI from "@/api/device/appIcon";
import type { AppIconQuery, AppIconVO } from "@/api/device/types";
import { withBase } from "@/utils/asset-url";
defineOptions({
name: "AppIcon",
@@ -275,25 +276,12 @@ function handleCurrentChange(row: AppIconVO | null) {
selectedRow.value = row;
}
const previewList = computed(() => list.value.map((item) => resolveIconUrl(item.iconUrl)));
const previewList = computed(() => list.value.map((item) => withBase(item.iconUrl)));
const previewIndex = (row: AppIconVO) => {
const idx = list.value.findIndex((item) => item.id === row.id);
return idx < 0 ? 0 : idx;
};
/**
* 拼接图标完整访问地址
* 后端返回的是相对路径(如 /static/app_icon/{md5}.png)。
* el-image 的 src 是浏览器原生请求,不经过 axios,拿不到 baseURL,
* 因此必须手动补上代理前缀(VITE_APP_BASE_API),否则请求会打到前端 dev server 上导致 404。
*/
function resolveIconUrl(url?: string | null): string {
if (!url) return "";
if (/^(https?:)?\/\//.test(url) || url.startsWith("data:")) return url;
const baseApi = import.meta.env.VITE_APP_BASE_API ?? "";
return `${baseApi.replace(/\/$/, "")}${url.startsWith("/") ? "" : "/"}${url}`;
}
function validateUploadFile(file: UploadRawFile) {
const allowExt = ["jpg", "jpeg", "png", "webp"];
const ext = file.name.split(".").pop()?.toLowerCase() || "";