etElementById('ai-txt'); var msg = txt.value.trim(); if(!msg) return; appendMsg(msg, 'user'); txt.value = ''; var loadId = appendMsg('DeepSeek 正在思考...', 'bot'); fetch('/ai_service.php', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({message: msg}) }) .then(function(res){ return res.json(); }) .then(function(data){ var loader = document.getElementById(loadId); if(loader) loader.remove(); appendMsg(data.reply, 'bot'); }) .catch(function(err){ var loader = document.getElementById(loadId); if(loader) loader.innerText = '连接超时,请检查API'; console.error(err); });}function appendMsg(text, type) { var div = document.createElement('div'); div.className = 'ai-msg ai-' + type; div.innerText = text; var list = document.getElementById('ai-chat-list'); list.appendChild(div); div.id = 'msg-' + Math.random(); list.scrollTop = list.scrollHeight; return div.id;}