113 lines
4.2 KiB
JavaScript
113 lines
4.2 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
||
// Elements
|
||
const clockEl = document.getElementById('real-time-clock');
|
||
const outputEl = document.getElementById('reportOutput');
|
||
const btnParse = document.getElementById('btnParse');
|
||
const btnClear = document.getElementById('btnClear');
|
||
const btnCopy = document.getElementById('btnCopy');
|
||
const toastMessage = document.getElementById('toastMessage');
|
||
const toastEl = document.getElementById('liveToast');
|
||
const toast = new bootstrap.Toast(toastEl);
|
||
|
||
// Input Elements Mapping
|
||
const inputs = {
|
||
totalWS: document.getElementById('in_totalWS'),
|
||
wsBanned: document.getElementById('in_wsBanned'),
|
||
wsPermBanned: document.getElementById('in_wsPermBanned'),
|
||
totalXHS: document.getElementById('in_totalXHS'),
|
||
totalSMS: document.getElementById('in_totalSMS'),
|
||
xhs: document.getElementById('in_xhs'),
|
||
xhs_reply: document.getElementById('in_xhs_reply'),
|
||
ws: document.getElementById('in_ws'),
|
||
ws_reply: document.getElementById('in_ws_reply'),
|
||
sms: document.getElementById('in_sms'),
|
||
sms_reply: document.getElementById('in_sms_reply'),
|
||
totalGreeting: document.getElementById('in_totalGreeting'),
|
||
totalReply: document.getElementById('in_totalReply'),
|
||
rechat: document.getElementById('in_rechat'),
|
||
traffic: document.getElementById('in_traffic'),
|
||
voice: document.getElementById('in_voice')
|
||
};
|
||
|
||
// Initialize Real-time Clock
|
||
const updateClock = () => {
|
||
const now = new Date();
|
||
const options = {
|
||
year: 'numeric', month: '2-digit', day: '2-digit',
|
||
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
||
hour12: false
|
||
};
|
||
const formatted = now.toLocaleString('zh-CN', options).replace(/\//g, '-');
|
||
clockEl.textContent = formatted;
|
||
};
|
||
setInterval(updateClock, 1000);
|
||
updateClock();
|
||
|
||
// Show Toast Helper
|
||
const showToast = (msg, isError = false) => {
|
||
toastMessage.textContent = msg;
|
||
const icon = isError ? 'fa-circle-xmark text-danger' : 'fa-circle-check text-success';
|
||
toastMessage.previousElementSibling.className = `fa-solid ${icon} me-2`;
|
||
toast.show();
|
||
};
|
||
|
||
// Parsing Logic (now just reading inputs)
|
||
const generateReport = () => {
|
||
const stats = {};
|
||
let hasValue = false;
|
||
|
||
for (const [key, el] of Object.entries(inputs)) {
|
||
const val = parseInt(el.value, 10) || 0;
|
||
stats[key] = val;
|
||
if (el.value !== '') hasValue = true;
|
||
}
|
||
|
||
if (!hasValue) {
|
||
showToast('请至少填入一项数据!', true);
|
||
return;
|
||
}
|
||
|
||
// Generate output in the EXACT order and format requested
|
||
const result = `总WS数量: ${stats.totalWS}
|
||
WS今日封号: ${stats.wsBanned}
|
||
总永封WS: ${stats.wsPermBanned}
|
||
总XHS数量: ${stats.totalXHS}
|
||
总SMS数量: ${stats.totalSMS}
|
||
XHS招呼量: ${stats.xhs} 回复: ${stats.xhs_reply}
|
||
WS招呼量: ${stats.ws} 回复: ${stats.ws_reply}
|
||
SMS招呼量: ${stats.sms} 回复: ${stats.sms_reply}
|
||
总招呼量: ${stats.totalGreeting}
|
||
总回复: ${stats.totalReply}
|
||
再聊: ${stats.rechat}
|
||
引流: ${stats.traffic}
|
||
语音: ${stats.voice}`;
|
||
|
||
outputEl.textContent = result;
|
||
btnCopy.disabled = false;
|
||
showToast('报表生成成功!');
|
||
};
|
||
|
||
// Events
|
||
btnParse.addEventListener('click', generateReport);
|
||
|
||
btnClear.addEventListener('click', () => {
|
||
for (const el of Object.values(inputs)) {
|
||
el.value = '';
|
||
}
|
||
outputEl.textContent = '数据结果将在此处生成...';
|
||
btnCopy.disabled = true;
|
||
showToast('已清空所有内容');
|
||
});
|
||
|
||
btnCopy.addEventListener('click', () => {
|
||
const text = outputEl.textContent;
|
||
if (text && !text.includes('在此处生成')) {
|
||
navigator.clipboard.writeText(text).then(() => {
|
||
showToast('汇总报表已复制到剪贴板!');
|
||
}).catch(err => {
|
||
console.error('Copy failed', err);
|
||
showToast('复制失败,请手动选择复制', true);
|
||
});
|
||
}
|
||
});
|
||
}); |