From ebbac4012f9cfeb07c8eda4ac8d3519ece2b1853 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 5 Jul 2026 04:53:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=BB=9A=E8=BD=AE=E7=BC=A9=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aidocs/project_context.md | 1 + apps/admin/src/composables/openMediaViewer.ts | 39 +++++++ .../client/src/composables/openMediaViewer.ts | 103 ++++++++++++------ 3 files changed, 107 insertions(+), 36 deletions(-) diff --git a/aidocs/project_context.md b/aidocs/project_context.md index 8d5df96..bb16d56 100644 --- a/aidocs/project_context.md +++ b/aidocs/project_context.md @@ -156,6 +156,7 @@ - 客户端溯源页暗色适配(2026-07-05):`Trace.vue` 将基础信息分隔线、时间轴线、时间轴说明文字、查看图片按钮底色、缩略图底色、轮播/证书圆点等浅色硬编码抽成 `--trace-*` 变量,并分别为系统深色和手动 `html[data-theme='dark']` 补充暗色变量,避免夜间模式下浅色控件和分割线突兀。 - 客户端主题变量收敛(2026-07-05):进一步把客户端顶部栏、卡片阴影、正品验证背景、工具按钮 hover、溯源页分隔/时间轴/占位色等主题变量统一迁入 `apps/client/src/styles.css` 的 `:root`、`prefers-color-scheme: dark`、`data-theme=light/dark`。`Trace.vue` 不再保留局部深色覆盖,顶部栏和语言/主题按钮直接使用全局变量,修复手动或系统夜间模式下顶部栏仍显示浅色的问题。 - 客户端基础信息字段排版(2026-07-05):溯源详情页基础信息字段行由 flex 改为 grid,标签列桌面端固定 132px、窄屏 118px,值列自适应;标签单行省略、值列加粗并允许换行,避免“创作年代 / 出品时间”等长标签把字段行撑乱或与值错位。 +- 图片预览滚轮缩放兜底(2026-07-05):后台和客户端共用的 `openMediaViewer` 在 PhotoSwipe `wheel` 事件中补充自定义缩放处理,拦截默认滚轮行为并按鼠标位置缩放当前图片;缩放上限至少放宽到初始比例 6 倍或 4 倍,避免认证文件、较小证书图等因 PhotoSwipe 默认上限判断导致鼠标滚轮看似无法放大。视频项仍通过 `isZoomable()` 自动跳过。 ## 当前代码基准与注意事项 diff --git a/apps/admin/src/composables/openMediaViewer.ts b/apps/admin/src/composables/openMediaViewer.ts index 26ec2f6..9a89472 100644 --- a/apps/admin/src/composables/openMediaViewer.ts +++ b/apps/admin/src/composables/openMediaViewer.ts @@ -32,6 +32,43 @@ function getImageSize(url: string): Promise<{ width: number; height: number }> { }); } +function bindWheelZoom(lightbox: PhotoSwipeLightbox): void { + lightbox.on('wheel', (event: any) => { + const originalEvent = event?.originalEvent as WheelEvent | undefined; + const pswp = lightbox.pswp as any; + const slide = pswp?.currSlide; + if (!originalEvent || !slide?.isZoomable?.()) return; + + event.preventDefault(); + originalEvent.preventDefault(); + originalEvent.stopPropagation(); + + const zoomLevels = slide.zoomLevels || {}; + const current = slide.currZoomLevel || zoomLevels.initial || 1; + const initial = zoomLevels.initial || current || 1; + const min = zoomLevels.min || initial; + const max = Math.max(zoomLevels.max || 0, initial * 6, 4); + + let zoomFactor = -originalEvent.deltaY; + if (originalEvent.deltaMode === 1) { + zoomFactor *= 0.05; + } else { + zoomFactor *= originalEvent.deltaMode ? 1 : 0.002; + } + const nextZoom = Math.min(max, Math.max(min, current * 2 ** zoomFactor)); + + slide.zoomTo( + nextZoom, + { + x: originalEvent.clientX, + y: originalEvent.clientY, + }, + 0, + true, + ); + }); +} + export async function openMediaViewer(items: MediaViewerItem[], index = 0): Promise { const list = (items || []).filter((item) => item.url); if (!list.length) return; @@ -61,6 +98,8 @@ export async function openMediaViewer(items: MediaViewerItem[], index = 0): Prom wheelToZoom: true, }); + bindWheelZoom(lightbox); + lightbox.on('contentLoad', (event: any) => { const { content } = event; if (content?.data?.type !== 'video') return; diff --git a/apps/client/src/composables/openMediaViewer.ts b/apps/client/src/composables/openMediaViewer.ts index 50725c6..b8aef5d 100644 --- a/apps/client/src/composables/openMediaViewer.ts +++ b/apps/client/src/composables/openMediaViewer.ts @@ -1,5 +1,5 @@ -import PhotoSwipeLightbox from 'photoswipe/lightbox'; import PhotoSwipe from 'photoswipe'; +import PhotoSwipeLightbox from 'photoswipe/lightbox'; import 'photoswipe/style.css'; export interface MediaItem { @@ -8,12 +8,12 @@ export interface MediaItem { type?: string; } -function isVideo(m: MediaItem) { - return !!m && (m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(m.url || '')); +const sizeCache = new Map(); + +function isVideo(item: MediaItem): boolean { + return item.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(item.url || ''); } -// 缓存图片真实尺寸,避免重复加载;PhotoSwipe 需要宽高才能正确缩放/居中 -const sizeCache = new Map(); function getImageSize(url: string): Promise<{ w: number; h: number }> { const cached = sizeCache.get(url); if (cached) return Promise.resolve(cached); @@ -29,24 +29,61 @@ function getImageSize(url: string): Promise<{ w: number; h: number }> { }); } -/** - * 打开图片 / 视频详情查看器(基于 PhotoSwipe v5)。 - * - 图片:支持双指/滚轮/双击缩放、拖动、左右滑动切换、下滑关闭。 - * - 视频:渲染为可控制的