用戶頭像

載入中...

等級 0
經驗值 0 / 0
0
對戰場次
0
勝利場次
0%
勝率
0
方塊數量
#0
排名
0
0
載入中...

載入方塊收藏中...

方塊收集進度

元素收集
電擊型
0/0
火焰型
0/0
水流型
0/0
大地型
0/0
暗影型
0/0
稀有度統計
普通
0/0
稀有
0/0
史詩
0/0
傳說
0/0
載入中...

載入技能庫中...

技能組合推薦

最佳搭配

選擇一個方塊以查看最佳技能組合

熱門組合
載入中...

載入成就數據中...

載入中...

載入對戰歷史中...

好友列表

載入好友列表中...

社交分享
社交平台連結
// 加載對戰歷史 function loadBattleHistory() { console.log('正在獲取對戰歷史...'); RequestUtil.get('/api/battles/history') .then(response => { if (!response.ok) { throw new Error('獲取對戰歷史失敗: ' + response.status + ' ' + response.statusText); } // 檢查內容類型 const contentType = response.headers.get('content-type'); if (!contentType || !contentType.includes('application/json')) { throw new Error('伺服器返回了非JSON格式的數據,可能是API路徑錯誤或認證問題'); } return response.json(); }) .then(data => { console.log('獲取對戰歷史成功:', data); if (data.success && data.data && data.data.battles) { const battles = data.data.battles; const battlesContainer = document.querySelector('#battle-history'); // 清空現有對戰歷史 battlesContainer.innerHTML = '

最近對戰

'; if (battles.length === 0) { battlesContainer.innerHTML += '
暫無對戰記錄
'; return; } // 添加對戰歷史 battles.forEach(battle => { // 使用資料庫中的實際數據 const battleHTML = `
${battle.isWin ? '勝利' : '失敗'}
對手: ${battle.opponent.name}
使用方塊: ${battle.userBlock.name} 對手方塊: ${battle.opponentBlock.name} ${new Date(battle.date).toLocaleString()}
獲得點數: ${battle.rewards ? battle.rewards.points : 0} 獲得經驗: ${battle.rewards ? battle.rewards.experience : 0} 對戰時長: ${battle.duration ? Math.floor(battle.duration / 60) + '分' + (battle.duration % 60) + '秒' : '未記錄'}
`; // 添加到容器 battlesContainer.innerHTML += battleHTML; }); // 添加載入更多按鈕 if (battles.length >= 5) { battlesContainer.innerHTML += `
`; // 添加載入更多事件 document.getElementById('loadMoreBattles').addEventListener('click', function() { const nextPage = parseInt(this.getAttribute('data-page')); loadMoreBattles(nextPage); }); } } else { // 如果沒有對戰歷史或獲取失敗,顯示提示 const battlesContainer = document.querySelector('#battle-history'); battlesContainer.innerHTML = '

最近對戰

暫無對戰記錄
'; } }) .catch(error => { console.error('獲取對戰歷史失敗:', error); // 顯示更詳細的錯誤信息 const battlesContainer = document.querySelector('#battle-history'); battlesContainer.innerHTML = `

最近對戰

獲取對戰歷史失敗

${error.message}

可能原因:

請檢查網絡連接並重新整理頁面,或聯繫管理員。

`; }); } // 載入更多對戰歷史 function loadMoreBattles(page) { const loadMoreBtn = document.getElementById('loadMoreBattles'); loadMoreBtn.innerHTML = ' 載入中...'; loadMoreBtn.disabled = true; RequestUtil.get(`/api/battles/history?page=${page}`) .then(response => { if (!response.ok) { throw new Error('獲取更多對戰歷史失敗'); } return response.json(); }) .then(data => { if (data.success && data.data && data.data.battles) { const battles = data.data.battles; const battlesContainer = document.querySelector('#battle-history'); // 移除載入更多按鈕 const loadMoreBtnContainer = document.querySelector('#battle-history .mt-3'); if (loadMoreBtnContainer) { loadMoreBtnContainer.remove(); } // 添加對戰歷史 battles.forEach(battle => { const battleHTML = `
${battle.isWin ? '勝利' : '失敗'}
對手: ${battle.opponent.name}
使用方塊: ${battle.userBlock.name} 對手方塊: ${battle.opponentBlock.name} ${new Date(battle.date).toLocaleString()}
獲得點數: ${battle.rewards ? battle.rewards.points : 0} 獲得經驗: ${battle.rewards ? battle.rewards.experience : 0} 對戰時長: ${battle.duration ? Math.floor(battle.duration / 60) + '分' + (battle.duration % 60) + '秒' : '未記錄'}
`; // 添加到容器,在最後一個對戰歷史項目之後 const lastBattleItem = battlesContainer.querySelector('.battle-history-item:last-child'); if (lastBattleItem) { lastBattleItem.insertAdjacentHTML('afterend', battleHTML); } else { battlesContainer.innerHTML += battleHTML; } }); // 如果還有更多對戰歷史,添加載入更多按鈕 if (battles.length >= 5) { battlesContainer.innerHTML += `
`; // 添加載入更多事件 document.getElementById('loadMoreBattles').addEventListener('click', function() { const nextPage = parseInt(this.getAttribute('data-page')); loadMoreBattles(nextPage); }); } } else { // 如果沒有更多對戰歷史,顯示提示 const battlesContainer = document.querySelector('#battle-history'); battlesContainer.innerHTML += '
沒有更多對戰記錄
'; } }) .catch(error => { console.error('獲取更多對戰歷史失敗:', error); // 恢復載入更多按鈕 loadMoreBtn.innerHTML = '載入更多'; loadMoreBtn.disabled = false; // 顯示錯誤提示 const battlesContainer = document.querySelector('#battle-history'); battlesContainer.innerHTML += `
獲取更多對戰歷史失敗: ${error.message}
`; }); } // 加載成就 function loadAchievements() { console.log('正在獲取成就...'); RequestUtil.get('/api/achievements') .then(response => { if (!response.ok) { throw new Error('獲取成就失敗: ' + response.status + ' ' + response.statusText); } // 檢查內容類型 const contentType = response.headers.get('content-type'); if (!contentType || !contentType.includes('application/json')) { throw new Error('伺服器返回了非JSON格式的數據,可能是API路徑錯誤或認證問題'); } return response.json(); }) .then(data => { console.log('獲取成就成功:', data); if (data.success && data.data && data.data.achievements) { const achievements = data.data.achievements; const achievementsContainer = document.querySelector('#achievements'); // 分類成就 const completedAchievements = achievements.filter(a => a.isCompleted); const inProgressAchievements = achievements.filter(a => !a.isCompleted && a.progress > 0); const lockedAchievements = achievements.filter(a => !a.isCompleted && a.progress === 0); // 清空現有成就 achievementsContainer.innerHTML = ''; // 添加已完成的成就 if (completedAchievements.length > 0) { achievementsContainer.innerHTML += '

已完成的成就

'; completedAchievements.forEach(achievement => { const achievementHTML = `
${achievement.name}
${achievement.description}
獎勵: ${achievement.reward}
`; // 添加到容器 achievementsContainer.innerHTML += achievementHTML; }); } // 添加進行中的成就 if (inProgressAchievements.length > 0) { achievementsContainer.innerHTML += '

進行中的成就

'; inProgressAchievements.forEach(achievement => { const achievementHTML = `
${achievement.name}
${achievement.description}
獎勵: ${achievement.reward}
進度 ${achievement.currentValue}/${achievement.targetValue}
`; // 添加到容器 achievementsContainer.innerHTML += achievementHTML; }); } // 添加未解鎖的成就 if (lockedAchievements.length > 0) { achievementsContainer.innerHTML += '

未解鎖的成就

'; lockedAchievements.forEach(achievement => { const achievementHTML = `
${achievement.name}
${achievement.description}
獎勵: ${achievement.reward}
`; // 添加到容器 achievementsContainer.innerHTML += achievementHTML; }); } } else { // 如果沒有成就或獲取失敗,顯示提示 const achievementsContainer = document.querySelector('#achievements'); achievementsContainer.innerHTML = '
暫無成就數據
'; } }) .catch(error => { console.error('獲取成就失敗:', error); // 顯示更詳細的錯誤信息 const achievementsContainer = document.querySelector('#achievements'); achievementsContainer.innerHTML = `
獲取成就失敗

${error.message}

可能原因:

請檢查網絡連接並重新整理頁面,或聯繫管理員。

`; }); } });