/** * 统一评估系统 - 同时生成SarcoI和SarcoII建议 */ let currentLanguage = 'zh'; // DOM加载完成后初始化 document.addEventListener('DOMContentLoaded', function() { console.log('统一评估系统已加载'); // 初始化语言 initializeLanguage(); // 初始化表单 initializeForm(); // 初始化自动计算 initializeAutoCalculation(); // 插入体力活动问卷 insertPhysicalActivitySection(); }); /** * 初始化语言功能 */ function initializeLanguage() { const savedLanguage = localStorage.getItem('language') || 'zh'; currentLanguage = savedLanguage; updateLanguageDisplay(); } function toggleLanguage() { currentLanguage = currentLanguage === 'zh' ? 'en' : 'zh'; localStorage.setItem('language', currentLanguage); updateLanguageDisplay(); } function updateLanguageDisplay() { const zhElements = document.querySelectorAll('.lang-zh'); const enElements = document.querySelectorAll('.lang-en'); const toggleText = document.getElementById('langToggleText'); if (currentLanguage === 'zh') { zhElements.forEach(el => el.style.display = ''); enElements.forEach(el => el.style.display = 'none'); if (toggleText) toggleText.textContent = 'English'; } else { zhElements.forEach(el => el.style.display = 'none'); enElements.forEach(el => el.style.display = ''); if (toggleText) toggleText.textContent = '中文'; } } /** * 初始化表单 */ function initializeForm() { const form = document.getElementById('unifiedForm'); form.addEventListener('submit', handleSubmit); // 添加输入验证 const inputs = form.querySelectorAll('input[required], select[required]'); inputs.forEach(input => { input.addEventListener('input', updateSubmitButton); }); console.log('统一评估表单初始化完成'); } /** * 初始化自动计算功能 */ function initializeAutoCalculation() { const heightInput = document.getElementById('height'); const weightInput = document.getElementById('weight'); const waistInput = document.getElementById('waist'); function updateCalculations() { const height = parseFloat(heightInput.value); const weight = parseFloat(weightInput.value); const waist = parseFloat(waistInput.value); // 计算BMI if (height && weight) { const heightInMeters = height / 100; const bmi = weight / (heightInMeters * heightInMeters); document.getElementById('bmiDisplay').textContent = bmi.toFixed(1); } else { document.getElementById('bmiDisplay').textContent = '--'; } // 计算WWI if (waist && weight) { const wwi = waist / Math.sqrt(weight); document.getElementById('wwiDisplay').textContent = wwi.toFixed(2); } else { document.getElementById('wwiDisplay').textContent = '--'; } } heightInput.addEventListener('input', updateCalculations); weightInput.addEventListener('input', updateCalculations); waistInput.addEventListener('input', updateCalculations); console.log('自动计算功能已初始化'); } /** * 插入体力活动问卷部分 */ function insertPhysicalActivitySection() { const section = document.getElementById('physicalActivitySection'); section.innerHTML = generatePhysicalActivityHTML(); // 初始化活动详情切换 initializeActivityToggles(); } /** * 生成体力活动问卷HTML */ function generatePhysicalActivityHTML() { return `
基于SarcoI和SarcoII模型的综合评估结果 Comprehensive assessment results based on SarcoI and SarcoII models
${rec.description}
优先级: ${rec.priority} | 预期效果: ${rec.expected_impact} Priority: ${rec.priority} | Expected Impact: ${rec.expected_impact}