diff --git a/src/layout/components/LayoutHeader.vue b/src/layout/components/LayoutHeader.vue index 443e2af..833b074 100644 --- a/src/layout/components/LayoutHeader.vue +++ b/src/layout/components/LayoutHeader.vue @@ -35,7 +35,8 @@
- + + {{ userInitial }} {{ username }} @@ -73,8 +74,21 @@ const message = useMessage() const layoutStore = useLayoutStore() const themeStore = useThemeStore() -const username = 'SparksFly' -const userInitial = computed(() => username.charAt(0).toUpperCase()) +const username = computed(() => { + try { + const stored = localStorage.getItem('userInfo') + if (stored) return JSON.parse(stored).user_name || 'Guest' + } catch {} + return 'Guest' +}) +const userAvatar = computed(() => { + try { + const stored = localStorage.getItem('userInfo') + if (stored) return JSON.parse(stored).avatar || '' + } catch {} + return '' +}) +const userInitial = computed(() => username.value.charAt(0).toUpperCase()) const currentRouteTitle = computed(() => (route.meta?.title as string) || '') diff --git a/src/layout/components/LayoutSider.vue b/src/layout/components/LayoutSider.vue index 228b94c..8776dfe 100644 --- a/src/layout/components/LayoutSider.vue +++ b/src/layout/components/LayoutSider.vue @@ -41,7 +41,8 @@
- + + {{ userInitial }}
@@ -86,8 +87,21 @@ const message = useMessage() const layoutStore = useLayoutStore() // ─── 用户 ─── -const username = 'SparksFly' -const userInitial = computed(() => username.charAt(0).toUpperCase()) +const username = computed(() => { + try { + const stored = localStorage.getItem('userInfo') + if (stored) return JSON.parse(stored).user_name || 'Guest' + } catch {} + return 'Guest' +}) +const userAvatar = computed(() => { + try { + const stored = localStorage.getItem('userInfo') + if (stored) return JSON.parse(stored).avatar || '' + } catch {} + return '' +}) +const userInitial = computed(() => username.value.charAt(0).toUpperCase()) // ─── Icon helper ─── function renderIcon(icon: Component) { diff --git a/src/views/system/Profile.vue b/src/views/system/Profile.vue index 892e8e6..a2e7e04 100644 --- a/src/views/system/Profile.vue +++ b/src/views/system/Profile.vue @@ -9,7 +9,8 @@
- + + {{ userInitial }}