feat: 节点图片支持逐张标题与默认收缩展开,修复C端放大后无法拖动
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
<button v-if="items.length > 1" class="nav next" :aria-label="t('viewer.next')" @click.stop="next">›</button>
|
||||
|
||||
<!-- 媒体区 -->
|
||||
<div class="stage">
|
||||
<div ref="stageEl" class="stage">
|
||||
<video
|
||||
v-if="curIsVideo"
|
||||
:key="cur?.url"
|
||||
@@ -31,18 +31,24 @@
|
||||
/>
|
||||
<img
|
||||
v-else
|
||||
ref="imgEl"
|
||||
class="media-img"
|
||||
:src="cur?.url"
|
||||
:alt="cur?.name"
|
||||
:style="imgStyle"
|
||||
draggable="false"
|
||||
@touchstart="onTouchStart"
|
||||
@touchmove.prevent="onTouchMove"
|
||||
@touchend="onTouchEnd"
|
||||
@wheel.prevent="onWheel"
|
||||
@mousedown.prevent="onMouseDown"
|
||||
@dblclick="onDblClick"
|
||||
@click.stop
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 图片标题 -->
|
||||
<div v-if="!curIsVideo && cur?.name" class="caption">{{ cur.name }}</div>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
@@ -68,13 +74,15 @@ const current = ref(0);
|
||||
const scale = ref(1);
|
||||
const tx = ref(0);
|
||||
const ty = ref(0);
|
||||
const imgEl = ref<HTMLImageElement | null>(null);
|
||||
const stageEl = ref<HTMLElement | null>(null);
|
||||
|
||||
const cur = computed(() => props.items[current.value]);
|
||||
const curIsVideo = computed(() => isVideo(cur.value));
|
||||
const imgStyle = computed(() => ({
|
||||
transform: `translate(${tx.value}px, ${ty.value}px) scale(${scale.value})`,
|
||||
transition: gesturing ? 'none' : 'transform 0.18s ease',
|
||||
cursor: scale.value > 1 ? 'grab' : 'zoom-in',
|
||||
transition: gesturing || dragging ? 'none' : 'transform 0.18s ease',
|
||||
cursor: scale.value > 1 ? (dragging ? 'grabbing' : 'grab') : 'zoom-in',
|
||||
}));
|
||||
|
||||
function isVideo(m?: MediaItem) {
|
||||
@@ -103,11 +111,18 @@ function next() {
|
||||
}
|
||||
|
||||
function clampScale(s: number) {
|
||||
return Math.min(5, Math.max(1, s));
|
||||
return Math.min(6, Math.max(1, s));
|
||||
}
|
||||
// 按"放大后图片实际溢出可视区"的尺寸约束平移,使拖动恰好能到达图片边缘
|
||||
function clampOffset() {
|
||||
const maxX = ((scale.value - 1) * window.innerWidth) / 2 + 40;
|
||||
const maxY = ((scale.value - 1) * window.innerHeight) / 2 + 40;
|
||||
const stage = stageEl.value;
|
||||
const img = imgEl.value;
|
||||
const vw = stage?.clientWidth ?? window.innerWidth;
|
||||
const vh = stage?.clientHeight ?? window.innerHeight;
|
||||
const baseW = img?.clientWidth ?? vw;
|
||||
const baseH = img?.clientHeight ?? vh;
|
||||
const maxX = Math.max(0, (baseW * scale.value - vw) / 2);
|
||||
const maxY = Math.max(0, (baseH * scale.value - vh) / 2);
|
||||
tx.value = Math.max(-maxX, Math.min(maxX, tx.value));
|
||||
ty.value = Math.max(-maxY, Math.min(maxY, ty.value));
|
||||
}
|
||||
@@ -184,6 +199,30 @@ function onTouchEnd(e: TouchEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
/* 鼠标拖动(桌面端):放大后可拖动查看四周细节 */
|
||||
let dragging = false;
|
||||
let dragStartX = 0;
|
||||
let dragStartY = 0;
|
||||
function onMouseDown(e: MouseEvent) {
|
||||
if (scale.value <= 1) return; // 未放大不拖动
|
||||
dragging = true;
|
||||
dragStartX = e.clientX - tx.value;
|
||||
dragStartY = e.clientY - ty.value;
|
||||
window.addEventListener('mousemove', onMouseMove);
|
||||
window.addEventListener('mouseup', onMouseUp);
|
||||
}
|
||||
function onMouseMove(e: MouseEvent) {
|
||||
if (!dragging) return;
|
||||
tx.value = e.clientX - dragStartX;
|
||||
ty.value = e.clientY - dragStartY;
|
||||
clampOffset();
|
||||
}
|
||||
function onMouseUp() {
|
||||
dragging = false;
|
||||
window.removeEventListener('mousemove', onMouseMove);
|
||||
window.removeEventListener('mouseup', onMouseUp);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.show,
|
||||
(v) => {
|
||||
@@ -291,6 +330,20 @@ watch(
|
||||
max-height: 86%;
|
||||
background: #000;
|
||||
}
|
||||
.caption {
|
||||
position: absolute;
|
||||
bottom: 18px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
max-width: 86%;
|
||||
padding: 6px 14px;
|
||||
border-radius: 16px;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
color: #fff;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
z-index: 2;
|
||||
}
|
||||
.viewer-fade-enter-active,
|
||||
.viewer-fade-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
"cert": "Certificates",
|
||||
"chain": "Digital Identity & Blockchain"
|
||||
},
|
||||
"timeline": {
|
||||
"expandMedia": "View images ({n})",
|
||||
"collapse": "Collapse"
|
||||
},
|
||||
"chain": {
|
||||
"archiveNo": "Archive No.",
|
||||
"code": "Trace Code",
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
"cert": "认证文件",
|
||||
"chain": "数字身份与区块链存证"
|
||||
},
|
||||
"timeline": {
|
||||
"expandMedia": "查看图片({n})",
|
||||
"collapse": "收起图片"
|
||||
},
|
||||
"chain": {
|
||||
"archiveNo": "档案编号",
|
||||
"code": "唯一追溯码",
|
||||
|
||||
+82
-24
@@ -98,19 +98,22 @@
|
||||
<div class="tl-title">{{ n.title }}</div>
|
||||
<div class="tl-meta muted">{{ [fmtDate(n.occurredAt), n.location].filter(Boolean).join(' · ') }}</div>
|
||||
<div v-if="n.description" class="tl-desc">{{ n.description }}</div>
|
||||
<div v-if="n.media?.length" class="tl-media">
|
||||
<template v-for="(m, j) in n.media" :key="j">
|
||||
<video
|
||||
v-if="isVideo(m)"
|
||||
:src="m.url"
|
||||
class="tl-video"
|
||||
controls
|
||||
playsinline
|
||||
preload="metadata"
|
||||
/>
|
||||
<img v-else :src="m.url" loading="lazy" @click="openViewer([m], 0)" />
|
||||
</template>
|
||||
</div>
|
||||
<template v-if="n.media?.length">
|
||||
<button class="tl-toggle" @click="toggleNode(i)">
|
||||
<span class="tl-toggle-ico" :class="{ open: expanded.has(i) }">▸</span>
|
||||
{{ expanded.has(i) ? t('timeline.collapse') : t('timeline.expandMedia', { n: n.media.length }) }}
|
||||
</button>
|
||||
<div v-if="expanded.has(i)" class="tl-media">
|
||||
<div v-for="(m, j) in n.media" :key="j" class="tl-media-item" @click="openViewer(n.media, j)">
|
||||
<div class="tl-media-thumb">
|
||||
<video v-if="isVideo(m)" :src="m.url" muted playsinline preload="metadata" />
|
||||
<img v-else :src="m.url" loading="lazy" />
|
||||
<div v-if="isVideo(m)" class="tl-play">▶</div>
|
||||
</div>
|
||||
<div v-if="m.name" class="tl-cap text-ellipsis">{{ m.name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -206,6 +209,14 @@ const viewerShow = ref(false);
|
||||
const viewerItems = ref<any[]>([]);
|
||||
const viewerStart = ref(0);
|
||||
|
||||
// 节点图片默认收缩,避免页面过长;点击展开
|
||||
const expanded = ref<Set<number>>(new Set());
|
||||
function toggleNode(i: number) {
|
||||
const s = new Set(expanded.value);
|
||||
s.has(i) ? s.delete(i) : s.add(i);
|
||||
expanded.value = s;
|
||||
}
|
||||
|
||||
const otherLangLabel = computed(() => (locale.value === 'zh-CN' ? 'EN' : '中文'));
|
||||
const stateKey = computed(() => {
|
||||
const s = data.value?.status;
|
||||
@@ -260,6 +271,7 @@ async function load(code: string) {
|
||||
loading.value = true;
|
||||
data.value = null;
|
||||
viewerShow.value = false;
|
||||
expanded.value = new Set();
|
||||
try {
|
||||
data.value = await fetchTrace(code);
|
||||
} catch {
|
||||
@@ -502,23 +514,69 @@ watch(
|
||||
font-size: 13px;
|
||||
color: #374151;
|
||||
}
|
||||
.tl-toggle {
|
||||
margin-top: 8px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
border: 1px solid #d0d7e2;
|
||||
background: #f4f7fc;
|
||||
color: var(--brand-2);
|
||||
border-radius: 999px;
|
||||
padding: 4px 12px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tl-toggle-ico {
|
||||
display: inline-block;
|
||||
transition: transform 0.18s ease;
|
||||
}
|
||||
.tl-toggle-ico.open {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.tl-media {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
.tl-media img {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
object-fit: cover;
|
||||
.tl-media-item {
|
||||
flex-shrink: 0;
|
||||
width: 92px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tl-media-thumb {
|
||||
position: relative;
|
||||
width: 92px;
|
||||
height: 92px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: #e7ecf3;
|
||||
}
|
||||
.tl-video {
|
||||
.tl-media-thumb img,
|
||||
.tl-media-thumb video {
|
||||
width: 100%;
|
||||
max-height: 220px;
|
||||
border-radius: 8px;
|
||||
background: #000;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.tl-play {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #fff;
|
||||
font-size: 22px;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
.tl-cap {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
margin-top: 4px;
|
||||
text-align: center;
|
||||
}
|
||||
.cert-grid {
|
||||
display: grid;
|
||||
|
||||
Reference in New Issue
Block a user