Update App.jsx via upload script - 2026-11-04 21:28:09

This commit is contained in:
mike 2026-11-04 21:28:17 +08:00
parent cf08d04079
commit 32796d0da6
1 changed files with 11 additions and 6 deletions

17
App.jsx
View File

@ -3039,14 +3039,19 @@ function MainApp({ username, onLogout }) {
const files = e.dataTransfer.files && Array.from(e.dataTransfer.files); const files = e.dataTransfer.files && Array.from(e.dataTransfer.files);
if (files && files.length) setAttachmentFiles(files); if (files && files.length) setAttachmentFiles(files);
} }
// 上传进度文字:按钮上显示"上传中 2/3 · 45%(8.6 / 19.0 MB)"
function uploadLabel(i, n, loaded, total) {
const mb = (x) => (x / 1048576).toFixed(1);
return `上传中${n > 1 ? ` ${i + 1}/${n}` : ''} · ${Math.floor(loaded / total * 100)}%(${mb(loaded)} / ${mb(total)} MB)`;
}
async function handleUploadAttachment(customerId, folderId) { async function handleUploadAttachment(customerId, folderId) {
if (!attachmentFiles.length) { notify('请先选择文件'); return; } if (!attachmentFiles.length) { notify('请先选择文件'); return; }
setUploading(true); setUploading(true);
const failed = []; const failed = [];
try { try {
for (const file of attachmentFiles) { for (const [i, file] of attachmentFiles.entries()) {
try { try {
const res = await uploadFile(customerId, file); const res = await uploadFile(customerId, file, (l, t) => setUploading(uploadLabel(i, attachmentFiles.length, l, t)));
const entry = { const entry = {
fileName: res.fileName, fileName: res.fileName,
originalName: res.originalName, originalName: res.originalName,
@ -3194,9 +3199,9 @@ function MainApp({ username, onLogout }) {
setSupplierUploading(true); setSupplierUploading(true);
const failed = []; const failed = [];
try { try {
for (const file of supplierAttachmentFiles) { for (const [i, file] of supplierAttachmentFiles.entries()) {
try { try {
const res = await uploadFile(supplierId, file); const res = await uploadFile(supplierId, file, (l, t) => setSupplierUploading(uploadLabel(i, supplierAttachmentFiles.length, l, t)));
const entry = { fileName: res.fileName, originalName: res.originalName, note: supplierAttachmentNote.trim(), date: todayStr() }; const entry = { fileName: res.fileName, originalName: res.originalName, note: supplierAttachmentNote.trim(), date: todayStr() };
setSuppliers(prev => prev.map(s => (s.id === supplierId ? { ...s, attachments: [entry, ...(s.attachments || [])] } : s))); setSuppliers(prev => prev.map(s => (s.id === supplierId ? { ...s, attachments: [entry, ...(s.attachments || [])] } : s)));
} catch (e) { } catch (e) {
@ -5771,7 +5776,7 @@ function SupplierDetail({
value={attachmentNote} onChange={e => setAttachmentNote(e.target.value)} value={attachmentNote} onChange={e => setAttachmentNote(e.target.value)}
/> />
<button className="btn btn-sm" disabled={uploading} onClick={onUploadAttachment} style={{ justifyContent: 'center' }}> <button className="btn btn-sm" disabled={uploading} onClick={onUploadAttachment} style={{ justifyContent: 'center' }}>
<Plus size={12} />{uploading ? '上传中…' : '上传'} <Plus size={12} />{uploading ? (typeof uploading === 'string' ? uploading : '上传中…') : '上传'}
</button> </button>
</div> </div>
</div> </div>
@ -6129,7 +6134,7 @@ function CustomerDetail({
value={attachmentNote} onChange={e => setAttachmentNote(e.target.value)} value={attachmentNote} onChange={e => setAttachmentNote(e.target.value)}
/> />
<button className="btn btn-sm" disabled={uploading} onClick={() => onUploadAttachment(currentFolderId)} style={{ justifyContent: 'center' }}> <button className="btn btn-sm" disabled={uploading} onClick={() => onUploadAttachment(currentFolderId)} style={{ justifyContent: 'center' }}>
<Plus size={12} />{uploading ? '上传中…' : (currentFolderId ? '上传到当前文件夹' : '上传')} <Plus size={12} />{uploading ? (typeof uploading === 'string' ? uploading : '上传中…') : (currentFolderId ? '上传到当前文件夹' : '上传')}
</button> </button>
</div> </div>
</div> </div>