// ── Main Page JavaScript ── const BASE_PATH = window.BASE_PATH || ''; document.addEventListener('DOMContentLoaded', () => { loadProfile(); loadSkills(); loadEducation(); loadExperience(); }); async function apiFetch(url) { const resp = await fetch(BASE_PATH + url); if (resp.status === 401) { window.location.href = BASE_PATH + '/login'; return null; } return resp.json(); } async function loadProfile() { const data = await apiFetch('/api/profile'); if (!data || !data.name) return; document.getElementById('profile-name').textContent = data.name; const photoEl = document.getElementById('profile-photo'); if (data.photo_url) { photoEl.innerHTML = `${data.name}`; } else { photoEl.textContent = data.name.charAt(0); } const items = [ { label: '学历', value: data.education_level }, { label: '所在地', value: data.location }, { label: '邮箱', value: data.email }, { label: '电话', value: data.phone }, ]; const grid = document.getElementById('profile-info-grid'); grid.innerHTML = items.filter(i => i.value).map(i => `
${i.label}: ${i.value}
` ).join(''); const summaryEl = document.getElementById('summary-text'); if (data.self_summary) { summaryEl.textContent = data.self_summary; } } async function loadSkills() { const data = await apiFetch('/api/skills'); if (!data || !data.length) return; const container = document.getElementById('skills-container'); container.innerHTML = data.map(s => `
${s.category}
${s.content}
`).join(''); } async function loadEducation() { const data = await apiFetch('/api/education'); if (!data || !data.length) return; const container = document.getElementById('education-container'); container.innerHTML = data.map(e => `
${e.start_date} - ${e.end_date}
${e.school}
${e.major} | ${e.degree}
${e.details ? `
${e.details}
` : '
暂无详细信息
'}
`).join(''); } async function loadExperience() { const data = await apiFetch('/api/experience'); if (!data || !data.length) return; const container = document.getElementById('experience-container'); container.innerHTML = data.map(exp => { let details = ''; if (exp.company_intro) { details += `
公司简介
${exp.company_intro}
`; } if (exp.responsibilities) { details += `
工作职责
${exp.responsibilities}
`; } if (exp.achievements) { details += `
工作成就
${exp.achievements}
`; } return `
${exp.start_date} - ${exp.end_date}
${exp.company}
${exp.position}
${details || '
暂无详细信息
'}
`; }).join(''); } function toggleAccordion(header) { const item = header.parentElement; const content = item.querySelector('.accordion-content'); const isActive = item.classList.contains('active'); if (isActive) { content.style.maxHeight = null; item.classList.remove('active'); } else { content.style.maxHeight = content.scrollHeight + 'px'; item.classList.add('active'); } }