一楼活动改为ZIP材料提交,默认一楼分类并新增AI数据接口和导出
This commit is contained in:
Vendored
+49
-20
@@ -377,7 +377,7 @@
|
||||
|
||||
// ------------------------------------------------------------- 顶栏
|
||||
$("#brand").addEventListener("click", () => show("feed"));
|
||||
$("#new-activity-btn").addEventListener("click", () => openActivityForm());
|
||||
$("#new-activity-btn").addEventListener("click", () => openActivityForm(null, state.view === 'center' ? 'center' : 'normal'));
|
||||
$("#menu-toggle").addEventListener("click", () => {
|
||||
const open = $("#nav").classList.toggle("open");
|
||||
$("#menu-toggle").setAttribute("aria-expanded", String(open));
|
||||
@@ -438,6 +438,7 @@
|
||||
</div>
|
||||
${a.description ? `<p class="acard-desc">${esc(a.description).slice(0, 160)}${a.description.length > 160 ? "…" : ""}</p>` : ""}
|
||||
${a.record_type === 'center' ? '<span class="tag cat">赋能中心一楼活动记录</span>' : ''}
|
||||
${a.material_id ? `<button class="btn sm" data-material="${esc(a.material_id)}">下载材料 ZIP</button>` : ''}
|
||||
${(a.photo_ids || []).length ? `<div class="activity-photos">${a.photo_ids.map(id => `<img data-photo="${esc(id)}" alt="活动照片" loading="lazy" />`).join('')}</div>` : ''}
|
||||
<div class="acard-foot">
|
||||
<div class="faces">
|
||||
@@ -807,7 +808,7 @@
|
||||
<label>地点<input name="location" maxlength="120" value="${esc(existing?.location || "")}" placeholder="如:3 号会议室" /></label>
|
||||
</div>
|
||||
<label>备注 <span class="hint-inline">(选填)</span><textarea name="description" rows="3" maxlength="2000" placeholder="做什么、带什么、注意事项…">${esc(existing?.description || "")}</textarea></label>
|
||||
<div id="act-photo-fields" class="hidden"><label>活动照片(必填,1–5 张)<input name="photos" type="file" accept="image/jpeg,image/png,image/webp" multiple /></label><p class="muted">每张不超过 8MB。编辑时不选新照片会保留原照片;选择新照片会替换原组。</p><div id="act-photo-preview" class="activity-photos">${(existing?.photo_ids || []).map(id => `<img data-photo="${esc(id)}" alt="活动照片" />`).join('')}</div></div>
|
||||
<div id="act-photo-fields" class="hidden"><label>活动材料 ZIP(必填)<input name="materials" type="file" accept=".zip,application/zip" /></label><p class="muted">最大30MB,包内须含1–5张活动照片,可附PDF、Office或文本材料。编辑时不选新包会保留原材料。</p><p id="act-material-name" class="muted"></p><div id="act-photo-preview" class="activity-photos">${(existing?.photo_ids || []).map(id => `<img data-photo="${esc(id)}" alt="活动照片" />`).join('')}</div></div>
|
||||
<label class="checkline"><input type="checkbox" name="visibility" ${!existing || existing.visibility === "public" ? "checked" : ""} /> 公开活动(所有人可见;不勾选则仅参加者可见)</label>
|
||||
<div class="form-error" id="act-error"></div>
|
||||
<div class="form-actions">
|
||||
@@ -817,17 +818,15 @@
|
||||
</form>`);
|
||||
const activityForm = $('#act-form');
|
||||
activityForm.record_type.value = existing?.record_type || defaultType;
|
||||
const togglePhotos = () => $('#act-photo-fields').classList.toggle('hidden', activityForm.record_type.value !== 'center');
|
||||
activityForm.record_type.disabled = state.view === 'center';
|
||||
const togglePhotos = () => {
|
||||
const isCenter = activityForm.record_type.value === 'center';
|
||||
$('#act-photo-fields').classList.toggle('hidden', !isCenter);
|
||||
if (isCenter && !activityForm.location.value.trim()) activityForm.location.value = '赋能中心一楼';
|
||||
};
|
||||
activityForm.record_type.addEventListener('change', togglePhotos); togglePhotos();
|
||||
loadPhotos($('#act-photo-preview'));
|
||||
activityForm.photos.addEventListener('change', () => {
|
||||
$('#act-photo-preview').replaceChildren();
|
||||
for (const file of [...activityForm.photos.files].slice(0, 5)) {
|
||||
const img = document.createElement('img'); const url = URL.createObjectURL(file);
|
||||
img.alt = file.name; img.src = url; img.onload = img.onerror = () => URL.revokeObjectURL(url);
|
||||
$('#act-photo-preview').append(img);
|
||||
}
|
||||
});
|
||||
activityForm.materials.addEventListener('change', () => { $('#act-material-name').textContent = activityForm.materials.files[0]?.name || ''; });
|
||||
|
||||
$("#act-cancel").addEventListener("click", closeModal);
|
||||
$("#act-form").addEventListener("submit", async (e) => {
|
||||
@@ -846,18 +845,18 @@
|
||||
};
|
||||
btn.disabled = true;
|
||||
try {
|
||||
const files = [...f.photos.files];
|
||||
const file = f.materials.files[0];
|
||||
if (body.record_type === 'center') {
|
||||
if (files.length > 5 || files.some(file => file.size > 8 * 1024 * 1024)) throw new Error('最多5张照片,每张不超过8MB');
|
||||
body.photo_ids = files.length ? [] : [...(existing?.photo_ids || [])];
|
||||
if (!files.length && !body.photo_ids.length) throw new Error('一楼活动记录需要至少一张照片');
|
||||
for (const file of files) {
|
||||
const response = await fetch('/api/center/photos', { method: 'POST', headers: { Authorization: `Bearer ${getToken()}`, 'Content-Type': file.type }, body: file });
|
||||
body.material_id = existing?.material_id || null;
|
||||
if (file) {
|
||||
if (file.size > 30 * 1024 * 1024 || !file.name.toLowerCase().endsWith('.zip')) throw new Error('请提交30MB以内的ZIP材料包');
|
||||
const response = await fetch('/api/center/materials', { method: 'POST', headers: { Authorization: `Bearer ${getToken()}`, 'Content-Type': 'application/zip' }, body: file });
|
||||
const result = await response.json();
|
||||
if (!response.ok) throw new Error(typeof result.detail === 'string' ? result.detail : '照片上传失败');
|
||||
body.photo_ids.push(result.id);
|
||||
if (!response.ok) throw new Error(typeof result.detail === 'string' ? result.detail : '材料包上传失败');
|
||||
body.material_id = result.id;
|
||||
}
|
||||
} else body.photo_ids = [];
|
||||
if (!body.material_id && !(existing?.photo_ids || []).length) throw new Error('请上传包含活动照片的ZIP材料包');
|
||||
} else { body.photo_ids = []; body.material_id = null; }
|
||||
if (isEdit) {
|
||||
await api(`/activities/${existing.id}`, { method: "PATCH", body });
|
||||
toast("已保存");
|
||||
@@ -934,6 +933,7 @@
|
||||
<div><span class="lbl">人数</span>${a.participant_count}${a.capacity ? ` / ${a.capacity}` : ""} · 已参加 ${a.attended_count}</div>
|
||||
</div>
|
||||
${a.description ? `<div class="detail-desc">${esc(a.description)}</div>` : ""}
|
||||
${a.material_id ? `<button class="btn sm" data-material="${esc(a.material_id)}">下载材料 ZIP</button>` : ''}
|
||||
<div class="activity-photos">${(a.photo_ids || []).map(id => `<img data-photo="${esc(id)}" alt="活动照片" />`).join('')}</div>
|
||||
${noteRow}
|
||||
<h4 style="margin:14px 0 2px">一起参加过(${a.participant_count})</h4>
|
||||
@@ -1018,6 +1018,35 @@
|
||||
}
|
||||
|
||||
let centerTab = 'records';
|
||||
async function downloadCenterFile(path, fallback) {
|
||||
const response = await fetch(path, { headers: { Authorization: `Bearer ${getToken()}` } });
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({}));
|
||||
throw new Error(typeof error.detail === 'string' ? error.detail : '下载失败,请检查筛选条件或重新登录');
|
||||
}
|
||||
const url = URL.createObjectURL(await response.blob());
|
||||
const filename = /filename="([^"]+)"/.exec(response.headers.get('Content-Disposition') || '')?.[1] || fallback;
|
||||
const link = document.createElement('a');link.href=url;link.download=filename;document.body.append(link);link.click();link.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url),30000);
|
||||
}
|
||||
document.addEventListener('click', async event => {
|
||||
const button = event.target.closest('[data-material]');
|
||||
if (!button || button.disabled) return;
|
||||
event.stopPropagation();button.disabled=true;
|
||||
try { await downloadCenterFile('/api/center/materials/'+encodeURIComponent(button.dataset.material),'center-materials.zip'); }
|
||||
catch (error) { toast(error.message,true); }
|
||||
finally { button.disabled=false; }
|
||||
});
|
||||
$('#center-export-download').addEventListener('click', async () => {
|
||||
const button = $('#center-export-download');button.disabled=true;$('#center-export-status').textContent='正在准备导出…';
|
||||
const params = new URLSearchParams({ dataset:$('#center-export-dataset').value, format:$('#center-export-format').value });
|
||||
for (const [id,key] of [['q','q'],['from','date_from'],['to','date_to'],['loan-status','loan_status']]) {
|
||||
const value=$('#center-export-'+id).value;if(value)params.set(key,value);
|
||||
}
|
||||
try { await downloadCenterFile('/api/center/export?'+params,'center-export.json');$('#center-export-status').textContent='已下载,文件不包含联系方式,照片与材料包以引用形式提供。'; }
|
||||
catch (error) { $('#center-export-status').textContent=error.message; }
|
||||
finally {button.disabled=false;}
|
||||
});
|
||||
let centerItems = [];
|
||||
let centerCanReview = false;
|
||||
let centerRecords = [];
|
||||
|
||||
Reference in New Issue
Block a user