// File upload modal and batch processing utilities // 文件上传模态框和批量处理工具 import { $, $id, createElement, on, addClass, removeClass } from './util.dom.js'; import { formatFileSize } from './util.file.js'; import { t } from './util.i18n.js'; // File upload modal state // 文件上传模态框状态 let uploadModal = null; let selectedFiles = new Map(); let fileIdCounter = 0; let onSendCallback = null; // Listen for language changes to update modal text // 监听语言变更以更新模态框文本 window.addEventListener('languageChange', () => { if (uploadModal) { updateModalTexts(); } }); // Update modal texts when language changes // 语言切换时更新模态框文本 function updateModalTexts() { if (!uploadModal) return; // Update modal title const modalTitle = uploadModal.querySelector('.file-upload-header h3'); if (modalTitle) { modalTitle.textContent = t('file.upload_files', 'Upload Files'); } // Update file list title const fileListTitle = uploadModal.querySelector('.file-list-title'); if (fileListTitle) { fileListTitle.textContent = t('file.selected_files', 'Selected Files'); } // Update clear all button const clearAllBtn = uploadModal.querySelector('.file-clear-all-btn'); if (clearAllBtn) { clearAllBtn.textContent = t('file.clear_all', 'Clear All'); } // Update cancel button const cancelBtn = uploadModal.querySelector('.file-upload-cancel-btn'); if (cancelBtn) { cancelBtn.textContent = t('file.cancel', 'Cancel'); } // Update send files button const sendBtn = uploadModal.querySelector('.file-upload-send-btn'); if (sendBtn) { sendBtn.textContent = t('file.send_files', 'Send Files'); } // Update drag drop text const dragDropText = uploadModal.querySelector('.file-drop-text'); if (dragDropText) { dragDropText.innerHTML = `
${t('file.drag_drop', 'Drag and drop files here')}
${t('file.or', 'or')}
`; // Re-attach browse button event const browseBtn = dragDropText.querySelector('.file-browse-btn'); if (browseBtn) { on(browseBtn, 'click', handleBrowseClick); } } // Update summary if files are selected if (selectedFiles.size > 0) { updateFileListDisplay(); } } // Generate unique file ID // 生成唯一文件ID function generateFileId() { return 'upload_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9); } // Create file upload modal // 创建文件上传模态框 function createUploadModal() { const modal = createElement('div', { class: 'file-upload-modal' }, `${t('file.drag_drop', 'Drag and drop files here')}
${t('file.or', 'or')}