延迟加载活动照片并增强镜像构建稳定性
This commit is contained in:
+18
-3
@@ -3,11 +3,26 @@ FROM python:3.11-slim
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY requirements.txt /app/requirements.txt
|
COPY requirements.txt /app/requirements.txt
|
||||||
# 国内服务器从默认PyPI下载大型识别组件可能超时;可用构建参数覆盖源。
|
# 大型识别组件下载时可能短暂断线。优先使用构建参数指定的源,
|
||||||
|
# 失败后自动切换到官方 PyPI,并保留 BuildKit 下载缓存。
|
||||||
ARG PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
|
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 \
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
python -m pip install --disable-pip-version-check --retries 3 --timeout 120 \
|
set -eu; \
|
||||||
--index-url "${PIP_INDEX_URL}" -r /app/requirements.txt
|
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"
|
RUN python -c "import PIL, rapidocr, onnxruntime, cv2"
|
||||||
|
|
||||||
COPY server /app/server
|
COPY server /app/server
|
||||||
|
|||||||
+2
-2
@@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
## Coolify / Docker 构建依赖下载失败
|
## 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` 配置示例,不包含本机凭据和数据库。
|
生产环境关闭 `WORKLOG_DEV_MODE` 并保留有效的 SMTP 配置;邮件链接的公网地址通过 `WORKLOG_BASE_URL` 设置。包内仅提供 `.env.example` 配置示例,不包含本机凭据和数据库。
|
||||||
|
|||||||
Vendored
+9
-2
@@ -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; }
|
.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%; } }
|
@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-photos:empty { display:none; }
|
||||||
.activity-materials { margin:12px 0; display:flex; flex-direction:column; gap:8px; }
|
.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; }
|
.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 { 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 p { margin:0 0 8px; font-size:13px; overflow-wrap:anywhere; }
|
||||||
.upload-progress progress { display:block; width:100%; height:12px; accent-color:var(--primary); }
|
.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-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 { 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 summary { cursor:pointer; font-weight:600; }
|
||||||
|
|||||||
Vendored
+98
-18
@@ -403,6 +403,49 @@
|
|||||||
return esc(/[\u4e00-\u9fff]/.test(s) ? s.slice(0, 1) : s.slice(0, 2).toUpperCase());
|
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 `<div class="photo-preview" data-photo-ids="${esc(unique.join(','))}" data-photo-label="${esc(label)}">
|
||||||
|
<div class="photo-preview-summary">
|
||||||
|
<button class="btn sm" type="button" data-photo-preview aria-expanded="false">预览图片</button>
|
||||||
|
<span>共 <strong>${unique.length}</strong> 张 · 点击后加载</span>
|
||||||
|
</div>
|
||||||
|
<div class="activity-photos photo-gallery hidden" aria-live="polite"></div>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) => `<img class="photo-loading" data-photo="${esc(id)}" alt="${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 = {}) {
|
function activityCard(a, opts = {}) {
|
||||||
const isCenter = a.record_type === 'center';
|
const isCenter = a.record_type === 'center';
|
||||||
const mine = isCenter ? null : a.my_participation;
|
const mine = isCenter ? null : a.my_participation;
|
||||||
@@ -451,7 +494,7 @@
|
|||||||
${a.description ? `<p class="acard-desc">${esc(a.description).slice(0, 160)}${a.description.length > 160 ? "…" : ""}</p>` : ""}
|
${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.record_type === 'center' ? '<span class="tag cat">赋能中心一楼活动记录</span>' : ''}
|
||||||
${materialButtons(a)}
|
${materialButtons(a)}
|
||||||
${(a.photo_ids || []).length ? `<div class="activity-photos">${a.photo_ids.map(id => `<img data-photo="${esc(id)}" alt="活动照片" loading="lazy" />`).join('')}</div>` : ''}
|
${photoGallery(a.photo_ids)}
|
||||||
<div class="acard-foot">
|
<div class="acard-foot">
|
||||||
<div class="faces">
|
<div class="faces">
|
||||||
${isCenter ? `<span class="faces-label">仅作记录 · 全员可见${a.organizer ? ` · ${esc(a.organizer.display_name)} 记录` : ''}</span>` : `${faces}${more}<span class="faces-label">${a.participant_count} 人${opts.showOrganizer && a.organizer ? ` · ${esc(a.organizer.display_name)} 记录` : ""}</span>`}
|
${isCenter ? `<span class="faces-label">仅作记录 · 全员可见${a.organizer ? ` · ${esc(a.organizer.display_name)} 记录` : ''}</span>` : `${faces}${more}<span class="faces-label">${a.participant_count} 人${opts.showOrganizer && a.organizer ? ` · ${esc(a.organizer.display_name)} 记录` : ""}</span>`}
|
||||||
@@ -462,7 +505,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function bindCardEvents(container) {
|
function bindCardEvents(container) {
|
||||||
loadPhotos(container);
|
bindPhotoPreviews(container);
|
||||||
container.querySelectorAll(".acard").forEach((card) => {
|
container.querySelectorAll(".acard").forEach((card) => {
|
||||||
const id = card.dataset.id;
|
const id = card.dataset.id;
|
||||||
const activity = findActivity(id);
|
const activity = findActivity(id);
|
||||||
@@ -526,7 +569,6 @@
|
|||||||
$("#feed-list").classList.toggle("hidden", !data.items.length);
|
$("#feed-list").classList.toggle("hidden", !data.items.length);
|
||||||
$("#feed-empty").classList.toggle("hidden", !!data.items.length);
|
$("#feed-empty").classList.toggle("hidden", !!data.items.length);
|
||||||
bindCardEvents($("#feed-list"));
|
bindCardEvents($("#feed-list"));
|
||||||
loadPhotos($("#feed-list"));
|
|
||||||
try {
|
try {
|
||||||
const ov = await api("/stats/overview");
|
const ov = await api("/stats/overview");
|
||||||
$("#feed-stats").innerHTML = `
|
$("#feed-stats").innerHTML = `
|
||||||
@@ -861,7 +903,7 @@
|
|||||||
|
|
||||||
function centerUploadFields(prefix) {
|
function centerUploadFields(prefix) {
|
||||||
return `<label>活动照片<input name="photos" type="file" accept="image/jpeg,image/png,image/webp" multiple /></label>
|
return `<label>活动照片<input name="photos" type="file" accept="image/jpeg,image/png,image/webp" multiple /></label>
|
||||||
<p class="muted">可直接多选相册照片或拍照,每次最多${CENTER_PHOTO_BATCH_LIMIT}张(含ZIP内照片),每张不超过${CENTER_PHOTO_MAX_MB}MB。</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="selected-photo-summary muted"></div>
|
||||||
<label>ZIP附件 <span class="hint-inline">(选填)</span><input name="materials" type="file" accept=".zip,application/zip" /></label>
|
<label>ZIP附件 <span class="hint-inline">(选填)</span><input name="materials" type="file" accept=".zip,application/zip" /></label>
|
||||||
<p class="muted">需要附PDF、Word、Excel等文档时再上传ZIP,最大${CENTER_ZIP_MAX_MB}MB,可不含照片。</p>`;
|
<p class="muted">需要附PDF、Word、Excel等文档时再上传ZIP,最大${CENTER_ZIP_MAX_MB}MB,可不含照片。</p>`;
|
||||||
}
|
}
|
||||||
@@ -877,10 +919,34 @@
|
|||||||
const preview = $('#' + prefix + '-selected-photos'); preview.replaceChildren();
|
const preview = $('#' + prefix + '-selected-photos'); preview.replaceChildren();
|
||||||
form.photos.setCustomValidity(form.photos.files.length > CENTER_PHOTO_BATCH_LIMIT ? `每次最多上传${CENTER_PHOTO_BATCH_LIMIT}张照片,请重新选择` : '');
|
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; }
|
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 files = [...form.photos.files];
|
||||||
const img = document.createElement('img'), url = URL.createObjectURL(file);
|
if (!files.length) return;
|
||||||
previewUrls.push(url); img.src = url; img.alt = file.name; preview.append(img);
|
preview.innerHTML = `<div class="photo-preview-summary"><button class="btn sm" type="button" data-local-photo-preview aria-expanded="false">预览图片</button><span>已选择 <strong>${files.length}</strong> 张 · 点击后加载</span></div><div class="activity-photos photo-gallery hidden"></div>`;
|
||||||
|
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');
|
box.classList.add('hidden');
|
||||||
});
|
});
|
||||||
form.materials.addEventListener('change', () => { uploadedZip = null; box.classList.add('hidden'); });
|
form.materials.addEventListener('change', () => { uploadedZip = null; box.classList.add('hidden'); });
|
||||||
@@ -959,7 +1025,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<label>人数上限 <span class="hint-inline">(选填,留空不限人数)</span><input name="capacity" type="number" min="1" max="500" step="1" value="${existing?.capacity ?? ""}" placeholder="不限人数" /></label>
|
<label>人数上限 <span class="hint-inline">(选填,留空不限人数)</span><input name="capacity" type="number" min="1" max="500" step="1" value="${existing?.capacity ?? ""}" placeholder="不限人数" /></label>
|
||||||
<label>备注 <span class="hint-inline">(选填)</span><textarea name="description" rows="3" maxlength="2000" placeholder="做什么、带什么、注意事项…">${esc(existing?.description || "")}</textarea></label>
|
<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">${centerUploadFields('act')}<p class="muted">照片和ZIP至少选择一种。编辑时会保留原照片和附件,所选内容追加保存。</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">${centerUploadFields('act')}<p class="muted">照片和ZIP至少选择一种。编辑时会保留原照片和附件,所选内容追加保存。</p><div id="act-photo-preview">${photoGallery(existing?.photo_ids, '已有活动照片')}</div></div>
|
||||||
<label class="checkline" id="act-visibility"><input type="checkbox" name="visibility" ${!existing || existing.visibility === "public" ? "checked" : ""} /> 公开活动(所有人可见;不勾选则仅参加者可见)</label>
|
<label class="checkline" id="act-visibility"><input type="checkbox" name="visibility" ${!existing || existing.visibility === "public" ? "checked" : ""} /> 公开活动(所有人可见;不勾选则仅参加者可见)</label>
|
||||||
<p id="act-center-policy" class="muted hidden">全员可见,仅作活动记录,无需参加,也不计入参加统计。</p>
|
<p id="act-center-policy" class="muted hidden">全员可见,仅作活动记录,无需参加,也不计入参加统计。</p>
|
||||||
<div id="act-upload-progress" class="upload-progress hidden">
|
<div id="act-upload-progress" class="upload-progress hidden">
|
||||||
@@ -989,7 +1055,7 @@
|
|||||||
if (isCenter && !activityForm.location.value.trim()) activityForm.location.value = '赋能中心一楼';
|
if (isCenter && !activityForm.location.value.trim()) activityForm.location.value = '赋能中心一楼';
|
||||||
};
|
};
|
||||||
activityForm.record_type.addEventListener('change', togglePhotos); togglePhotos();
|
activityForm.record_type.addEventListener('change', togglePhotos); togglePhotos();
|
||||||
loadPhotos($('#act-photo-preview'));
|
bindPhotoPreviews(activityForm);
|
||||||
|
|
||||||
$("#act-cancel").addEventListener("click", closeModal);
|
$("#act-cancel").addEventListener("click", closeModal);
|
||||||
$("#act-form").addEventListener("submit", async (e) => {
|
$("#act-form").addEventListener("submit", async (e) => {
|
||||||
@@ -1109,7 +1175,7 @@
|
|||||||
</div>
|
</div>
|
||||||
${a.description ? `<div class="detail-desc">${esc(a.description)}</div>` : ""}
|
${a.description ? `<div class="detail-desc">${esc(a.description)}</div>` : ""}
|
||||||
${materialButtons(a)}
|
${materialButtons(a)}
|
||||||
<div class="activity-photos">${(a.photo_ids || []).map(id => `<img data-photo="${esc(id)}" alt="活动照片" />`).join('')}</div>
|
${photoGallery(a.photo_ids)}
|
||||||
${noteRow}
|
${noteRow}
|
||||||
${isCenter ? '' : `<h4 style="margin:14px 0 2px">一起参加过(${a.participant_count})</h4><ul class="p-list">${rows || '<li class="muted">还没有其他人的参加记录</li>'}</ul>`}
|
${isCenter ? '' : `<h4 style="margin:14px 0 2px">一起参加过(${a.participant_count})</h4><ul class="p-list">${rows || '<li class="muted">还没有其他人的参加记录</li>'}</ul>`}
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
@@ -1117,6 +1183,7 @@
|
|||||||
</div>`);
|
</div>`);
|
||||||
|
|
||||||
$("#d-close").addEventListener("click", closeModal);
|
$("#d-close").addEventListener("click", closeModal);
|
||||||
|
bindPhotoPreviews($("#modal-root"));
|
||||||
|
|
||||||
const reload = async () => {
|
const reload = async () => {
|
||||||
closeModal();
|
closeModal();
|
||||||
@@ -1137,7 +1204,6 @@
|
|||||||
try { await api(`/activities/${id}`, { method: "DELETE" }); toast("已删除"); closeModal(); refreshCurrent(); } catch (err) { toast(err.message, true); }
|
try { await api(`/activities/${id}`, { method: "DELETE" }); toast("已删除"); closeModal(); refreshCurrent(); } catch (err) { toast(err.message, true); }
|
||||||
});
|
});
|
||||||
|
|
||||||
loadPhotos($("#modal-root"));
|
|
||||||
const noteInput = $("#d-note");
|
const noteInput = $("#d-note");
|
||||||
if (noteInput) {
|
if (noteInput) {
|
||||||
let timer = null;
|
let timer = null;
|
||||||
@@ -1175,22 +1241,36 @@
|
|||||||
const photoUrls = new Map();
|
const photoUrls = new Map();
|
||||||
async function loadPhotos(container) {
|
async function loadPhotos(container) {
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
for (const img of container.querySelectorAll('[data-photo]')) {
|
const images = [...container.querySelectorAll('[data-photo]')].filter(img => !img.dataset.loading);
|
||||||
if (img.dataset.loading) continue;
|
if (!images.length) return;
|
||||||
|
let cursor = 0;
|
||||||
|
const loadOne = async () => {
|
||||||
|
while (cursor < images.length) {
|
||||||
|
const img = images[cursor++];
|
||||||
img.dataset.loading = 'true';
|
img.dataset.loading = 'true';
|
||||||
const id = img.dataset.photo;
|
const id = img.dataset.photo;
|
||||||
try {
|
try {
|
||||||
if (!photoUrls.has(id)) {
|
if (!photoUrls.has(id)) {
|
||||||
photoUrls.set(id, fetch(`/api/center/photos/${encodeURIComponent(id)}`, { headers: { Authorization: `Bearer ${getToken()}` } }).then(async r => {
|
photoUrls.set(id, fetch(`/api/center/photos/${encodeURIComponent(id)}`, { headers: { Authorization: `Bearer ${getToken()}` } }).then(async response => {
|
||||||
if (!r.ok) throw new Error('照片加载失败');
|
if (!response.ok) throw new Error('照片加载失败');
|
||||||
return URL.createObjectURL(await r.blob());
|
return URL.createObjectURL(await response.blob());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
const url = await photoUrls.get(id); img.src = url;
|
const url = await photoUrls.get(id);
|
||||||
|
img.src = url;
|
||||||
|
img.classList.remove('photo-loading');
|
||||||
img.addEventListener('click', () => window.open(url, '_blank', 'noopener'));
|
img.addEventListener('click', () => window.open(url, '_blank', 'noopener'));
|
||||||
} catch { photoUrls.delete(id); img.alt = '照片暂时无法加载'; }
|
} catch {
|
||||||
|
photoUrls.delete(id);
|
||||||
|
img.classList.remove('photo-loading');
|
||||||
|
img.classList.add('photo-error');
|
||||||
|
img.alt = '照片暂时无法加载';
|
||||||
|
delete img.dataset.loading;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
await Promise.all(Array.from({ length: Math.min(4, images.length) }, loadOne));
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------- 课表收取
|
// ------------------------------------------------------------- 课表收取
|
||||||
let timetableData = null;
|
let timetableData = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user