fix: 修复认证文件滚轮缩放
This commit is contained in:
@@ -156,6 +156,7 @@
|
|||||||
- 客户端溯源页暗色适配(2026-07-05):`Trace.vue` 将基础信息分隔线、时间轴线、时间轴说明文字、查看图片按钮底色、缩略图底色、轮播/证书圆点等浅色硬编码抽成 `--trace-*` 变量,并分别为系统深色和手动 `html[data-theme='dark']` 补充暗色变量,避免夜间模式下浅色控件和分割线突兀。
|
- 客户端溯源页暗色适配(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):进一步把客户端顶部栏、卡片阴影、正品验证背景、工具按钮 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):溯源详情页基础信息字段行由 flex 改为 grid,标签列桌面端固定 132px、窄屏 118px,值列自适应;标签单行省略、值列加粗并允许换行,避免“创作年代 / 出品时间”等长标签把字段行撑乱或与值错位。
|
||||||
|
- 图片预览滚轮缩放兜底(2026-07-05):后台和客户端共用的 `openMediaViewer` 在 PhotoSwipe `wheel` 事件中补充自定义缩放处理,拦截默认滚轮行为并按鼠标位置缩放当前图片;缩放上限至少放宽到初始比例 6 倍或 4 倍,避免认证文件、较小证书图等因 PhotoSwipe 默认上限判断导致鼠标滚轮看似无法放大。视频项仍通过 `isZoomable()` 自动跳过。
|
||||||
|
|
||||||
## 当前代码基准与注意事项
|
## 当前代码基准与注意事项
|
||||||
|
|
||||||
|
|||||||
@@ -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<void> {
|
export async function openMediaViewer(items: MediaViewerItem[], index = 0): Promise<void> {
|
||||||
const list = (items || []).filter((item) => item.url);
|
const list = (items || []).filter((item) => item.url);
|
||||||
if (!list.length) return;
|
if (!list.length) return;
|
||||||
@@ -61,6 +98,8 @@ export async function openMediaViewer(items: MediaViewerItem[], index = 0): Prom
|
|||||||
wheelToZoom: true,
|
wheelToZoom: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bindWheelZoom(lightbox);
|
||||||
|
|
||||||
lightbox.on('contentLoad', (event: any) => {
|
lightbox.on('contentLoad', (event: any) => {
|
||||||
const { content } = event;
|
const { content } = event;
|
||||||
if (content?.data?.type !== 'video') return;
|
if (content?.data?.type !== 'video') return;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
|
||||||
import PhotoSwipe from 'photoswipe';
|
import PhotoSwipe from 'photoswipe';
|
||||||
|
import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
||||||
import 'photoswipe/style.css';
|
import 'photoswipe/style.css';
|
||||||
|
|
||||||
export interface MediaItem {
|
export interface MediaItem {
|
||||||
@@ -8,12 +8,12 @@ export interface MediaItem {
|
|||||||
type?: string;
|
type?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideo(m: MediaItem) {
|
const sizeCache = new Map<string, { w: number; h: number }>();
|
||||||
return !!m && (m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(m.url || ''));
|
|
||||||
|
function isVideo(item: MediaItem): boolean {
|
||||||
|
return item.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(item.url || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 缓存图片真实尺寸,避免重复加载;PhotoSwipe 需要宽高才能正确缩放/居中
|
|
||||||
const sizeCache = new Map<string, { w: number; h: number }>();
|
|
||||||
function getImageSize(url: string): Promise<{ w: number; h: number }> {
|
function getImageSize(url: string): Promise<{ w: number; h: number }> {
|
||||||
const cached = sizeCache.get(url);
|
const cached = sizeCache.get(url);
|
||||||
if (cached) return Promise.resolve(cached);
|
if (cached) return Promise.resolve(cached);
|
||||||
@@ -29,24 +29,61 @@ function getImageSize(url: string): Promise<{ w: number; h: number }> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function bindWheelZoom(lightbox: PhotoSwipeLightbox): void {
|
||||||
* 打开图片 / 视频详情查看器(基于 PhotoSwipe v5)。
|
lightbox.on('wheel', (event: any) => {
|
||||||
* - 图片:支持双指/滚轮/双击缩放、拖动、左右滑动切换、下滑关闭。
|
const originalEvent = event?.originalEvent as WheelEvent | undefined;
|
||||||
* - 视频:渲染为可控制的 <video> 播放,切到其它张或关闭时自动暂停。
|
const pswp = lightbox.pswp as any;
|
||||||
* - 循环:到最后一张的下一张回到第一张。
|
const slide = pswp?.currSlide;
|
||||||
*/
|
if (!originalEvent || !slide?.isZoomable?.()) return;
|
||||||
export async function openMediaViewer(items: MediaItem[], index = 0) {
|
|
||||||
const list = (items || []).filter((m) => m && m.url);
|
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: MediaItem[], index = 0): Promise<void> {
|
||||||
|
const list = (items || []).filter((item) => item.url);
|
||||||
if (!list.length) return;
|
if (!list.length) return;
|
||||||
const start = Math.min(Math.max(0, index), list.length - 1);
|
const start = Math.min(Math.max(index, 0), list.length - 1);
|
||||||
|
|
||||||
const dataSource = await Promise.all(
|
const dataSource = await Promise.all(
|
||||||
list.map(async (m) => {
|
list.map(async (item) => {
|
||||||
if (isVideo(m)) {
|
if (isVideo(item)) {
|
||||||
return { type: 'video', src: m.url as string, title: m.name };
|
return { type: 'video', src: item.url as string, title: item.name };
|
||||||
}
|
}
|
||||||
const { w, h } = await getImageSize(m.url as string);
|
const { w, h } = await getImageSize(item.url as string);
|
||||||
return { src: m.url as string, width: w, height: h, alt: m.name, title: m.name };
|
return {
|
||||||
|
src: item.url as string,
|
||||||
|
width: w,
|
||||||
|
height: h,
|
||||||
|
alt: item.name,
|
||||||
|
title: item.name,
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -57,18 +94,17 @@ export async function openMediaViewer(items: MediaItem[], index = 0) {
|
|||||||
loop: true,
|
loop: true,
|
||||||
bgOpacity: 0.96,
|
bgOpacity: 0.96,
|
||||||
wheelToZoom: true,
|
wheelToZoom: true,
|
||||||
// 图片支持双击/双指/滚轮缩放;视频项无宽高,PhotoSwipe 会自动隐藏其缩放按钮
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 视频项:用自定义 DOM 替换默认内容
|
bindWheelZoom(lightbox);
|
||||||
lightbox.on('contentLoad', (e: any) => {
|
|
||||||
const { content } = e;
|
lightbox.on('contentLoad', (event: any) => {
|
||||||
|
const { content } = event;
|
||||||
if (content?.data?.type !== 'video') return;
|
if (content?.data?.type !== 'video') return;
|
||||||
e.preventDefault();
|
event.preventDefault();
|
||||||
const wrap = document.createElement('div');
|
const wrap = document.createElement('div');
|
||||||
wrap.className = 'pswp-video';
|
wrap.className = 'pswp-video';
|
||||||
wrap.style.cssText =
|
wrap.style.cssText = 'width:100%;height:100%;display:flex;align-items:center;justify-content:center;';
|
||||||
'width:100%;height:100%;display:flex;align-items:center;justify-content:center;';
|
|
||||||
const video = document.createElement('video');
|
const video = document.createElement('video');
|
||||||
video.src = content.data.src;
|
video.src = content.data.src;
|
||||||
video.controls = true;
|
video.controls = true;
|
||||||
@@ -79,19 +115,14 @@ export async function openMediaViewer(items: MediaItem[], index = 0) {
|
|||||||
content.element = wrap;
|
content.element = wrap;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 离开当前张时暂停其视频
|
const pauseVideo = (event: any) => {
|
||||||
const pauseVideo = (e: any) => {
|
const video = event?.content?.element?.querySelector?.('video') as HTMLVideoElement | null;
|
||||||
const v = e?.content?.element?.querySelector?.('video') as HTMLVideoElement | null;
|
video?.pause();
|
||||||
if (v) v.pause();
|
|
||||||
};
|
};
|
||||||
lightbox.on('contentDeactivate', pauseVideo);
|
lightbox.on('contentDeactivate', pauseVideo);
|
||||||
lightbox.on('close', () => {
|
lightbox.on('close', () => {
|
||||||
const v = document.querySelector('.pswp .pswp-video video') as HTMLVideoElement | null;
|
const video = document.querySelector('.pswp .pswp-video video') as HTMLVideoElement | null;
|
||||||
if (v) v.pause();
|
video?.pause();
|
||||||
});
|
|
||||||
// 关闭后销毁实例,释放键盘/尺寸监听
|
|
||||||
lightbox.on('destroy', () => {
|
|
||||||
/* PhotoSwipe 自行清理 */
|
|
||||||
});
|
});
|
||||||
|
|
||||||
lightbox.init();
|
lightbox.init();
|
||||||
|
|||||||
Reference in New Issue
Block a user