图片路径调整

This commit is contained in:
dzl
2025-09-02 17:05:49 +08:00
parent 80ddefec0f
commit 8d50c6dadf
14 changed files with 144 additions and 73 deletions

View File

@@ -64,7 +64,7 @@
<div class="balance-item">
<span class="balance-label">我的融豆</span>
<div class="balance-content">
<img src="/imgs/profile/融豆.png" alt="融豆" class="bean-image">
<img :src="getImageUrl('/imgs/profile/融豆.png')" alt="融豆" class="bean-image">
<div class="balance-value">{{ Math.abs(accountInfo.balance) }}</div>
</div>
</div>
@@ -137,6 +137,7 @@ import { useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import { User, Plus } from '@element-plus/icons-vue';
import api from '@/utils/api';
import { getImageUrl } from '@/config';
export default {
setup() {
@@ -144,6 +145,7 @@ export default {
const router = useRouter();
const avatarUrl = ref('');
const newAvatar = ref('');
const uploadedAvatarData = ref(null);
const showAvatarUpload = ref(false);
const accountInfo = ref({ balance: '0.00', is_distribute: false });
const isLoading = ref(false);
@@ -177,10 +179,12 @@ export default {
};
// 确保加载头像
if (response.data.user?.avatar) {
avatarUrl.value = response.data.data.avatar;
// 使用getImageUrl处理头像路径
const processedAvatarUrl = getImageUrl(response.data.user.avatar);
avatarUrl.value = processedAvatarUrl;
// 更新store中的头像
if(userStore.user) {
userStore.setUserAvatar(response.data.data.avatar);
userStore.setUserAvatar(processedAvatarUrl);
}
}
}
@@ -258,7 +262,10 @@ export default {
});
if (response.data.success) {
newAvatar.value = response.data.url;
// 保存上传响应数据
uploadedAvatarData.value = response.data.data;
// 使用url作为显示地址
newAvatar.value = response.data.data.url;
ElMessage.success('头像上传成功');
} else {
ElMessage.error(response.data.message || '上传失败');
@@ -272,26 +279,30 @@ export default {
// 确认更新头像
const confirmAvatarUpload = async () => {
try {
if (!newAvatar.value) {
if (!newAvatar.value || !uploadedAvatarData.value) {
ElMessage.error('请先选择头像');
return;
}
// 使用path提交给后端
const avatarPath = uploadedAvatarData.value.path;
const response = await api.put('/user/profile', {
avatar: newAvatar.value
avatar: avatarPath
});
if (response.data.success) {
avatarUrl.value = newAvatar.value;
// 更新用户store中的头像信息 - 修改这里
// 使用url作为显示地址
avatarUrl.value = uploadedAvatarData.value.url;
// 更新用户store中的头像信息
if(userStore.user) {
userStore.setUser({
...userStore.user,
avatar: newAvatar.value
avatar: uploadedAvatarData.value.url
});
}
showAvatarUpload.value = false;
newAvatar.value = '';
uploadedAvatarData.value = null;
ElMessage.success('头像更新成功');
} else {
ElMessage.error(response.data.message || '头像更新失败');
@@ -334,6 +345,7 @@ export default {
avatarUrl,
newAvatar,
showAvatarUpload,
uploadedAvatarData,
accountInfo,
isLoading,
functionItems,
@@ -343,7 +355,8 @@ export default {
confirmAvatarUpload,
handleLogout,
handleDistributeChange,
userStore
userStore,
getImageUrl
};
}
};