diff --git a/Dockerfile b/Dockerfile index ed231de..ce9aab2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,11 +3,26 @@ FROM python:3.11-slim WORKDIR /app COPY requirements.txt /app/requirements.txt -# 国内服务器从默认PyPI下载大型识别组件可能超时;可用构建参数覆盖源。 +# 大型识别组件下载时可能短暂断线。优先使用构建参数指定的源, +# 失败后自动切换到官方 PyPI,并保留 BuildKit 下载缓存。 ARG PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ +ARG PIP_FALLBACK_INDEX_URL=https://pypi.org/simple/ +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \ + PIP_DEFAULT_TIMEOUT=300 \ + PIP_RETRIES=10 \ + PIP_PROGRESS_BAR=off RUN --mount=type=cache,target=/root/.cache/pip \ - python -m pip install --disable-pip-version-check --retries 3 --timeout 120 \ - --index-url "${PIP_INDEX_URL}" -r /app/requirements.txt + set -eu; \ + for index_url in "${PIP_INDEX_URL}" "${PIP_FALLBACK_INDEX_URL}"; do \ + echo "Installing Python dependencies from ${index_url}"; \ + if python -m pip install --prefer-binary --no-input \ + --retries "${PIP_RETRIES}" --timeout "${PIP_DEFAULT_TIMEOUT}" \ + --index-url "${index_url}" -r /app/requirements.txt; then \ + exit 0; \ + fi; \ + echo "Dependency download failed from ${index_url}; trying the next source"; \ + done; \ + exit 1 RUN python -c "import PIL, rapidocr, onnxruntime, cv2" COPY server /app/server diff --git a/UPGRADE.md b/UPGRADE.md index 59c0654..81aade8 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -21,8 +21,8 @@ ## Coolify / Docker 构建依赖下载失败 -如果日志已成功检出 Git 提交,但停在 `pip install`,并出现 `files.pythonhosted.org` 下载缓慢或 `Temporary failure in name resolution`,失败发生在构建机下载依赖的阶段。镜像构建默认使用 HTTPS 阿里云 PyPI 镜像,并通过 BuildKit 缓存下载包,减少大型课表识别组件反复下载;构建时会检查 Pillow、RapidOCR、ONNX Runtime 和 OpenCV 能否导入。 +如果日志已成功检出 Git 提交,但停在 `pip install`,并出现 `files.pythonhosted.org` 下载缓慢、`Broken pipe` 或 `Temporary failure in name resolution`,失败发生在构建机下载依赖的阶段。镜像构建默认使用 HTTPS 阿里云 PyPI 镜像,并通过 BuildKit 缓存下载包,减少大型课表识别组件反复下载。每个依赖源会以 300 秒超时和 10 次连接重试安装;主源失败时自动尝试官方 PyPI。构建最后会检查 Pillow、RapidOCR、ONNX Runtime 和 OpenCV 能否导入。 -需要其他源时通过 Docker 构建参数 `PIP_INDEX_URL` 覆盖,例如官方源 `https://pypi.org/simple/`。使用 BuildKit 构建(Coolify 已默认启用)。重新部署时继续挂载原有 `/app/data`,保留原环境变量,不开启 `FORCE_SEED=1`。 +需要其他源时通过 Docker 构建参数 `PIP_INDEX_URL` 覆盖,备用源可通过 `PIP_FALLBACK_INDEX_URL` 设置,例如把任意一项改为 `https://pypi.org/simple/`。使用 BuildKit 构建(Coolify 已默认启用)。重新部署时继续挂载原有 `/app/data`,保留原环境变量,不开启 `FORCE_SEED=1`。 生产环境关闭 `WORKLOG_DEV_MODE` 并保留有效的 SMTP 配置;邮件链接的公网地址通过 `WORKLOG_BASE_URL` 设置。包内仅提供 `.env.example` 配置示例,不包含本机凭据和数据库。 diff --git a/dist/assets/styles.css b/dist/assets/styles.css index a3ad3ae..5bedc2b 100644 --- a/dist/assets/styles.css +++ b/dist/assets/styles.css @@ -580,14 +580,21 @@ button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px s .settings-divider { border: 0; border-top: 1px solid var(--line); margin: 24px 0; } @media (max-width: 520px) { .duty-reminder-row { flex-wrap: wrap; } .duty-row-actions { width: 100%; } } -.activity-photos { display:flex; gap:10px; flex-wrap:wrap; margin:14px 0; } +.photo-preview { margin:14px 0; } +.photo-preview-summary { display:flex; align-items:center; flex-wrap:wrap; gap:10px; padding:10px 12px; border:1px solid var(--line); border-radius:10px; background:#f7faf8; color:var(--muted); font-size:13px; } +.photo-preview-summary strong { color:var(--text); } +.selected-photo-summary:empty { display:none; } +.activity-photos { display:grid; grid-template-columns:repeat(auto-fill,minmax(120px,1fr)); gap:10px; margin:12px 0 0; } .activity-photos:empty { display:none; } .activity-materials { margin:12px 0; display:flex; flex-direction:column; gap:8px; } .activity-materials > div { display:flex; flex-wrap:wrap; align-items:center; gap:8px; } .upload-progress { margin:16px 0; padding:12px 14px; border:1px solid var(--line); border-radius:10px; background:var(--primary-soft); } .upload-progress p { margin:0 0 8px; font-size:13px; overflow-wrap:anywhere; } .upload-progress progress { display:block; width:100%; height:12px; accent-color:var(--primary); } -.activity-photos img { width:120px; height:90px; object-fit:cover; border-radius:8px; border:1px solid var(--line); cursor:zoom-in; } +.activity-photos img { display:block; width:100%; aspect-ratio:4/3; height:auto; object-fit:cover; border-radius:8px; border:1px solid var(--line); cursor:zoom-in; background:#edf2ee; } +.activity-photos img.photo-loading { background:linear-gradient(110deg,#edf2ee 8%,#f8faf8 18%,#edf2ee 33%); background-size:200% 100%; animation:photo-shimmer 1.4s linear infinite; } +.activity-photos img.photo-error { display:grid; place-items:center; padding:10px; color:var(--muted); font-size:12px; cursor:default; } +@keyframes photo-shimmer { to { background-position-x:-200%; } } .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; } diff --git a/dist/js/app.js b/dist/js/app.js index 09e9b13..61d851d 100644 --- a/dist/js/app.js +++ b/dist/js/app.js @@ -403,6 +403,49 @@ return esc(/[\u4e00-\u9fff]/.test(s) ? s.slice(0, 1) : s.slice(0, 2).toUpperCase()); }; + function photoGallery(ids, label = '活动照片') { + const unique = [...new Set((ids || []).filter(Boolean))]; + if (!unique.length) return ''; + return `
+
+ + 共 ${unique.length} 张 · 点击后加载 +
+ +
`; + } + + function bindPhotoPreviews(container) { + if (!container) return; + container.querySelectorAll('[data-photo-preview]').forEach(button => { + if (button.dataset.bound) return; + button.dataset.bound = 'true'; + button.addEventListener('click', event => { + event.preventDefault(); + event.stopPropagation(); + const wrapper = button.closest('.photo-preview'); + const gallery = wrapper.querySelector('.photo-gallery'); + const opening = gallery.classList.contains('hidden'); + if (!opening) { + gallery.classList.add('hidden'); + button.textContent = '预览图片'; + button.setAttribute('aria-expanded', 'false'); + return; + } + const ids = (wrapper.dataset.photoIds || '').split(',').filter(Boolean); + if (!gallery.dataset.loaded) { + const label = wrapper.dataset.photoLabel || '活动照片'; + gallery.innerHTML = ids.map((id, index) => `${esc(label)} ${index + 1}`).join(''); + gallery.dataset.loaded = 'true'; + } + gallery.classList.remove('hidden'); + button.textContent = '收起图片'; + button.setAttribute('aria-expanded', 'true'); + loadPhotos(gallery); + }); + }); + } + function activityCard(a, opts = {}) { const isCenter = a.record_type === 'center'; const mine = isCenter ? null : a.my_participation; @@ -451,7 +494,7 @@ ${a.description ? `

${esc(a.description).slice(0, 160)}${a.description.length > 160 ? "…" : ""}

` : ""} ${a.record_type === 'center' ? '赋能中心一楼活动记录' : ''} ${materialButtons(a)} - ${(a.photo_ids || []).length ? `
${a.photo_ids.map(id => `活动照片`).join('')}
` : ''} + ${photoGallery(a.photo_ids)}
${isCenter ? `仅作记录 · 全员可见${a.organizer ? ` · ${esc(a.organizer.display_name)} 记录` : ''}` : `${faces}${more}${a.participant_count} 人${opts.showOrganizer && a.organizer ? ` · ${esc(a.organizer.display_name)} 记录` : ""}`} @@ -462,7 +505,7 @@ } function bindCardEvents(container) { - loadPhotos(container); + bindPhotoPreviews(container); container.querySelectorAll(".acard").forEach((card) => { const id = card.dataset.id; const activity = findActivity(id); @@ -526,7 +569,6 @@ $("#feed-list").classList.toggle("hidden", !data.items.length); $("#feed-empty").classList.toggle("hidden", !!data.items.length); bindCardEvents($("#feed-list")); - loadPhotos($("#feed-list")); try { const ov = await api("/stats/overview"); $("#feed-stats").innerHTML = ` @@ -861,7 +903,7 @@ function centerUploadFields(prefix) { return ` -

可直接多选相册照片或拍照,每次最多${CENTER_PHOTO_BATCH_LIMIT}张(含ZIP内照片),每张不超过${CENTER_PHOTO_MAX_MB}MB。

+

可直接多选相册照片或拍照,每次最多${CENTER_PHOTO_BATCH_LIMIT}张(含ZIP内照片),每张不超过${CENTER_PHOTO_MAX_MB}MB。

需要附PDF、Word、Excel等文档时再上传ZIP,最大${CENTER_ZIP_MAX_MB}MB,可不含照片。

`; } @@ -877,10 +919,34 @@ const preview = $('#' + prefix + '-selected-photos'); preview.replaceChildren(); 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); - } + const files = [...form.photos.files]; + if (!files.length) return; + preview.innerHTML = `
已选择 ${files.length} 张 · 点击后加载
`; + const button = preview.querySelector('[data-local-photo-preview]'); + const gallery = preview.querySelector('.photo-gallery'); + button.addEventListener('click', () => { + const opening = gallery.classList.contains('hidden'); + if (!opening) { + gallery.classList.add('hidden'); + button.textContent = '预览图片'; + button.setAttribute('aria-expanded', 'false'); + return; + } + if (!gallery.dataset.loaded) { + gallery.innerHTML = ''; + files.forEach((file, index) => { + const img = document.createElement('img'), url = URL.createObjectURL(file); + previewUrls.push(url); + img.src = url; + img.alt = `${file.name || '已选照片'} ${index + 1}`; + gallery.append(img); + }); + gallery.dataset.loaded = 'true'; + } + gallery.classList.remove('hidden'); + button.textContent = '收起图片'; + button.setAttribute('aria-expanded', 'true'); + }); box.classList.add('hidden'); }); form.materials.addEventListener('change', () => { uploadedZip = null; box.classList.add('hidden'); }); @@ -959,7 +1025,7 @@
- + ${a.description ? `
${esc(a.description)}
` : ""} ${materialButtons(a)} -
${(a.photo_ids || []).map(id => `活动照片`).join('')}
+ ${photoGallery(a.photo_ids)} ${noteRow} ${isCenter ? '' : `

一起参加过(${a.participant_count})

`}
@@ -1117,6 +1183,7 @@
`); $("#d-close").addEventListener("click", closeModal); + bindPhotoPreviews($("#modal-root")); const reload = async () => { closeModal(); @@ -1137,7 +1204,6 @@ try { await api(`/activities/${id}`, { method: "DELETE" }); toast("已删除"); closeModal(); refreshCurrent(); } catch (err) { toast(err.message, true); } }); - loadPhotos($("#modal-root")); const noteInput = $("#d-note"); if (noteInput) { let timer = null; @@ -1175,21 +1241,35 @@ const photoUrls = new Map(); async function loadPhotos(container) { if (!container) return; - for (const img of container.querySelectorAll('[data-photo]')) { - if (img.dataset.loading) continue; - img.dataset.loading = 'true'; - const id = img.dataset.photo; - try { - if (!photoUrls.has(id)) { - photoUrls.set(id, fetch(`/api/center/photos/${encodeURIComponent(id)}`, { headers: { Authorization: `Bearer ${getToken()}` } }).then(async r => { - if (!r.ok) throw new Error('照片加载失败'); - return URL.createObjectURL(await r.blob()); - })); + const images = [...container.querySelectorAll('[data-photo]')].filter(img => !img.dataset.loading); + if (!images.length) return; + let cursor = 0; + const loadOne = async () => { + while (cursor < images.length) { + const img = images[cursor++]; + img.dataset.loading = 'true'; + const id = img.dataset.photo; + try { + if (!photoUrls.has(id)) { + photoUrls.set(id, fetch(`/api/center/photos/${encodeURIComponent(id)}`, { headers: { Authorization: `Bearer ${getToken()}` } }).then(async response => { + if (!response.ok) throw new Error('照片加载失败'); + return URL.createObjectURL(await response.blob()); + })); + } + const url = await photoUrls.get(id); + img.src = url; + img.classList.remove('photo-loading'); + img.addEventListener('click', () => window.open(url, '_blank', 'noopener')); + } catch { + photoUrls.delete(id); + img.classList.remove('photo-loading'); + img.classList.add('photo-error'); + img.alt = '照片暂时无法加载'; + delete img.dataset.loading; } - const url = await photoUrls.get(id); img.src = url; - img.addEventListener('click', () => window.open(url, '_blank', 'noopener')); - } catch { photoUrls.delete(id); img.alt = '照片暂时无法加载'; } - } + } + }; + await Promise.all(Array.from({ length: Math.min(4, images.length) }, loadOne)); } // ------------------------------------------------------------- 课表收取