/** * 注册页面 JavaScript * 使用 utils.js 中的工具库 */ // 状态 let currentTask = null; let currentBatch = null; let logPollingInterval = null; let batchPollingInterval = null; let accountsPollingInterval = null; let isBatchMode = false; let isOutlookBatchMode = false; let outlookAccounts = []; let taskCompleted = false; // 标记任务是否已完成 let batchCompleted = false; // 标记批量任务是否已完成 let taskFinalStatus = null; // 保存任务的最终状态 let batchFinalStatus = null; // 保存批量任务的最终状态 let displayedLogs = new Set(); // 用于日志去重 let toastShown = false; // 标记是否已显示过 toast let availableServices = { tempmail: { available: true, services: [] }, outlook: { available: false, services: [] }, custom_domain: { available: false, services: [] }, temp_mail: { available: false, services: [] } }; // WebSocket 相关变量 let webSocket = null; let batchWebSocket = null; // 批量任务 WebSocket let useWebSocket = true; // 是否使用 WebSocket let wsHeartbeatInterval = null; // 心跳定时器 let batchWsHeartbeatInterval = null; // 批量任务心跳定时器 let activeTaskUuid = null; // 当前活跃的单任务 UUID(用于页面重新可见时重连) let activeBatchId = null; // 当前活跃的批量任务 ID(用于页面重新可见时重连) // DOM 元素 const elements = { form: document.getElementById('registration-form'), emailService: document.getElementById('email-service'), regMode: document.getElementById('reg-mode'), regModeGroup: document.getElementById('reg-mode-group'), batchCountGroup: document.getElementById('batch-count-group'), batchCount: document.getElementById('batch-count'), batchOptions: document.getElementById('batch-options'), intervalMin: document.getElementById('interval-min'), intervalMax: document.getElementById('interval-max'), startBtn: document.getElementById('start-btn'), cancelBtn: document.getElementById('cancel-btn'), taskStatusRow: document.getElementById('task-status-row'), batchProgressSection: document.getElementById('batch-progress-section'), consoleLog: document.getElementById('console-log'), clearLogBtn: document.getElementById('clear-log-btn'), // 任务状态 taskId: document.getElementById('task-id'), taskEmail: document.getElementById('task-email'), taskStatus: document.getElementById('task-status'), taskService: document.getElementById('task-service'), taskStatusBadge: document.getElementById('task-status-badge'), // 批量状态 batchProgressText: document.getElementById('batch-progress-text'), batchProgressPercent: document.getElementById('batch-progress-percent'), progressBar: document.getElementById('progress-bar'), batchSuccess: document.getElementById('batch-success'), batchFailed: document.getElementById('batch-failed'), batchRemaining: document.getElementById('batch-remaining'), // 已注册账号 recentAccountsTable: document.getElementById('recent-accounts-table'), refreshAccountsBtn: document.getElementById('refresh-accounts-btn'), // Outlook 批量注册 outlookBatchSection: document.getElementById('outlook-batch-section'), outlookAccountsContainer: document.getElementById('outlook-accounts-container'), outlookIntervalMin: document.getElementById('outlook-interval-min'), outlookIntervalMax: document.getElementById('outlook-interval-max'), outlookSkipRegistered: document.getElementById('outlook-skip-registered'), outlookConcurrencyMode: document.getElementById('outlook-concurrency-mode'), outlookConcurrencyCount: document.getElementById('outlook-concurrency-count'), outlookConcurrencyHint: document.getElementById('outlook-concurrency-hint'), outlookIntervalGroup: document.getElementById('outlook-interval-group'), // 批量并发控件 concurrencyMode: document.getElementById('concurrency-mode'), concurrencyCount: document.getElementById('concurrency-count'), concurrencyHint: document.getElementById('concurrency-hint'), intervalGroup: document.getElementById('interval-group'), // 注册后自动操作 autoUploadCpa: document.getElementById('auto-upload-cpa'), cpaServiceSelectGroup: document.getElementById('cpa-service-select-group'), cpaServiceSelect: document.getElementById('cpa-service-select') }; // 初始化 document.addEventListener('DOMContentLoaded', () => { initEventListeners(); loadAvailableServices(); loadRecentAccounts(); startAccountsPolling(); initVisibilityReconnect(); restoreActiveTask(); checkCpaEnabled(); }); // 检查 CPA 是否启用,未启用则禁用复选框;同时加载 CPA 服务列表 async function checkCpaEnabled() { if (!elements.autoUploadCpa) return; // 加载 CPA 服务列表,列表为空则禁用复选框 await loadCpaServiceOptions(); try { const services = await api.get('/cpa-services?enabled=true'); if (!services || services.length === 0) { elements.autoUploadCpa.disabled = true; elements.autoUploadCpa.title = '请先在设置中添加 CPA 服务'; const label = elements.autoUploadCpa.closest('label'); if (label) label.style.opacity = '0.5'; } } catch (e) { elements.autoUploadCpa.disabled = true; } // 复选框联动显示/隐藏服务选择器 if (elements.autoUploadCpa) { elements.autoUploadCpa.addEventListener('change', () => { if (elements.cpaServiceSelectGroup) { elements.cpaServiceSelectGroup.style.display = elements.autoUploadCpa.checked ? 'block' : 'none'; } }); } } async function loadCpaServiceOptions() { if (!elements.cpaServiceSelect) return; try { const services = await api.get('/cpa-services?enabled=true'); const defaultOpt = ''; const opts = services.map(s => `