diff --git a/backend/src/main/java/com/zl/mjga/controller/IdentityAccessController.java b/backend/src/main/java/com/zl/mjga/controller/IdentityAccessController.java index d717cf0..da08a31 100644 --- a/backend/src/main/java/com/zl/mjga/controller/IdentityAccessController.java +++ b/backend/src/main/java/com/zl/mjga/controller/IdentityAccessController.java @@ -48,7 +48,7 @@ public class IdentityAccessController { produces = MediaType.TEXT_PLAIN_VALUE) public String uploadAvatar(Principal principal, @RequestPart("file") MultipartFile multipartFile) throws Exception { - String objectName = String.format("avatar/%s/avatar.jpg", principal.getName()); + String objectName = String.format("/avatar/%s/avatar.jpg", principal.getName()); if (multipartFile.isEmpty()) { throw new BusinessException("上传的文件不能为空"); } diff --git a/frontend/.env b/frontend/.env index d076a73..e805a63 100644 --- a/frontend/.env +++ b/frontend/.env @@ -3,12 +3,12 @@ VITE_SOURCE_MAP=true # mock #VITE_ENABLE_MOCK=true #VITE_BASE_URL=http://localhost:5173 -#VITE_STATIC_URL=http://localhost:5173/static +#VITE_STATIC_URL=http://localhost:9000/zhilu # local VITE_ENABLE_MOCK=false VITE_BASE_URL=http://localhost:8080 -VITE_STATIC_URL=http://localhost:8080/static +VITE_STATIC_URL=http://localhost:9000/zhilu # dev #VITE_ENABLE_MOCK=false #VITE_BASE_URL=https://localhost/api -#VITE_STATIC_URL=https://localhost/ +#VITE_STATIC_URL=https://localhost/static diff --git a/frontend/env.d.ts b/frontend/env.d.ts index af756f6..5e95224 100644 --- a/frontend/env.d.ts +++ b/frontend/env.d.ts @@ -9,6 +9,7 @@ interface ImportMetaEnv { readonly VITE_ENABLE_MOCK: "true" | "false"; readonly VITE_BACKEND_PORT: string; readonly VITE_BASE_URL: string; + readonly VITE_STATIC_URL: string; readonly VITE_SOURCE_MAP: "true" | "false"; } diff --git a/frontend/src/utils/avatarUtil.ts b/frontend/src/utils/avatarUtil.ts new file mode 100644 index 0000000..75f3ec0 --- /dev/null +++ b/frontend/src/utils/avatarUtil.ts @@ -0,0 +1,5 @@ +export const getUserAvatarUrl = (avatar?: string): string | undefined => { + if (avatar?.startsWith("/")) { + return `${import.meta.env.VITE_STATIC_URL}${avatar}`; + } +}; diff --git a/frontend/src/views/UserView.vue b/frontend/src/views/UserView.vue index 642224f..ca8288c 100644 --- a/frontend/src/views/UserView.vue +++ b/frontend/src/views/UserView.vue @@ -21,7 +21,12 @@