Files
membank/office-site/assets/js/main.js
张威33321 6296202eb0 0908
2026-09-08 19:10:54 +08:00

86 lines
2.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 站点交互(占位实现,接入后端后替换为真实接口)
(function () {
'use strict';
/* ---------- 移动端菜单 ---------- */
var toggle = document.getElementById('navToggle');
var nav = document.querySelector('.nav');
if (toggle && nav) {
toggle.addEventListener('click', function () {
var open = nav.classList.toggle('open');
toggle.classList.toggle('active', open);
toggle.setAttribute('aria-expanded', String(open));
});
// 点击菜单项后自动收起
nav.addEventListener('click', function (e) {
if (e.target.tagName === 'A') {
nav.classList.remove('open');
toggle.classList.remove('active');
toggle.setAttribute('aria-expanded', 'false');
}
});
}
/* ---------- 报告查询 ---------- */
var form = document.getElementById('reportForm');
if (form) {
var sn = document.getElementById('sn');
var empty = document.getElementById('resultEmpty');
var detail = document.getElementById('resultDetail');
form.addEventListener('submit', function (e) {
e.preventDefault();
var val = (sn.value || '').trim();
if (!val) {
alert('请输入机身编号 / SN');
sn.focus();
return;
}
// TODO 接口GET /api/reports?sn=xxx → 渲染真实报告数据
empty.style.display = 'none';
detail.style.display = 'block';
detail.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
});
}
/* ---------- 智能客服 ---------- */
var chatForm = document.getElementById('chatForm');
if (chatForm) {
var input = document.getElementById('chatInput');
var body = document.getElementById('chatBody');
function addBubble(text, who) {
var el = document.createElement('div');
el.className = 'bubble ' + who;
el.textContent = text;
body.appendChild(el);
body.scrollTop = body.scrollHeight;
}
chatForm.addEventListener('submit', function (e) {
e.preventDefault();
var text = (input.value || '').trim();
if (!text) return;
addBubble(text, 'me');
input.value = '';
// TODO 接口POST /api/chat → 返回真实回复
setTimeout(function () {
addBubble('已收到你的问题:' + '「' + text + '」。智能客服接口尚未接入,这里将展示真实回复。', 'bot');
}, 400);
});
}
/* ---------- 常见问题快捷提问 ---------- */
var quickList = document.getElementById('quickList');
if (quickList) {
var chatInput = document.getElementById('chatInput');
quickList.addEventListener('click', function (e) {
var item = e.target.closest('.quick-item');
if (!item || !chatInput) return;
chatInput.value = item.textContent.trim();
chatInput.focus();
});
}
})();