物品借出免审批并扩大上传限制
This commit is contained in:
Vendored
+2
-2
@@ -155,7 +155,7 @@
|
||||
<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>
|
||||
<label>借用状态<select id="center-export-loan-status"><option value="all">全部状态</option><option value="approved">借出未归还</option><option value="returned">已归还</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>
|
||||
@@ -170,7 +170,7 @@
|
||||
<div class="center-check-status" id="center-check-status" role="status"></div>
|
||||
<div class="filters center-toolbar"><input id="center-item-q" type="search" aria-label="搜索物品" placeholder="搜索物品名称" /><button id="center-add-item" class="btn">添加物品</button><button id="center-check" class="btn primary">完成今日清点</button><button id="center-refresh" class="btn">刷新</button></div>
|
||||
<div id="center-items" class="member-grid"></div>
|
||||
<div class="page-head center-subhead"><h3>借用记录</h3><select id="center-loan-status" aria-label="借用状态"><option value="all">全部借用</option><option value="pending">待审批</option><option value="rejected">已驳回</option><option value="borrowed">借出未归还</option><option value="returned">已归还</option></select></div>
|
||||
<div class="page-head center-subhead"><h3>借用记录</h3><select id="center-loan-status" aria-label="借用状态"><option value="all">全部借用</option><option value="borrowed">借出未归还</option><option value="returned">已归还</option></select></div>
|
||||
<div id="center-loans" class="card-list"></div>
|
||||
<details class="center-history"><summary>每日清点记录</summary><div id="center-checks"></div></details>
|
||||
</section>
|
||||
|
||||
Vendored
+17
-19
@@ -4,6 +4,10 @@
|
||||
(() => {
|
||||
const API = "/api";
|
||||
const TOKEN_KEY = "worklog_token";
|
||||
const MB = 1024 * 1024;
|
||||
const CENTER_PHOTO_BATCH_LIMIT = 50;
|
||||
const CENTER_PHOTO_MAX_MB = 8;
|
||||
const CENTER_ZIP_MAX_MB = 100;
|
||||
|
||||
// ------------------------------------------------------------- 工具
|
||||
const $ = (sel) => document.querySelector(sel);
|
||||
@@ -857,9 +861,9 @@
|
||||
|
||||
function centerUploadFields(prefix) {
|
||||
return `<label>活动照片<input name="photos" type="file" accept="image/jpeg,image/png,image/webp" multiple /></label>
|
||||
<p class="muted">可直接多选相册照片或拍照,每次最多20张(含ZIP内照片),每张不超过8MB。</p><div id="${prefix}-selected-photos" class="activity-photos"></div>
|
||||
<p class="muted">可直接多选相册照片或拍照,每次最多${CENTER_PHOTO_BATCH_LIMIT}张(含ZIP内照片),每张不超过${CENTER_PHOTO_MAX_MB}MB。</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>`;
|
||||
<p class="muted">需要附PDF、Word、Excel等文档时再上传ZIP,最大${CENTER_ZIP_MAX_MB}MB,可不含照片。</p>`;
|
||||
}
|
||||
|
||||
function bindCenterUploads(form, box, label, meter, prefix) {
|
||||
@@ -871,8 +875,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; }
|
||||
form.photos.setCustomValidity(form.photos.files.length > CENTER_PHOTO_BATCH_LIMIT ? `每次最多上传${CENTER_PHOTO_BATCH_LIMIT}张照片,请重新选择` : '');
|
||||
if (form.photos.files.length > CENTER_PHOTO_BATCH_LIMIT) { 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);
|
||||
@@ -882,9 +886,9 @@
|
||||
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 > CENTER_PHOTO_BATCH_LIMIT) throw new Error(`每次最多上传${CENTER_PHOTO_BATCH_LIMIT}张照片,请重新选择`);
|
||||
if (files.some(file => file.size > CENTER_PHOTO_MAX_MB * MB || !(/\.(jpe?g|png|webp)$/i.test(file.name) || /^image\/(jpeg|png|webp)$/.test(file.type)))) throw new Error(`照片支持JPG、PNG、WebP,每张最大${CENTER_PHOTO_MAX_MB}MB`);
|
||||
if (zip && (zip.size > CENTER_ZIP_MAX_MB * MB || !zip.name.toLowerCase().endsWith('.zip'))) throw new Error(`请提交${CENTER_ZIP_MAX_MB}MB以内的ZIP附件`);
|
||||
if (files.length || zip) box.classList.remove('hidden');
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
if (!form.isConnected) throw new Error('上传已取消');
|
||||
@@ -903,7 +907,7 @@
|
||||
const result = await uploadMaterial(zip, (loaded, total) => renderUploadProgress(label, meter, loaded, total, 'ZIP已上传,正在校验附件…'));
|
||||
uploadedZip = { file: zip, id: result.id, photoCount: result.photo_ids.length };
|
||||
}
|
||||
if (files.length + (zip ? uploadedZip.photoCount : 0) > 20) throw new Error('每次最多上传20张照片(含ZIP内照片),请减少照片后重试');
|
||||
if (files.length + (zip ? uploadedZip.photoCount : 0) > CENTER_PHOTO_BATCH_LIMIT) throw new Error(`每次最多上传${CENTER_PHOTO_BATCH_LIMIT}张照片(含ZIP内照片),请减少照片后重试`);
|
||||
meter.value = 100; label.textContent = '上传完成,正在保存记录…';
|
||||
return { photo_ids: files.map(file => uploadedPhotos.get(file)), material_id: zip ? uploadedZip.id : null };
|
||||
};
|
||||
@@ -1416,7 +1420,6 @@
|
||||
finally {button.disabled=false;}
|
||||
});
|
||||
let centerItems = [];
|
||||
let centerCanReview = false;
|
||||
let centerRecords = [];
|
||||
function openCenterFromHash() {
|
||||
if (state.me && location.hash === '#timetables') { show('timetables'); return true; }
|
||||
@@ -1444,14 +1447,14 @@
|
||||
$('#center-record-list').innerHTML = data.items.map(a => activityCard(a)).join('') || '<div class="empty">暂无匹配的一楼活动,记录活动时请上传照片。</div>';
|
||||
bindCardEvents($('#center-record-list'));
|
||||
} else {
|
||||
const data = await api(`/center/items?q=${encodeURIComponent($('#center-item-q').value)}`); centerItems = data.items; centerCanReview = data.can_review;
|
||||
$('#center-check-status').textContent = `${data.day} · ${data.checked_today ? '今日清点已完成' : '今日待清点,请逐项核对实际在库数量'}${data.approval_configured ? '' : ' · 负责人待配置,借出申请将保持待审批'}`;
|
||||
const data = await api(`/center/items?q=${encodeURIComponent($('#center-item-q').value)}`); centerItems = data.items;
|
||||
$('#center-check-status').textContent = `${data.day} · ${data.checked_today ? '今日清点已完成' : '今日待清点,请逐项核对实际在库数量'}`;
|
||||
const canEditCheck = data.check?.user_id === state.me.id;
|
||||
$('#center-check').disabled = data.checked_today && !canEditCheck;
|
||||
$('#center-check').textContent = data.checked_today && canEditCheck ? '修改今日清点' : '完成今日清点';
|
||||
$('#center-items').innerHTML = data.items.map(item => `<div class="mcard"><b>${esc(item.name)}</b><p class="muted">总数 ${item.quantity} · 已借出 ${item.borrowed} · 在库 ${item.available}</p><button class="btn sm" data-borrow="${item.id}" ${item.available ? '' : 'disabled'}>申请借出</button></div>`).join('') || '<div class="empty">还没有物品,请先添加物品。</div>';
|
||||
$('#center-items').innerHTML = data.items.map(item => `<div class="mcard"><b>${esc(item.name)}</b><p class="muted">总数 ${item.quantity} · 已借出 ${item.borrowed} · 在库 ${item.available}</p><button class="btn sm" data-borrow="${item.id}" ${item.available ? '' : 'disabled'}>登记借出</button></div>`).join('') || '<div class="empty">还没有物品,请先添加物品。</div>';
|
||||
const loans = await api(`/center/loans?status=${$('#center-loan-status').value}`);
|
||||
$('#center-loans').innerHTML = loans.items.map(r => `<div class="acard"><b>${esc(r.item_name)} × ${r.quantity}</b> <span class="tag ${r.returned_at ? 'attended' : 'joined'}">${({pending:'待审批',approved:'借出中',returned:'已归还',rejected:'已驳回'})[r.status] || r.status}</span><p class="muted">${esc(r.display_name)} · ${fmtDate(r.created_at)}</p><p>${esc(r.reason)}</p>${r.contact ? `<p class="muted">联系方式:${esc(r.contact)}</p>` : ''}<p class="muted">${esc(r.review_note || '')}</p>${r.status === 'pending' && centerCanReview ? `<button class="btn primary sm" data-review="${r.id}" data-action="approve">批准</button> <button class="btn sm" data-review="${r.id}" data-action="reject">驳回</button>` : ''}${r.status === 'approved' && r.user_id === state.me.id ? `<button class="btn sm" data-return="${r.id}">登记归还</button>` : ''}</div>`).join('') || '<div class="empty">暂无借用记录。</div>';
|
||||
$('#center-loans').innerHTML = loans.items.map(r => `<div class="acard"><b>${esc(r.item_name)} × ${r.quantity}</b> <span class="tag ${r.returned_at ? 'attended' : 'joined'}">${({pending:'历史待处理',approved:'借出中',returned:'已归还',rejected:'历史未借出'})[r.status] || r.status}</span><p class="muted">${esc(r.display_name)} · ${fmtDate(r.created_at)}</p><p>${esc(r.reason)}</p>${r.contact ? `<p class="muted">联系方式:${esc(r.contact)}</p>` : ''}${r.status === 'approved' && r.user_id === state.me.id ? `<button class="btn sm" data-return="${r.id}">登记归还</button>` : ''}</div>`).join('') || '<div class="empty">暂无借用记录。</div>';
|
||||
const checks = await api('/center/checks');
|
||||
$('#center-checks').innerHTML = checks.items.map(r => `<div class="acard"><b>${esc(r.day)}</b><p class="muted">${esc(r.display_name)} · ${fmtDate(r.created_at)}</p>${r.details.map(d => `<p>${esc(d.name)}:应在库 ${d.expected},实点 ${d.actual},借出 ${d.borrowed}</p>`).join('')}<p>${esc(r.note)}</p></div>`).join('') || '<p class="muted">暂无清点记录。</p>';
|
||||
}
|
||||
@@ -1482,14 +1485,9 @@
|
||||
$('#center-items').addEventListener('click', event => {
|
||||
const button = event.target.closest('[data-borrow]'); if (!button || button.disabled) return;
|
||||
const item = centerItems.find(r => r.id === button.dataset.borrow);
|
||||
centerForm(`借出 · ${esc(item.name)}`, `<p class="muted">提交后等待负责人审批。联系方式仅本人和负责人可见,便于联系归还。</p><label>借出数量<input name="quantity" type="number" min="1" max="${item.available}" value="1" required /></label><label>申请理由<textarea name="reason" required maxlength="500"></textarea></label><label>联系方式<input name="contact" required maxlength="200" placeholder="电话、微信或邮箱" /></label>`, f => api(`/center/items/${item.id}/loans`, { method: 'POST', body: { quantity: Number(f.quantity.value), reason: f.reason.value, contact: f.contact.value } }));
|
||||
centerForm(`登记借出 · ${esc(item.name)}`, `<p class="muted">提交后立即借出并占用库存。请在使用后由借用人登记归还;联系方式仅本人可见。</p><label>借出数量<input name="quantity" type="number" min="1" max="${item.available}" value="1" required /></label><label>借出理由<textarea name="reason" required maxlength="500"></textarea></label><label>联系方式<input name="contact" required maxlength="200" placeholder="电话、微信或邮箱" /></label>`, f => api(`/center/items/${item.id}/loans`, { method: 'POST', body: { quantity: Number(f.quantity.value), reason: f.reason.value, contact: f.contact.value } }));
|
||||
});
|
||||
$('#center-loans').addEventListener('click', async event => {
|
||||
const review = event.target.closest('[data-review]');
|
||||
if (review && !review.disabled) {
|
||||
centerForm(review.dataset.action === 'approve' ? '批准借出申请' : '驳回借出申请', '<label>审批说明<textarea name="note" maxlength="500"></textarea></label>', f => api(`/center/loans/${review.dataset.review}/review`, { method: 'POST', body: { action: review.dataset.action, note: f.note.value } }));
|
||||
return;
|
||||
}
|
||||
const button = event.target.closest('[data-return]'); if (!button || button.disabled) return;
|
||||
button.disabled = true;
|
||||
try { await api(`/center/loans/${button.dataset.return}/return`, { method: 'POST' }); await loadCenter(); }
|
||||
|
||||
Reference in New Issue
Block a user