限制一楼活动每次上传最多20张照片并保留历史材料
This commit is contained in:
Vendored
+1
-1
@@ -322,7 +322,7 @@
|
||||
|
||||
<div id="toast" class="toast hidden" role="status" aria-live="polite"></div>
|
||||
|
||||
<script src="/js/app.js?v=29"></script>
|
||||
<script src="/js/app.js?v=30"></script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Vendored
+7
-3
@@ -857,7 +857,7 @@
|
||||
|
||||
function centerUploadFields(prefix) {
|
||||
return `<label>活动照片<input name="photos" type="file" accept="image/jpeg,image/png,image/webp" multiple /></label>
|
||||
<p class="muted">可直接多选相册照片或拍照,每张不超过8MB。照片数量不限。</p><div id="${prefix}-selected-photos" class="activity-photos"></div>
|
||||
<p class="muted">可直接多选相册照片或拍照,每次最多20张(含ZIP内照片),每张不超过8MB。</p><div id="${prefix}-selected-photos" class="activity-photos"></div>
|
||||
<label>ZIP附件 <span class="hint-inline">(选填)</span><input name="materials" type="file" accept=".zip,application/zip" /></label>
|
||||
<p class="muted">需要附PDF、Word、Excel等文档时再上传ZIP,最大30MB,可不含照片。</p>`;
|
||||
}
|
||||
@@ -871,6 +871,8 @@
|
||||
form.photos.addEventListener('change', () => {
|
||||
clearPreview();
|
||||
const preview = $('#' + prefix + '-selected-photos'); preview.replaceChildren();
|
||||
form.photos.setCustomValidity(form.photos.files.length > 20 ? '每次最多上传20张照片,请重新选择' : '');
|
||||
if (form.photos.files.length > 20) { form.photos.reportValidity(); box.classList.add('hidden'); return; }
|
||||
for (const file of form.photos.files) {
|
||||
const img = document.createElement('img'), url = URL.createObjectURL(file);
|
||||
previewUrls.push(url); img.src = url; img.alt = file.name; preview.append(img);
|
||||
@@ -880,6 +882,7 @@
|
||||
form.materials.addEventListener('change', () => { uploadedZip = null; box.classList.add('hidden'); });
|
||||
return async () => {
|
||||
const files = [...form.photos.files], zip = form.materials.files[0];
|
||||
if (files.length > 20) throw new Error('每次最多上传20张照片,请重新选择');
|
||||
if (files.some(file => file.size > 8 * 1024 * 1024 || !(/\.(jpe?g|png|webp)$/i.test(file.name) || /^image\/(jpeg|png|webp)$/.test(file.type)))) throw new Error('照片支持JPG、PNG、WebP,每张最大8MB');
|
||||
if (zip && (zip.size > 30 * 1024 * 1024 || !zip.name.toLowerCase().endsWith('.zip'))) throw new Error('请提交30MB以内的ZIP附件');
|
||||
if (files.length || zip) box.classList.remove('hidden');
|
||||
@@ -898,8 +901,9 @@
|
||||
if (zip && uploadedZip?.file !== zip) {
|
||||
if (!form.isConnected) throw new Error('上传已取消');
|
||||
const result = await uploadMaterial(zip, (loaded, total) => renderUploadProgress(label, meter, loaded, total, 'ZIP已上传,正在校验附件…'));
|
||||
uploadedZip = { file: zip, id: result.id };
|
||||
uploadedZip = { file: zip, id: result.id, photoCount: result.photo_ids.length };
|
||||
}
|
||||
if (files.length + (zip ? uploadedZip.photoCount : 0) > 20) throw new Error('每次最多上传20张照片(含ZIP内照片),请减少照片后重试');
|
||||
meter.value = 100; label.textContent = '上传完成,正在保存记录…';
|
||||
return { photo_ids: files.map(file => uploadedPhotos.get(file)), material_id: zip ? uploadedZip.id : null };
|
||||
};
|
||||
@@ -1009,7 +1013,7 @@
|
||||
if (!f.photos.files.length && !f.materials.files.length && !(existing?.photo_ids || []).length && !existing?.material_id && !existing?.materials?.length) throw new Error('请至少选择照片或ZIP附件');
|
||||
btn.textContent = '正在上传…';
|
||||
const uploaded = await collectUploads();
|
||||
body.photo_ids = [...new Set([...(existing?.photo_ids || []), ...uploaded.photo_ids])];
|
||||
body.photo_ids = uploaded.photo_ids;
|
||||
body.material_id = uploaded.material_id || existing?.material_id || null;
|
||||
} else { body.photo_ids = []; body.material_id = null; }
|
||||
if (!f.isConnected) return;
|
||||
|
||||
Reference in New Issue
Block a user