一楼活动改为ZIP材料提交,默认一楼分类并新增AI数据接口和导出

This commit is contained in:
2026-11-11 16:14:59 +08:00
parent 4f25f40915
commit e1e909d617
11 changed files with 397 additions and 35 deletions
+4
View File
@@ -584,6 +584,10 @@ button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px s
.activity-photos:empty { display:none; }
.activity-photos img { width:120px; height:90px; object-fit:cover; border-radius:8px; border:1px solid var(--line); cursor:zoom-in; }
.center-toolbar { margin-bottom:24px; }
.center-export { margin:0 0 24px; padding:16px 20px; border:1px solid var(--line); background:var(--card); border-radius:12px; }
.center-export summary { cursor:pointer; font-weight:600; }
.center-export label { display:flex; flex-direction:column; gap:6px; color:var(--muted); font-size:13px; }
.center-export .filters { align-items:flex-end; }
.center-shortcuts { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:16px; width:100%; padding:22px 24px; background:var(--primary-soft); border:1px solid #d5e5da; border-radius:12px; }
.center-shortcuts strong { font-size:18px; }
.center-shortcuts p { margin:5px 0 0; color:var(--muted); font-size:13px; }
+15 -2
View File
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WorkLog · 活动记录</title>
<meta name="theme-color" content="#f5f7f5" />
<link rel="stylesheet" href="/assets/styles.css?v=17" />
<link rel="stylesheet" href="/assets/styles.css?v=18" />
</head>
<body>
<div id="app">
@@ -147,6 +147,19 @@
<main id="center-view" class="view hidden">
<div class="container">
<div class="page-head"><div><h2>赋能中心一楼</h2><p class="muted">记录活动,管理物品流转,完成每日清点</p></div></div>
<details class="center-export"><summary>AI读取与数据导出</summary>
<p class="muted">导出当前账号可见的数据,隐藏联系方式。照片与材料包以引用形式提供,全部CSV打包为ZIP。</p>
<div class="filters center-toolbar">
<label>数据范围<select id="center-export-dataset"><option value="all">全部一楼数据</option><option value="activities">一楼活动记录</option><option value="items">物品库存</option><option value="loans">借用记录</option><option value="checks">每日清点</option></select></label>
<label>格式<select id="center-export-format"><option value="json">JSON(适合AI)</option><option value="csv">CSV(全部时为ZIP)</option></select></label>
<label>关键词<input id="center-export-q" type="search" placeholder="主题、物品、申请理由" /></label>
<label>从<input id="center-export-from" type="date" /></label><label>至<input id="center-export-to" type="date" /></label>
<label>借用状态<select id="center-export-loan-status"><option value="all">全部状态</option><option value="pending">待审批</option><option value="approved">借出中</option><option value="returned">已归还</option><option value="rejected">已驳回</option></select></label>
<button id="center-export-download" class="btn primary" type="button">下载数据</button>
</div>
<p class="muted" id="center-export-status" role="status"></p>
<p class="muted">程序读取:GET /api/center/data;字段说明:GET /api/center/schema。均需使用本人登录令牌。</p>
</details>
<div class="tabs center-tabs"><button class="tab active" data-center-tab="records">活动记录</button><button class="tab" data-center-tab="assets">物品清点与借出</button></div>
<section id="center-records">
<div class="filters center-toolbar"><input id="center-q" type="search" aria-label="搜索活动主题" placeholder="搜索活动主题" /><input id="center-from" type="date" aria-label="活动起始日期" /><input id="center-to" type="date" aria-label="活动截止日期" /><button id="center-new" class="btn primary">+ 记录一楼活动</button></div>
@@ -296,7 +309,7 @@
<div id="toast" class="toast hidden" role="status" aria-live="polite"></div>
<script src="/js/app.js?v=24"></script>
<script src="/js/app.js?v=25"></script>
</div>
</body>
</html>
+49 -20
View File
@@ -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 = [];