fix: 🐛 修复修改头像后没有显示最新的头像
- 移除在 permission.ts 中的冗余用户信息检查 - 刷新页面确保获取最新的用户信息 - 更新 profile 页面中用户头像的显示逻辑 - 在头像上传成功后同步更新用户信息 #ICRONO
This commit is contained in:
@@ -35,13 +35,11 @@ export function setupPermission() {
|
|||||||
const permissionStore = usePermissionStore();
|
const permissionStore = usePermissionStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
// 确保用户信息已加载
|
|
||||||
if (!userStore.userInfo.username) {
|
|
||||||
await userStore.getUserInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确保动态路由已生成
|
// 确保动态路由已生成
|
||||||
if (!permissionStore.isDynamicRoutesGenerated) {
|
if (!permissionStore.isDynamicRoutesGenerated) {
|
||||||
|
/** 先获取最新的用户信息 */
|
||||||
|
await userStore.getUserInfo();
|
||||||
|
|
||||||
const dynamicRoutes = await permissionStore.generateRoutes();
|
const dynamicRoutes = await permissionStore.generateRoutes();
|
||||||
dynamicRoutes.forEach((route: RouteRecordRaw) => {
|
dynamicRoutes.forEach((route: RouteRecordRaw) => {
|
||||||
router.addRoute(route);
|
router.addRoute(route);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<el-card class="user-card">
|
<el-card class="user-card">
|
||||||
<div class="user-info">
|
<div class="user-info">
|
||||||
<div class="avatar-wrapper">
|
<div class="avatar-wrapper">
|
||||||
<el-avatar :src="userProfile.avatar" :size="100" />
|
<el-avatar :src="userStore.userInfo.avatar" :size="100" />
|
||||||
<el-button
|
<el-button
|
||||||
type="info"
|
type="info"
|
||||||
class="avatar-edit-btn"
|
class="avatar-edit-btn"
|
||||||
@@ -227,9 +227,12 @@ import UserAPI, {
|
|||||||
} from "@/api/system/user.api";
|
} from "@/api/system/user.api";
|
||||||
|
|
||||||
import FileAPI from "@/api/file.api";
|
import FileAPI from "@/api/file.api";
|
||||||
|
import { useUserStoreHook } from "@/store";
|
||||||
|
|
||||||
import { Camera } from "@element-plus/icons-vue";
|
import { Camera } from "@element-plus/icons-vue";
|
||||||
|
|
||||||
|
const userStore = useUserStoreHook();
|
||||||
|
|
||||||
const userProfile = ref<UserProfileVO>({});
|
const userProfile = ref<UserProfileVO>({});
|
||||||
|
|
||||||
const enum DialogType {
|
const enum DialogType {
|
||||||
@@ -443,12 +446,12 @@ const handleFileChange = async (event: Event) => {
|
|||||||
// 调用文件上传API
|
// 调用文件上传API
|
||||||
try {
|
try {
|
||||||
const data = await FileAPI.uploadFile(file);
|
const data = await FileAPI.uploadFile(file);
|
||||||
// 更新用户头像
|
|
||||||
userProfile.value.avatar = data.url;
|
|
||||||
// 更新用户信息
|
// 更新用户信息
|
||||||
await UserAPI.updateProfile({
|
await UserAPI.updateProfile({
|
||||||
avatar: data.url,
|
avatar: data.url,
|
||||||
});
|
});
|
||||||
|
// 更新用户头像
|
||||||
|
userStore.userInfo.avatar = data.url;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("头像上传失败:" + error);
|
console.error("头像上传失败:" + error);
|
||||||
ElMessage.error("头像上传失败");
|
ElMessage.error("头像上传失败");
|
||||||
|
|||||||
Reference in New Issue
Block a user