// ============ 表单 + 生成图 + MantleDB 提交 ============ const form = document.getElementById('commissionForm'); const sheetWrapper = document.getElementById('sheetWrapper'); const modal = document.getElementById('modal'); const closeBtn = document.getElementById('closeBtn'); const downloadBtn = document.getElementById('downloadBtn'); const previewBtn = document.getElementById('previewBtn'); const statusMsg = document.getElementById('status'); let currentData = null; function collect() { const fd = new FormData(form); const data = {}; fd.forEach((v, k) => data[k] = (v || '').toString().trim()); return data; } function escapeHtml(s) { return String(s ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]) ); } function cell(num, label, value) { const v = value && value.trim() ? escapeHtml(value) : ''; return `