|
1 | 1 | <script setup lang="ts"> |
| 2 | +import { ref, onMounted, onUnmounted, computed } from 'vue' |
| 3 | +import { Icon } from '@iconify/vue' |
| 4 | +import { achievements } from '../data/AchievementsData'; |
| 5 | +
|
| 6 | +const player = ref({ |
| 7 | + avatar: '/assets/小啄_02.png', |
| 8 | + nickname: '鱈魚', |
| 9 | + title: '新手小啄', |
| 10 | + points: 0, |
| 11 | + achievements: achievements, |
| 12 | +}); |
| 13 | +
|
| 14 | +const availableTitles = computed(() => { |
| 15 | + const titles = [{ id: 0, label: '新手小啄', icon: '' }]; |
| 16 | + player.value.achievements.forEach(achievement => { |
| 17 | + if (achievement.unlocked) { |
| 18 | + titles.push({ |
| 19 | + id: achievement.id, |
| 20 | + label: achievement.label, |
| 21 | + icon: achievement.icon |
| 22 | + }); |
| 23 | + } |
| 24 | + }); |
| 25 | + return titles; |
| 26 | +}); |
| 27 | +
|
| 28 | +// This is for test |
| 29 | +const handleKeydown = (event: KeyboardEvent) => { |
| 30 | + const key = parseInt(event.key); |
| 31 | + if (key >= 1 && key <= player.value.achievements.length) { |
| 32 | + const medalToUnlock = player.value.achievements.find(m => m.id === key); |
| 33 | + if (medalToUnlock && !medalToUnlock.unlocked) { |
| 34 | + medalToUnlock.unlocked = true; |
| 35 | + } |
| 36 | + } |
| 37 | +}; |
| 38 | +
|
| 39 | +onMounted(() => { |
| 40 | + window.addEventListener('keydown', handleKeydown); |
| 41 | +}); |
| 42 | +
|
| 43 | +onUnmounted(() => { |
| 44 | + window.removeEventListener('keydown', handleKeydown); |
| 45 | +}); |
2 | 46 | </script> |
3 | 47 |
|
4 | 48 | <template> |
5 | | - <main id="myProfile"> |
6 | | - <h2>我的資料</h2> |
7 | | - </main> |
| 49 | + <div id="myProfile"> |
| 50 | + <div class="avatar-section"> |
| 51 | + <div class="avatar-container"> |
| 52 | + <img :src="player.avatar" alt="Player Avatar" class="avatar-image"> |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + |
| 56 | + <div class="info-section"> |
| 57 | + <div class="display-score">{{ player.points }} 分</div> |
| 58 | + <div class="nickname-container"> |
| 59 | + <span class="display-nickname">{{ player.nickname }}</span> |
| 60 | + </div> |
| 61 | + |
| 62 | + <div class="title-container"> |
| 63 | + <select v-model="player.title" class="title-select"> |
| 64 | + <option v-for="title in availableTitles" :key="title.id" :value="title.label"> |
| 65 | + {{ title.label }} |
| 66 | + </option> |
| 67 | + </select> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + |
| 71 | + <div class="scrollable-content"> |
| 72 | + <div class="achievements-section"> |
| 73 | + <h3>成就</h3> |
| 74 | + <div class="achievements-grid"> |
| 75 | + <div v-for="medal in player.achievements" :key="medal.id" class="medal-item"> |
| 76 | + <Icon :icon="medal.icon" class="medal-icon" :style="{ color: medal.unlocked ? '#F8C0C8' : '#888' }" /> |
| 77 | + <span class="medal-label">{{ medal.unlocked ? medal.label : '???' }}</span> |
| 78 | + </div> |
| 79 | + </div> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + </div> |
8 | 83 | </template> |
9 | 84 |
|
10 | 85 | <style scoped> |
| 86 | +#myProfile { |
| 87 | + width: 100%; |
| 88 | + height: 100%; |
| 89 | + background-color: #fbfaf2; |
| 90 | + display: flex; |
| 91 | + flex-direction: column; |
| 92 | + align-items: center; |
| 93 | + padding: 35px 20px 20px 20px; |
| 94 | + box-sizing: border-box; |
| 95 | +} |
| 96 | +
|
| 97 | +.avatar-section { |
| 98 | + display: flex; |
| 99 | + flex-direction: column; |
| 100 | + align-items: center; |
| 101 | + margin-bottom: 5px; |
| 102 | + flex-shrink: 0; |
| 103 | +} |
| 104 | +
|
| 105 | +.avatar-container { |
| 106 | + width: 150px; |
| 107 | + height: 150px; |
| 108 | + border-radius: 50%; |
| 109 | + background-color: #e0e6ec; |
| 110 | + display: flex; |
| 111 | + justify-content: center; |
| 112 | + align-items: center; |
| 113 | + overflow: hidden; |
| 114 | + border: 4px solid #fff; |
| 115 | + box-shadow: 0 0 0 2px #c9d2da; |
| 116 | + position: relative; |
| 117 | +} |
| 118 | +
|
| 119 | +.avatar-image { |
| 120 | + width: 100%; |
| 121 | + height: 90%; |
| 122 | + object-fit: cover; |
| 123 | + border-radius: 50%; |
| 124 | + transform: translateY(5px) translateX(3px); |
| 125 | +} |
| 126 | +
|
| 127 | +.info-section { |
| 128 | + width: 100%; |
| 129 | + display: flex; |
| 130 | + flex-direction: column; |
| 131 | + gap: 10px; |
| 132 | + margin-bottom: 20px; |
| 133 | + flex-shrink: 0; |
| 134 | +} |
| 135 | +
|
| 136 | +.display-score { |
| 137 | + font-size: 15px; |
| 138 | + font-family: 'Zen Maru Gothic', sans-serif; |
| 139 | + font-weight: bold; |
| 140 | + color: #4a4a4a; |
| 141 | + text-align: center; |
| 142 | + width: 100%; |
| 143 | +} |
| 144 | +
|
| 145 | +.nickname-container { |
| 146 | + display: flex; |
| 147 | + justify-content: center; |
| 148 | + align-items: center; |
| 149 | + height: 25px; |
| 150 | +} |
| 151 | +
|
| 152 | +.display-nickname { |
| 153 | + font-size: 20px; |
| 154 | + font-family: 'Zen Maru Gothic', sans-serif; |
| 155 | + font-weight: bold; |
| 156 | + color: #333; |
| 157 | +} |
| 158 | +
|
| 159 | +.title-container { |
| 160 | + background-color: #e6eef4; |
| 161 | + border-radius: 25px; |
| 162 | + padding: 10px 15px; |
| 163 | + display: flex; |
| 164 | + align-items: center; |
| 165 | + justify-content: center; |
| 166 | +} |
| 167 | +
|
| 168 | +.title-select { |
| 169 | + flex-grow: 1; |
| 170 | + border: none; |
| 171 | + background: transparent; |
| 172 | + outline: none; |
| 173 | + font-size: 16px; |
| 174 | + font-family: 'Zen Maru Gothic', sans-serif; |
| 175 | + color: #333; |
| 176 | + -webkit-appearance: none; |
| 177 | + -moz-appearance: none; |
| 178 | + appearance: none; |
| 179 | + cursor: pointer; |
| 180 | + text-align: center; |
| 181 | +} |
| 182 | +
|
| 183 | +.title-container::after { |
| 184 | + content: '▼'; |
| 185 | + position: absolute; |
| 186 | + right: 15px; |
| 187 | + color: #888; |
| 188 | + font-size: 12px; |
| 189 | + pointer-events: none; |
| 190 | +} |
| 191 | +
|
| 192 | +.title-container { |
| 193 | + position: relative; |
| 194 | +} |
| 195 | +
|
| 196 | +.scrollable-content { |
| 197 | + flex-grow: 1; |
| 198 | + overflow-y: auto; |
| 199 | + width: 100%; |
| 200 | + padding-right: 5px; |
| 201 | + box-sizing: border-box; |
| 202 | +} |
| 203 | +
|
| 204 | +.achievements-section { |
| 205 | + padding: 0; |
| 206 | + box-sizing: border-box; |
| 207 | + text-align: center; |
| 208 | + position: relative; |
| 209 | + margin-top: 0; |
| 210 | + box-shadow: none; |
| 211 | +} |
| 212 | +
|
| 213 | +.achievements-section h3 { |
| 214 | + font-size: 20px; |
| 215 | + font-family: 'Zen Maru Gothic', sans-serif; |
| 216 | + font-weight: bold; |
| 217 | + color: #4A4A4A; |
| 218 | + margin-top: 0; |
| 219 | + margin-bottom: 15px; |
| 220 | + letter-spacing: 2px; |
| 221 | +} |
| 222 | +
|
| 223 | +.achievements-grid { |
| 224 | + display: grid; |
| 225 | + grid-template-columns: repeat(3, 1fr); |
| 226 | + gap: 15px; |
| 227 | + justify-items: center; |
| 228 | + margin-bottom: 70px; |
| 229 | +} |
| 230 | +
|
| 231 | +.medal-item { |
| 232 | + width: 80px; |
| 233 | + height: 80px; |
| 234 | + display: flex; |
| 235 | + flex-direction: column; |
| 236 | + justify-content: center; |
| 237 | + align-items: center; |
| 238 | + gap: 5px; |
| 239 | +} |
| 240 | +
|
| 241 | +.medal-icon { |
| 242 | + font-size: 48px; |
| 243 | + /* color: #F8C0C8; */ |
| 244 | +} |
| 245 | +
|
| 246 | +.medal-label { |
| 247 | + font-size: 12px; |
| 248 | + font-family: 'Zen Maru Gothic', sans-serif; |
| 249 | + color: #555; |
| 250 | + text-align: center; |
| 251 | + white-space: nowrap; |
| 252 | + overflow: hidden; |
| 253 | + text-overflow: ellipsis; |
| 254 | +} |
11 | 255 |
|
| 256 | +input:focus { |
| 257 | + outline: none; |
| 258 | +} |
12 | 259 | </style> |
0 commit comments