mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: add username to navbar, pass title by props
This commit is contained in:
1 parent
d15a197db9
commit
89f86fad30
4 files changed
+62
-8
No files matched your search
@@ -1,9 +1,11 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
|
import { defineProps, onMounted } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useToast } from 'vue-toastification'
|
import { useToast } from 'vue-toastification'
|
||||||
import { logout } from '../utils/auth'
|
import { logout } from '../utils/auth'
|
||||||
import { bugReportUrl } from '../config'
|
import { bugReportUrl } from '../config'
|
||||||
import sessionStore, { reset } from '../store/session'
|
import { reset } from '../store/session'
|
||||||
|
import userProfileStore, { loadUserProfile } from '../store/userProfile'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -29,6 +31,22 @@ const handleMap = async () => {
|
|||||||
console.error(err)
|
console.error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
await loadUserProfile()
|
||||||
|
} catch (err) {
|
||||||
|
// toast.error('Failed to load user profile')
|
||||||
|
toast.error('無法讀取使用者資料')
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -51,9 +69,8 @@ const handleMap = async () => {
|
|||||||
id="HeaderText"
|
id="HeaderText"
|
||||||
class="text-text-primary inline-block font-bold whitespace-nowrap"
|
class="text-text-primary inline-block font-bold whitespace-nowrap"
|
||||||
style="font-size: 2vh"
|
style="font-size: 2vh"
|
||||||
v-if="sessionStore.quest"
|
|
||||||
>
|
>
|
||||||
{{ sessionStore.quest.title }}
|
{{ title }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="h-full w-full flex gap-3 items-center justify-end">
|
<div class="h-full w-full flex gap-3 items-center justify-end">
|
||||||
@@ -75,6 +92,13 @@ const handleMap = async () => {
|
|||||||
class="text-text-primary h-full w-full"
|
class="text-text-primary h-full w-full"
|
||||||
/>
|
/>
|
||||||
</button> -->
|
</button> -->
|
||||||
|
<p
|
||||||
|
id="UsernameText"
|
||||||
|
class="text-text inline-block whitespace-nowrap"
|
||||||
|
style="font-size: 2vh"
|
||||||
|
>
|
||||||
|
{{ userProfileStore.username }}
|
||||||
|
</p>
|
||||||
<button title="Map" @click="handleMap" class="h-5 w-5">
|
<button title="Map" @click="handleMap" class="h-5 w-5">
|
||||||
<font-awesome-icon
|
<font-awesome-icon
|
||||||
:icon="['fas', 'map']"
|
:icon="['fas', 'map']"
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { reactive } from 'vue'
|
||||||
|
import api from '../utils/api'
|
||||||
|
|
||||||
|
const store = reactive({
|
||||||
|
username: '',
|
||||||
|
email: '',
|
||||||
|
progress: {},
|
||||||
|
})
|
||||||
|
|
||||||
|
export async function loadUserProfile() {
|
||||||
|
try {
|
||||||
|
const res = await api.get('/users/me')
|
||||||
|
const { username, email, progress } = res.data
|
||||||
|
store.username = username
|
||||||
|
store.email = email
|
||||||
|
store.progress = progress
|
||||||
|
return store
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
throw new Error('Failed to load user profile', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetUserProfile() {
|
||||||
|
store.username = ''
|
||||||
|
store.email = ''
|
||||||
|
store.progress = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default store
|
||||||
@@ -50,7 +50,7 @@ onMounted(async () => {
|
|||||||
<template>
|
<template>
|
||||||
<!-- game header -->
|
<!-- game header -->
|
||||||
<div class="h-[6vh] w-full">
|
<div class="h-[6vh] w-full">
|
||||||
<GameHeaderPart />
|
<GameHeaderPart :title="sessionStore.quest?.title" />
|
||||||
</div>
|
</div>
|
||||||
<!-- current status indicator -->
|
<!-- current status indicator -->
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import GameHeaderPart from '../components/GameHeaderPart.vue'
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="h-[6vh] w-full">
|
<div class="h-[6vh] w-full">
|
||||||
<GameHeaderPart />
|
<GameHeaderPart title="關卡地圖" />
|
||||||
<p
|
<!-- <p
|
||||||
class="text-text-primary absolute z-1 font-bold inline-block tracking-widest"
|
class="text-text-primary absolute z-1 font-bold inline-block tracking-widest"
|
||||||
style="left: 1.2%; top: 1.5%; height: 100%; font-size: 2vh"
|
style="left: 1.2%; top: 1.5%; height: 100%; font-size: 2vh"
|
||||||
>
|
>
|
||||||
<!-- Quest Map -->
|
Quest Map
|
||||||
Unix編年史
|
Unix編年史
|
||||||
</p>
|
</p> -->
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col justify-center items-center w-full h-[94vh]">
|
<div class="flex flex-col justify-center items-center w-full h-[94vh]">
|
||||||
<QuestMap />
|
<QuestMap />
|
||||||
|
|||||||
Reference in new issue
Block a user