// ── 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 = `
`;
} 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 => `
`).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 += ``;
}
if (exp.responsibilities) {
details += `工作职责
${exp.responsibilities}
`;
}
if (exp.achievements) {
details += ``;
}
return `
`;
}).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');
}
}