0908
This commit is contained in:
66
office-site/assets/js/main.js
Normal file
66
office-site/assets/js/main.js
Normal file
@@ -0,0 +1,66 @@
|
||||
// 站点交互(占位实现,接入后端后替换为真实接口)
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/* ---------- 报告查询 ---------- */
|
||||
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();
|
||||
});
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user