feat: C端展示区改为单张居中无缝轮播并接入PhotoSwipe图片视频查看器,轮播间隔支持后台配置
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -78,4 +78,5 @@
|
|||||||
- 脚本修复(四,2026-06-29):排查并修复 `dev.py` 报 `P1000 Authentication failed (artveris)`。真因有二:① 宿主机另一项目 `E:\code\remote\jvfu` 的 `jvfu_mysql` 占用了 3306,`localhost:3306` 命中了错误的库;② MySQL 8 `caching_sha2_password` 冷启动需安全连接换公钥,Prisma/pymysql 走明文 TCP 首次鉴权失败。修复:① `config.yaml` 改宿主端口 MySQL→3307、Redis→6380(容器内仍 3306/6379),与他项目共存、不动他项目;② 两个 compose 加 `--default-authentication-plugin=mysql_native_password`,并 `down -v` 重置数据卷使账号以 native_password 重建;③ `_lib.wait_db_auth` 用 pymysql 真账号轮询鉴权就绪,替代不可靠的 `wait_port`+`sleep(3)`,auto/manual 模式都先确认可鉴权再迁移;超时给出含"重置数据卷/检查凭据"的清晰提示。已实测冷启动 dev.py 全流程通过(3307 连库、迁移、种子、三端 200)。
|
- 脚本修复(四,2026-06-29):排查并修复 `dev.py` 报 `P1000 Authentication failed (artveris)`。真因有二:① 宿主机另一项目 `E:\code\remote\jvfu` 的 `jvfu_mysql` 占用了 3306,`localhost:3306` 命中了错误的库;② MySQL 8 `caching_sha2_password` 冷启动需安全连接换公钥,Prisma/pymysql 走明文 TCP 首次鉴权失败。修复:① `config.yaml` 改宿主端口 MySQL→3307、Redis→6380(容器内仍 3306/6379),与他项目共存、不动他项目;② 两个 compose 加 `--default-authentication-plugin=mysql_native_password`,并 `down -v` 重置数据卷使账号以 native_password 重建;③ `_lib.wait_db_auth` 用 pymysql 真账号轮询鉴权就绪,替代不可靠的 `wait_port`+`sleep(3)`,auto/manual 模式都先确认可鉴权再迁移;超时给出含"重置数据卷/检查凭据"的清晰提示。已实测冷启动 dev.py 全流程通过(3307 连库、迁移、种子、三端 200)。
|
||||||
- 脚本修复(五,2026-06-29):修复 docker_build.py / docker_dev.py。问题与修复:① 缺 `.dockerignore` 导致 `COPY` 把宿主机 node_modules 覆盖容器内已装依赖(tsc/prisma 找不到)→ 新增根 `.dockerignore` 忽略 node_modules/dist 等;② corepack 默认拉 pnpm 11 与 Node20 不兼容(ERR_UNKNOWN_BUILTIN_MODULE)→ 根 package.json 固定 `packageManager: pnpm@10.28.0`,Dockerfile 加 `COREPACK_ENABLE_DOWNLOAD_PROMPT=0`;③ Dockerfile 只复制部分 workspace 清单致 frozen 安装不全 → 复制全部 app/包清单后全量安装;④ 运行期 prisma CLI 路径错(pnpm 隔离布局在 apps/api/node_modules)→ CMD 改 `node node_modules/prisma/build/index.js`。基础镜像经 daocloud 镜像拉取 node:20-slim / nginx:alpine(本机无法直连 docker.io)。已实测:docker_build.py 构建 API 镜像成功、docker_dev.py 全栈启动(mysql healthy、api Up、admin:80 / h5:8080 / /api/health 全 200)、--down 正常。
|
- 脚本修复(五,2026-06-29):修复 docker_build.py / docker_dev.py。问题与修复:① 缺 `.dockerignore` 导致 `COPY` 把宿主机 node_modules 覆盖容器内已装依赖(tsc/prisma 找不到)→ 新增根 `.dockerignore` 忽略 node_modules/dist 等;② corepack 默认拉 pnpm 11 与 Node20 不兼容(ERR_UNKNOWN_BUILTIN_MODULE)→ 根 package.json 固定 `packageManager: pnpm@10.28.0`,Dockerfile 加 `COREPACK_ENABLE_DOWNLOAD_PROMPT=0`;③ Dockerfile 只复制部分 workspace 清单致 frozen 安装不全 → 复制全部 app/包清单后全量安装;④ 运行期 prisma CLI 路径错(pnpm 隔离布局在 apps/api/node_modules)→ CMD 改 `node node_modules/prisma/build/index.js`。基础镜像经 daocloud 镜像拉取 node:20-slim / nginx:alpine(本机无法直连 docker.io)。已实测:docker_build.py 构建 API 镜像成功、docker_dev.py 全栈启动(mysql healthy、api Up、admin:80 / h5:8080 / /api/health 全 200)、--down 正常。
|
||||||
- 脚本修复(三):彻底根治 `EADDRINUSE` 与"停止后残留服务"。要点:① 启动前用 `kill_project_servers()` **按命令行特征**(项目路径 + nest/vite/dist·main 标记)清掉所有残留服务,能清除处于 idle、当前不监听端口因而按端口找不到的 `nest --watch` 监视器(这是按端口清理会漏掉、进而被其自动重启抢端口的真因);② 三端子进程加入 `KILL_ON_JOB_CLOSE` 的 Windows Job(`CREATE_SUSPENDED` 挂起创建→加入 Job→`NtResumeProcess` 恢复,避免漏掉先派生的孙进程;ctypes 须显式 `restype/argtypes`,否则 64 位 HANDLE 被截断导致 Job 失效);③ `install_console_ctrl_handler` 用 `SetConsoleCtrlHandler` 在 OS 层拦截 Ctrl+C / Ctrl+Break / 关闭终端 / 注销 / 关机,统一 `stop_all`(taskkill /F /T 整树) + `kill_project_servers` 清理(带线程锁去重,finally 双保险)。已端到端实测(启动→CTRL_BREAK 强杀):三端均监听、nest watch 仅 1 个、无 EADDRINUSE;停止后残留 node 进程=0、端口全部释放(PASS)。
|
- 脚本修复(三):彻底根治 `EADDRINUSE` 与"停止后残留服务"。要点:① 启动前用 `kill_project_servers()` **按命令行特征**(项目路径 + nest/vite/dist·main 标记)清掉所有残留服务,能清除处于 idle、当前不监听端口因而按端口找不到的 `nest --watch` 监视器(这是按端口清理会漏掉、进而被其自动重启抢端口的真因);② 三端子进程加入 `KILL_ON_JOB_CLOSE` 的 Windows Job(`CREATE_SUSPENDED` 挂起创建→加入 Job→`NtResumeProcess` 恢复,避免漏掉先派生的孙进程;ctypes 须显式 `restype/argtypes`,否则 64 位 HANDLE 被截断导致 Job 失效);③ `install_console_ctrl_handler` 用 `SetConsoleCtrlHandler` 在 OS 层拦截 Ctrl+C / Ctrl+Break / 关闭终端 / 注销 / 关机,统一 `stop_all`(taskkill /F /T 整树) + `kill_project_servers` 清理(带线程锁去重,finally 双保险)。已端到端实测(启动→CTRL_BREAK 强杀):三端均监听、nest watch 仅 1 个、无 EADDRINUSE;停止后残留 node 进程=0、端口全部释放(PASS)。
|
||||||
|
- C 端展示区轮播 + 详情查看器升级(2026-06-30):① 顶部媒体区由"静态横向列表"改为**单张居中、两侧露出相邻媒体边界、定时切换带动画的轮播**(`Trace.vue`):首尾各加一张克隆,滑到克隆张后在 `transitionend` 时无动画跳回真实张,实现"最后一张→第一张"真正无缝循环(手动/自动皆然);自动切换间隔由后台设置,触摸/悬停暂停、离开恢复;支持指针拖动切换(纵向手势让位页面滚动)、底部圆点指示+计数、PC 悬停显示左右箭头。视频仍是封面卡片不自动播放。② 轮播速度配置项:后端 `settings` 新增 `carouselInterval`(单张停留秒数,支持小数,0=不自动切换),`EDITABLE_KEYS` 放行、`/settings/public` 下发;Admin 设置页加"C 端轮播间隔(秒)"数字输入(含中英 i18n);C 端 `onMounted` 读取。③ **踩坑**:PC 点击卡片打不开查看器,根因是拖动逻辑在 `pointerdown` 即 `setPointerCapture` 导致后续 `click` 被改派到容器——改为仅在确认横向拖动后才捕获指针。④ 图片/视频详情查看器**改用 PhotoSwipe v5**(MIT 商用免费,经用户确认选型)替换自写 `MediaViewer.vue`(已删除):新增 `apps/h5/src/composables/openMediaViewer.ts`,图片支持双击/双指/滚轮缩放·拖动·滑动切换·下滑关闭、`loop:true` 循环;视频项用 `contentLoad` 钩子渲染自定义 `<video controls>`、切走/关闭自动暂停;图片打开前预读真实宽高(带缓存)供 PhotoSwipe 缩放居中。新增依赖 `photoswipe`。验证:`pnpm --filter @artveris/h5 build` 通过。
|
||||||
|
|
||||||
|
|||||||
@@ -307,6 +307,8 @@
|
|||||||
"appName": "Platform Name",
|
"appName": "Platform Name",
|
||||||
"logRetentionDays": "Log Retention (days)",
|
"logRetentionDays": "Log Retention (days)",
|
||||||
"watermarkText": "Certificate Watermark",
|
"watermarkText": "Certificate Watermark",
|
||||||
|
"carouselInterval": "H5 Carousel Interval (s)",
|
||||||
|
"carouselIntervalHint": "Seconds each media stays; decimals allowed. 0 disables auto-advance (manual loop still works).",
|
||||||
"saved": "Settings saved"
|
"saved": "Settings saved"
|
||||||
},
|
},
|
||||||
"profile": {
|
"profile": {
|
||||||
|
|||||||
@@ -307,6 +307,8 @@
|
|||||||
"appName": "平台名称",
|
"appName": "平台名称",
|
||||||
"logRetentionDays": "日志保留天数",
|
"logRetentionDays": "日志保留天数",
|
||||||
"watermarkText": "证书水印文案",
|
"watermarkText": "证书水印文案",
|
||||||
|
"carouselInterval": "C 端轮播间隔(秒)",
|
||||||
|
"carouselIntervalHint": "每张媒体停留秒数,支持小数;填 0 则不自动切换(仍可手动循环切换)",
|
||||||
"saved": "设置已保存"
|
"saved": "设置已保存"
|
||||||
},
|
},
|
||||||
"profile": {
|
"profile": {
|
||||||
|
|||||||
@@ -11,6 +11,19 @@
|
|||||||
<n-form-item :label="t('pages.settings.watermarkText')">
|
<n-form-item :label="t('pages.settings.watermarkText')">
|
||||||
<n-input v-model:value="form.watermarkText" />
|
<n-input v-model:value="form.watermarkText" />
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
|
<n-form-item :label="t('pages.settings.carouselInterval')">
|
||||||
|
<div style="display: flex; flex-direction: column; gap: 4px">
|
||||||
|
<n-input-number
|
||||||
|
v-model:value="form.carouselInterval"
|
||||||
|
:min="0"
|
||||||
|
:max="30"
|
||||||
|
:step="0.5"
|
||||||
|
:precision="1"
|
||||||
|
style="width: 220px"
|
||||||
|
/>
|
||||||
|
<span style="font-size: 12px; color: #999">{{ t('pages.settings.carouselIntervalHint') }}</span>
|
||||||
|
</div>
|
||||||
|
</n-form-item>
|
||||||
<n-button type="primary" :loading="saving" @click="save">{{ t('common.action.save') }}</n-button>
|
<n-button type="primary" :loading="saving" @click="save">{{ t('common.action.save') }}</n-button>
|
||||||
</n-form>
|
</n-form>
|
||||||
</n-card>
|
</n-card>
|
||||||
@@ -25,10 +38,16 @@ import { message } from '@/utils/feedback';
|
|||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const saving = ref(false);
|
const saving = ref(false);
|
||||||
const form = reactive<{ appName: string; logRetentionDays: number; watermarkText: string }>({
|
const form = reactive<{
|
||||||
|
appName: string;
|
||||||
|
logRetentionDays: number;
|
||||||
|
watermarkText: string;
|
||||||
|
carouselInterval: number;
|
||||||
|
}>({
|
||||||
appName: '',
|
appName: '',
|
||||||
logRetentionDays: 365,
|
logRetentionDays: 365,
|
||||||
watermarkText: '',
|
watermarkText: '',
|
||||||
|
carouselInterval: 3,
|
||||||
});
|
});
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
@@ -36,6 +55,7 @@ async function load() {
|
|||||||
form.appName = s.appName || '';
|
form.appName = s.appName || '';
|
||||||
form.logRetentionDays = Number(s.logRetentionDays || 365);
|
form.logRetentionDays = Number(s.logRetentionDays || 365);
|
||||||
form.watermarkText = s.watermarkText || '';
|
form.watermarkText = s.watermarkText || '';
|
||||||
|
form.carouselInterval = Number(s.carouselInterval ?? 3);
|
||||||
}
|
}
|
||||||
async function save() {
|
async function save() {
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
@@ -44,6 +64,7 @@ async function save() {
|
|||||||
appName: form.appName,
|
appName: form.appName,
|
||||||
logRetentionDays: String(form.logRetentionDays),
|
logRetentionDays: String(form.logRetentionDays),
|
||||||
watermarkText: form.watermarkText,
|
watermarkText: form.watermarkText,
|
||||||
|
carouselInterval: String(form.carouselInterval),
|
||||||
});
|
});
|
||||||
message.success(t('pages.settings.saved'));
|
message.success(t('pages.settings.saved'));
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class SettingsController {
|
|||||||
@ApiOperation({ summary: '获取公开设置(应用名等)' })
|
@ApiOperation({ summary: '获取公开设置(应用名等)' })
|
||||||
async getPublic() {
|
async getPublic() {
|
||||||
const all = await this.settingsService.getAll();
|
const all = await this.settingsService.getAll();
|
||||||
return { appName: all.appName };
|
return { appName: all.appName, carouselInterval: all.carouselInterval };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
|
|||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { PrismaService } from '../prisma/prisma.service';
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
|
|
||||||
const EDITABLE_KEYS = ['appName', 'logRetentionDays', 'watermarkText'];
|
const EDITABLE_KEYS = ['appName', 'logRetentionDays', 'watermarkText', 'carouselInterval'];
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SettingsService {
|
export class SettingsService {
|
||||||
@@ -17,6 +17,8 @@ export class SettingsService {
|
|||||||
appName: this.config.get<string>('appName') || '',
|
appName: this.config.get<string>('appName') || '',
|
||||||
logRetentionDays: String(this.config.get<number>('logRetentionDays') || 365),
|
logRetentionDays: String(this.config.get<number>('logRetentionDays') || 365),
|
||||||
watermarkText: this.config.get<string>('watermarkText') || '仅供溯源核验使用',
|
watermarkText: this.config.get<string>('watermarkText') || '仅供溯源核验使用',
|
||||||
|
// C 端顶部媒体轮播:单张停留秒数(支持小数),0 表示不自动切换
|
||||||
|
carouselInterval: '3',
|
||||||
};
|
};
|
||||||
for (const r of rows) map[r.key] = r.value;
|
for (const r of rows) map[r.key] = r.value;
|
||||||
return map;
|
return map;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
|
"photoswipe": "^5.4.4",
|
||||||
"vue": "^3.5.13",
|
"vue": "^3.5.13",
|
||||||
"vue-i18n": "^9.14.2",
|
"vue-i18n": "^9.14.2",
|
||||||
"vue-router": "^4.5.0"
|
"vue-router": "^4.5.0"
|
||||||
|
|||||||
@@ -1,355 +0,0 @@
|
|||||||
<template>
|
|
||||||
<transition name="viewer-fade">
|
|
||||||
<div v-if="show" class="viewer" @click.self="onBackdrop">
|
|
||||||
<!-- 顶部工具栏 -->
|
|
||||||
<div class="bar">
|
|
||||||
<span class="counter" v-if="items.length > 1">{{ current + 1 }} / {{ items.length }}</span>
|
|
||||||
<span class="spacer" />
|
|
||||||
<template v-if="!curIsVideo">
|
|
||||||
<button class="tool" :aria-label="t('viewer.zoomOut')" @click="zoomOut">−</button>
|
|
||||||
<button class="tool" :aria-label="t('viewer.reset')" @click="resetTransform">⟲</button>
|
|
||||||
<button class="tool" :aria-label="t('viewer.zoomIn')" @click="zoomIn">+</button>
|
|
||||||
</template>
|
|
||||||
<button class="tool close" :aria-label="t('viewer.close')" @click="close">×</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 左右切换 -->
|
|
||||||
<button v-if="items.length > 1" class="nav prev" :aria-label="t('viewer.prev')" @click.stop="prev">‹</button>
|
|
||||||
<button v-if="items.length > 1" class="nav next" :aria-label="t('viewer.next')" @click.stop="next">›</button>
|
|
||||||
|
|
||||||
<!-- 媒体区 -->
|
|
||||||
<div ref="stageEl" class="stage">
|
|
||||||
<video
|
|
||||||
v-if="curIsVideo"
|
|
||||||
:key="cur?.url"
|
|
||||||
class="media-video"
|
|
||||||
:src="cur?.url"
|
|
||||||
controls
|
|
||||||
autoplay
|
|
||||||
playsinline
|
|
||||||
@click.stop
|
|
||||||
/>
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { computed, ref, watch } from 'vue';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
|
|
||||||
interface MediaItem {
|
|
||||||
url?: string;
|
|
||||||
name?: string;
|
|
||||||
type?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = withDefaults(
|
|
||||||
defineProps<{ show: boolean; items: MediaItem[]; start?: number }>(),
|
|
||||||
{ start: 0 },
|
|
||||||
);
|
|
||||||
const emit = defineEmits<{ (e: 'update:show', v: boolean): void }>();
|
|
||||||
const { t } = useI18n();
|
|
||||||
|
|
||||||
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 || dragging ? 'none' : 'transform 0.18s ease',
|
|
||||||
cursor: scale.value > 1 ? (dragging ? 'grabbing' : 'grab') : 'zoom-in',
|
|
||||||
}));
|
|
||||||
|
|
||||||
function isVideo(m?: MediaItem) {
|
|
||||||
return !!m && (m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(m.url || ''));
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetTransform() {
|
|
||||||
scale.value = 1;
|
|
||||||
tx.value = 0;
|
|
||||||
ty.value = 0;
|
|
||||||
}
|
|
||||||
function close() {
|
|
||||||
emit('update:show', false);
|
|
||||||
}
|
|
||||||
function onBackdrop() {
|
|
||||||
if (scale.value === 1) close();
|
|
||||||
else resetTransform();
|
|
||||||
}
|
|
||||||
function prev() {
|
|
||||||
current.value = (current.value - 1 + props.items.length) % props.items.length;
|
|
||||||
resetTransform();
|
|
||||||
}
|
|
||||||
function next() {
|
|
||||||
current.value = (current.value + 1) % props.items.length;
|
|
||||||
resetTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
function clampScale(s: number) {
|
|
||||||
return Math.min(6, Math.max(1, s));
|
|
||||||
}
|
|
||||||
// 按"放大后图片实际溢出可视区"的尺寸约束平移,使拖动恰好能到达图片边缘
|
|
||||||
function clampOffset() {
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
function zoomIn() {
|
|
||||||
scale.value = clampScale(scale.value * 1.4);
|
|
||||||
clampOffset();
|
|
||||||
}
|
|
||||||
function zoomOut() {
|
|
||||||
scale.value = clampScale(scale.value / 1.4);
|
|
||||||
if (scale.value === 1) {
|
|
||||||
tx.value = 0;
|
|
||||||
ty.value = 0;
|
|
||||||
} else {
|
|
||||||
clampOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onWheel(e: WheelEvent) {
|
|
||||||
scale.value = clampScale(scale.value * (e.deltaY < 0 ? 1.15 : 0.87));
|
|
||||||
if (scale.value === 1) {
|
|
||||||
tx.value = 0;
|
|
||||||
ty.value = 0;
|
|
||||||
} else {
|
|
||||||
clampOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onDblClick() {
|
|
||||||
if (scale.value > 1) resetTransform();
|
|
||||||
else scale.value = 2.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 触摸:单指平移、双指缩放 */
|
|
||||||
let gesturing = false;
|
|
||||||
let mode: 'none' | 'pan' | 'pinch' = 'none';
|
|
||||||
let startDist = 0;
|
|
||||||
let startScale = 1;
|
|
||||||
let panX = 0;
|
|
||||||
let panY = 0;
|
|
||||||
|
|
||||||
function dist(a: Touch, b: Touch) {
|
|
||||||
return Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY);
|
|
||||||
}
|
|
||||||
function onTouchStart(e: TouchEvent) {
|
|
||||||
gesturing = true;
|
|
||||||
if (e.touches.length >= 2) {
|
|
||||||
mode = 'pinch';
|
|
||||||
startDist = dist(e.touches[0], e.touches[1]);
|
|
||||||
startScale = scale.value;
|
|
||||||
} else if (e.touches.length === 1) {
|
|
||||||
mode = 'pan';
|
|
||||||
panX = e.touches[0].clientX - tx.value;
|
|
||||||
panY = e.touches[0].clientY - ty.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onTouchMove(e: TouchEvent) {
|
|
||||||
if (mode === 'pinch' && e.touches.length >= 2) {
|
|
||||||
const d = dist(e.touches[0], e.touches[1]);
|
|
||||||
scale.value = clampScale(startScale * (d / (startDist || 1)));
|
|
||||||
if (scale.value === 1) {
|
|
||||||
tx.value = 0;
|
|
||||||
ty.value = 0;
|
|
||||||
} else {
|
|
||||||
clampOffset();
|
|
||||||
}
|
|
||||||
} else if (mode === 'pan' && e.touches.length === 1 && scale.value > 1) {
|
|
||||||
tx.value = e.touches[0].clientX - panX;
|
|
||||||
ty.value = e.touches[0].clientY - panY;
|
|
||||||
clampOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onTouchEnd(e: TouchEvent) {
|
|
||||||
if (e.touches.length === 0) {
|
|
||||||
mode = 'none';
|
|
||||||
gesturing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 鼠标拖动(桌面端):放大后可拖动查看四周细节 */
|
|
||||||
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) => {
|
|
||||||
if (v) {
|
|
||||||
current.value = Math.min(props.start, Math.max(0, props.items.length - 1));
|
|
||||||
resetTransform();
|
|
||||||
document.body.style.overflow = 'hidden';
|
|
||||||
} else {
|
|
||||||
document.body.style.overflow = '';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.viewer {
|
|
||||||
position: fixed;
|
|
||||||
inset: 0;
|
|
||||||
z-index: 100;
|
|
||||||
background: rgba(0, 0, 0, 0.94);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
overflow: hidden;
|
|
||||||
touch-action: none;
|
|
||||||
}
|
|
||||||
.bar {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
height: 52px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
padding: 0 12px;
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
.spacer {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
.counter {
|
|
||||||
color: #fff;
|
|
||||||
font-size: 13px;
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
.tool {
|
|
||||||
width: 38px;
|
|
||||||
height: 38px;
|
|
||||||
border-radius: 50%;
|
|
||||||
border: none;
|
|
||||||
background: rgba(255, 255, 255, 0.16);
|
|
||||||
color: #fff;
|
|
||||||
font-size: 20px;
|
|
||||||
line-height: 38px;
|
|
||||||
text-align: center;
|
|
||||||
cursor: pointer;
|
|
||||||
-webkit-tap-highlight-color: transparent;
|
|
||||||
}
|
|
||||||
.tool:active {
|
|
||||||
background: rgba(255, 255, 255, 0.32);
|
|
||||||
}
|
|
||||||
.tool.close {
|
|
||||||
font-size: 24px;
|
|
||||||
}
|
|
||||||
.nav {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
width: 42px;
|
|
||||||
height: 64px;
|
|
||||||
border: none;
|
|
||||||
background: rgba(255, 255, 255, 0.12);
|
|
||||||
color: #fff;
|
|
||||||
font-size: 30px;
|
|
||||||
cursor: pointer;
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
.nav.prev {
|
|
||||||
left: 0;
|
|
||||||
border-radius: 0 8px 8px 0;
|
|
||||||
}
|
|
||||||
.nav.next {
|
|
||||||
right: 0;
|
|
||||||
border-radius: 8px 0 0 8px;
|
|
||||||
}
|
|
||||||
.stage {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
.media-img {
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 100%;
|
|
||||||
object-fit: contain;
|
|
||||||
will-change: transform;
|
|
||||||
user-select: none;
|
|
||||||
-webkit-user-drag: none;
|
|
||||||
}
|
|
||||||
.media-video {
|
|
||||||
max-width: 100%;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
.viewer-fade-enter-from,
|
|
||||||
.viewer-fade-leave-to {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
||||||
|
import PhotoSwipe from 'photoswipe';
|
||||||
|
import 'photoswipe/style.css';
|
||||||
|
|
||||||
|
export interface MediaItem {
|
||||||
|
url?: string;
|
||||||
|
name?: string;
|
||||||
|
type?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isVideo(m: MediaItem) {
|
||||||
|
return !!m && (m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(m.url || ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 缓存图片真实尺寸,避免重复加载;PhotoSwipe 需要宽高才能正确缩放/居中
|
||||||
|
const sizeCache = new Map<string, { w: number; h: number }>();
|
||||||
|
function getImageSize(url: string): Promise<{ w: number; h: number }> {
|
||||||
|
const cached = sizeCache.get(url);
|
||||||
|
if (cached) return Promise.resolve(cached);
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
const dim = { w: img.naturalWidth || 1600, h: img.naturalHeight || 1200 };
|
||||||
|
sizeCache.set(url, dim);
|
||||||
|
resolve(dim);
|
||||||
|
};
|
||||||
|
img.onerror = () => resolve({ w: 1600, h: 1200 });
|
||||||
|
img.src = url;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开图片 / 视频详情查看器(基于 PhotoSwipe v5)。
|
||||||
|
* - 图片:支持双指/滚轮/双击缩放、拖动、左右滑动切换、下滑关闭。
|
||||||
|
* - 视频:渲染为可控制的 <video> 播放,切到其它张或关闭时自动暂停。
|
||||||
|
* - 循环:到最后一张的下一张回到第一张。
|
||||||
|
*/
|
||||||
|
export async function openMediaViewer(items: MediaItem[], index = 0) {
|
||||||
|
const list = (items || []).filter((m) => m && m.url);
|
||||||
|
if (!list.length) return;
|
||||||
|
const start = Math.min(Math.max(0, index), list.length - 1);
|
||||||
|
|
||||||
|
const dataSource = await Promise.all(
|
||||||
|
list.map(async (m) => {
|
||||||
|
if (isVideo(m)) {
|
||||||
|
return { type: 'video', src: m.url as string, title: m.name };
|
||||||
|
}
|
||||||
|
const { w, h } = await getImageSize(m.url as string);
|
||||||
|
return { src: m.url as string, width: w, height: h, alt: m.name, title: m.name };
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const lightbox = new PhotoSwipeLightbox({
|
||||||
|
dataSource,
|
||||||
|
index: start,
|
||||||
|
pswpModule: PhotoSwipe as any,
|
||||||
|
loop: true,
|
||||||
|
bgOpacity: 0.96,
|
||||||
|
wheelToZoom: true,
|
||||||
|
// 图片支持双击/双指/滚轮缩放;视频项无宽高,PhotoSwipe 会自动隐藏其缩放按钮
|
||||||
|
});
|
||||||
|
|
||||||
|
// 视频项:用自定义 DOM 替换默认内容
|
||||||
|
lightbox.on('contentLoad', (e: any) => {
|
||||||
|
const { content } = e;
|
||||||
|
if (content?.data?.type !== 'video') return;
|
||||||
|
e.preventDefault();
|
||||||
|
const wrap = document.createElement('div');
|
||||||
|
wrap.className = 'pswp-video';
|
||||||
|
wrap.style.cssText =
|
||||||
|
'width:100%;height:100%;display:flex;align-items:center;justify-content:center;';
|
||||||
|
const video = document.createElement('video');
|
||||||
|
video.src = content.data.src;
|
||||||
|
video.controls = true;
|
||||||
|
video.playsInline = true;
|
||||||
|
video.preload = 'metadata';
|
||||||
|
video.style.cssText = 'max-width:100%;max-height:100%;background:#000;';
|
||||||
|
wrap.appendChild(video);
|
||||||
|
content.element = wrap;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 离开当前张时暂停其视频
|
||||||
|
const pauseVideo = (e: any) => {
|
||||||
|
const v = e?.content?.element?.querySelector?.('video') as HTMLVideoElement | null;
|
||||||
|
if (v) v.pause();
|
||||||
|
};
|
||||||
|
lightbox.on('contentDeactivate', pauseVideo);
|
||||||
|
lightbox.on('close', () => {
|
||||||
|
const v = document.querySelector('.pswp .pswp-video video') as HTMLVideoElement | null;
|
||||||
|
if (v) v.pause();
|
||||||
|
});
|
||||||
|
// 关闭后销毁实例,释放键盘/尺寸监听
|
||||||
|
lightbox.on('destroy', () => {
|
||||||
|
/* PhotoSwipe 自行清理 */
|
||||||
|
});
|
||||||
|
|
||||||
|
lightbox.init();
|
||||||
|
lightbox.loadAndOpen(start);
|
||||||
|
}
|
||||||
+399
-46
@@ -38,30 +38,83 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 图片 / 视频轮播 -->
|
<!-- 图片 / 视频轮播:单张居中、两侧露出相邻媒体边界、定时切换、克隆实现无缝循环 -->
|
||||||
<div v-if="data.artwork.images?.length" class="carousel">
|
<div
|
||||||
<div
|
v-if="data.artwork.images?.length"
|
||||||
v-for="(m, i) in data.artwork.images"
|
ref="carouselEl"
|
||||||
:key="i"
|
class="carousel"
|
||||||
class="carousel-item"
|
@pointerdown="onDragStart"
|
||||||
@click="openViewer(data.artwork.images, i)"
|
@pointermove="onDragMove"
|
||||||
>
|
@pointerup="onDragEnd"
|
||||||
<video
|
@pointercancel="onDragEnd"
|
||||||
v-if="isVideo(m)"
|
@mouseenter="pauseAuto"
|
||||||
:src="m.url"
|
@mouseleave="resumeAuto"
|
||||||
class="carousel-media"
|
>
|
||||||
muted
|
<div class="carousel-track" :style="trackStyle" @transitionend="onTransitionEnd">
|
||||||
playsinline
|
<div
|
||||||
preload="metadata"
|
v-for="(s, i) in loopSlides"
|
||||||
/>
|
:key="i"
|
||||||
<img v-else :src="m.url" :alt="m.name" class="carousel-media" loading="lazy" />
|
class="carousel-slide"
|
||||||
<div v-if="isVideo(m)" class="play-overlay">
|
:class="{ current: i === pos }"
|
||||||
<svg viewBox="0 0 64 64" width="56" height="56" aria-hidden="true">
|
@click="onSlideClick(i, s)"
|
||||||
<circle cx="32" cy="32" r="30" fill="rgba(0,0,0,0.42)" />
|
>
|
||||||
<polygon points="26,21 46,32 26,43" fill="#fff" />
|
<video
|
||||||
</svg>
|
v-if="isVideo(s.media)"
|
||||||
|
:src="s.media.url"
|
||||||
|
class="carousel-media"
|
||||||
|
muted
|
||||||
|
playsinline
|
||||||
|
preload="metadata"
|
||||||
|
/>
|
||||||
|
<img v-else :src="s.media.url" :alt="s.media.name" class="carousel-media" loading="lazy" />
|
||||||
|
<div v-if="isVideo(s.media)" class="play-overlay">
|
||||||
|
<svg viewBox="0 0 64 64" width="56" height="56" aria-hidden="true">
|
||||||
|
<circle cx="32" cy="32" r="30" fill="rgba(0,0,0,0.42)" />
|
||||||
|
<polygon points="26,21 46,32 26,43" fill="#fff" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 左右切换箭头(PC 悬停显示,移动端常驻) -->
|
||||||
|
<button
|
||||||
|
v-if="data.artwork.images.length > 1"
|
||||||
|
type="button"
|
||||||
|
class="carousel-nav prev"
|
||||||
|
:aria-label="t('viewer.prev')"
|
||||||
|
@pointerdown.stop
|
||||||
|
@click.stop="go(pos - 1)"
|
||||||
|
>
|
||||||
|
‹
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="data.artwork.images.length > 1"
|
||||||
|
type="button"
|
||||||
|
class="carousel-nav next"
|
||||||
|
:aria-label="t('viewer.next')"
|
||||||
|
@pointerdown.stop
|
||||||
|
@click.stop="go(pos + 1)"
|
||||||
|
>
|
||||||
|
›
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 媒体计数 + 当前位置指示 -->
|
||||||
|
<div v-if="data.artwork.images?.length > 1" class="carousel-ind">
|
||||||
|
<div class="carousel-dots">
|
||||||
|
<button
|
||||||
|
v-for="(m, i) in data.artwork.images"
|
||||||
|
:key="i"
|
||||||
|
type="button"
|
||||||
|
class="dot"
|
||||||
|
:class="{ active: i === carouselIndex }"
|
||||||
|
:aria-label="String(i + 1)"
|
||||||
|
@click="goToReal(i)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="carousel-count">
|
||||||
|
<span v-if="isVideo(data.artwork.images[carouselIndex])" class="carousel-count-ico">▶</span>
|
||||||
|
{{ carouselIndex + 1 }} / {{ data.artwork.images.length }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 基础信息 -->
|
<!-- 基础信息 -->
|
||||||
@@ -178,9 +231,6 @@
|
|||||||
<footer class="footer muted">{{ appName }}</footer>
|
<footer class="footer muted">{{ appName }}</footer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- 媒体查看器:图片可双指缩放/拖动,视频弹窗播放 -->
|
|
||||||
<media-viewer v-model:show="viewerShow" :items="viewerItems" :start="viewerStart" />
|
|
||||||
|
|
||||||
<!-- 轻提示 -->
|
<!-- 轻提示 -->
|
||||||
<transition name="toast">
|
<transition name="toast">
|
||||||
<div v-if="toast" class="toast">{{ toast }}</div>
|
<div v-if="toast" class="toast">{{ toast }}</div>
|
||||||
@@ -189,13 +239,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref, watch } from 'vue';
|
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { fetchTrace, fetchAppInfo } from '@/api';
|
import { fetchTrace, fetchAppInfo } from '@/api';
|
||||||
import { setLocale } from '@/locales';
|
import { setLocale } from '@/locales';
|
||||||
import MediaViewer from '@/components/MediaViewer.vue';
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { t, locale } = useI18n();
|
const { t, locale } = useI18n();
|
||||||
@@ -205,10 +255,6 @@ const data = ref<any>(null);
|
|||||||
const appName = ref('');
|
const appName = ref('');
|
||||||
const toast = ref('');
|
const toast = ref('');
|
||||||
|
|
||||||
const viewerShow = ref(false);
|
|
||||||
const viewerItems = ref<any[]>([]);
|
|
||||||
const viewerStart = ref(0);
|
|
||||||
|
|
||||||
// 节点图片默认收缩,避免页面过长;点击展开
|
// 节点图片默认收缩,避免页面过长;点击展开
|
||||||
const expanded = ref<Set<number>>(new Set());
|
const expanded = ref<Set<number>>(new Set());
|
||||||
function toggleNode(i: number) {
|
function toggleNode(i: number) {
|
||||||
@@ -244,9 +290,208 @@ function safeUrl(v?: string): string {
|
|||||||
return /^(https?:\/\/|\/)/i.test(v) ? v : '';
|
return /^(https?:\/\/|\/)/i.test(v) ? v : '';
|
||||||
}
|
}
|
||||||
function openViewer(items: any[], index: number) {
|
function openViewer(items: any[], index: number) {
|
||||||
viewerItems.value = items || [];
|
openMediaViewer(items, index);
|
||||||
viewerStart.value = index;
|
}
|
||||||
viewerShow.value = true;
|
|
||||||
|
// 顶部媒体轮播:单张居中、两侧露出相邻媒体边界、定时切换并带切换动画。
|
||||||
|
// 通过在首尾各复制一张「克隆」实现无缝循环:滑到克隆张后,动画结束瞬间无动画跳回真实张,
|
||||||
|
// 因此无论手动还是自动,永远不会出现“最后一张直接跳回第一张”的违和回跳。
|
||||||
|
// 后台设置 carouselInterval = 单张停留秒数(支持小数),0 表示不自动切换(仍可手动循环)。
|
||||||
|
const carouselEl = ref<HTMLElement | null>(null);
|
||||||
|
const carouselInterval = ref(3); // 秒/张,来自 /settings/public
|
||||||
|
const pos = ref(0); // 当前在 loopSlides 中的下标
|
||||||
|
const viewW = ref(0); // 容器宽度
|
||||||
|
const slideW = ref(0); // 单张布局宽度
|
||||||
|
const stride = ref(0); // 相邻两张中心间距(含间隙)
|
||||||
|
const dragDelta = ref(0); // 拖动中的临时位移
|
||||||
|
const dragging = ref(false);
|
||||||
|
const noAnim = ref(true); // true 时禁用过渡(用于克隆瞬移、初始化、resize、拖动)
|
||||||
|
|
||||||
|
let autoTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
let ro: ResizeObserver | undefined;
|
||||||
|
let startX = 0;
|
||||||
|
let startY = 0;
|
||||||
|
let axisLocked = false;
|
||||||
|
let moved = false;
|
||||||
|
|
||||||
|
const carouselCount = computed(() => data.value?.artwork?.images?.length || 0);
|
||||||
|
// 首尾各加一张克隆:[克隆(末), 真0..真N-1, 克隆(首)]
|
||||||
|
const loopSlides = computed<{ media: any; real: number }[]>(() => {
|
||||||
|
const imgs = data.value?.artwork?.images || [];
|
||||||
|
if (imgs.length <= 1) return imgs.map((m: any, idx: number) => ({ media: m, real: idx }));
|
||||||
|
const arr: { media: any; real: number }[] = [];
|
||||||
|
arr.push({ media: imgs[imgs.length - 1], real: imgs.length - 1 });
|
||||||
|
imgs.forEach((m: any, idx: number) => arr.push({ media: m, real: idx }));
|
||||||
|
arr.push({ media: imgs[0], real: 0 });
|
||||||
|
return arr;
|
||||||
|
});
|
||||||
|
// 当前真实下标(用于计数 / 圆点高亮)
|
||||||
|
const carouselIndex = computed(() => {
|
||||||
|
const n = carouselCount.value;
|
||||||
|
if (n <= 1) return 0;
|
||||||
|
return ((pos.value - 1) % n + n) % n;
|
||||||
|
});
|
||||||
|
const intervalMs = computed(() => Math.round(carouselInterval.value * 1000));
|
||||||
|
const autoEnabled = computed(() => intervalMs.value > 0 && carouselCount.value > 1);
|
||||||
|
|
||||||
|
// 轨道位移:把第 pos 张居中;拖动时叠加 dragDelta
|
||||||
|
const baseTrackX = computed(() => (viewW.value - slideW.value) / 2 - pos.value * stride.value);
|
||||||
|
const trackStyle = computed(() => ({
|
||||||
|
transform: `translateX(${baseTrackX.value + dragDelta.value}px)`,
|
||||||
|
transitionDuration: noAnim.value || dragging.value ? '0ms' : '450ms',
|
||||||
|
}));
|
||||||
|
|
||||||
|
function measureCarousel() {
|
||||||
|
const el = carouselEl.value;
|
||||||
|
if (!el) return;
|
||||||
|
viewW.value = el.clientWidth;
|
||||||
|
const track = el.querySelector('.carousel-track') as HTMLElement | null;
|
||||||
|
const slides = track?.children;
|
||||||
|
if (slides && slides.length) {
|
||||||
|
const a = slides[0] as HTMLElement;
|
||||||
|
slideW.value = a.offsetWidth; // offset* 取布局尺寸,不受 CSS transform 缩放影响
|
||||||
|
stride.value =
|
||||||
|
slides.length > 1 ? (slides[1] as HTMLElement).offsetLeft - a.offsetLeft : a.offsetWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearAuto() {
|
||||||
|
if (autoTimer) {
|
||||||
|
clearTimeout(autoTimer);
|
||||||
|
autoTimer = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function scheduleAuto() {
|
||||||
|
clearAuto();
|
||||||
|
if (!autoEnabled.value) return;
|
||||||
|
autoTimer = setTimeout(() => next(), intervalMs.value);
|
||||||
|
}
|
||||||
|
function pauseAuto() {
|
||||||
|
clearAuto();
|
||||||
|
}
|
||||||
|
function resumeAuto() {
|
||||||
|
scheduleAuto();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 切换到 loopSlides 的第 p 张(带动画),并重置自动计时
|
||||||
|
function go(p: number) {
|
||||||
|
pos.value = p;
|
||||||
|
scheduleAuto();
|
||||||
|
}
|
||||||
|
function next() {
|
||||||
|
go(pos.value + 1);
|
||||||
|
}
|
||||||
|
// 跳到真实第 i 张
|
||||||
|
function goToReal(i: number) {
|
||||||
|
go(i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 动画结束后若停在克隆张,则无动画瞬移到对应真实张,实现无缝循环
|
||||||
|
async function onTransitionEnd(e: TransitionEvent) {
|
||||||
|
// 仅响应轨道自身的 transform 过渡;忽略子卡片缩放过渡的冒泡事件
|
||||||
|
if (e.target !== e.currentTarget || e.propertyName !== 'transform') return;
|
||||||
|
const n = carouselCount.value;
|
||||||
|
if (n <= 1) return;
|
||||||
|
let target = pos.value;
|
||||||
|
if (pos.value > n) target = pos.value - n; // 越过末尾克隆 → 回到真实首部
|
||||||
|
else if (pos.value < 1) target = pos.value + n; // 越过开头克隆 → 回到真实尾部
|
||||||
|
if (target === pos.value) return;
|
||||||
|
noAnim.value = true;
|
||||||
|
pos.value = target;
|
||||||
|
await nextTick();
|
||||||
|
requestAnimationFrame(() =>
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
noAnim.value = false;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSlideClick(i: number, slide: { media: any; real: number }) {
|
||||||
|
if (moved) {
|
||||||
|
moved = false;
|
||||||
|
return; // 刚才是拖动,不触发点击
|
||||||
|
}
|
||||||
|
if (i === pos.value) {
|
||||||
|
openViewer(data.value?.artwork?.images || [], slide.real); // 点当前张 → 打开查看器
|
||||||
|
} else {
|
||||||
|
go(i); // 点两侧露出的相邻张 → 切到它
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDragStart(e: PointerEvent) {
|
||||||
|
if (carouselCount.value <= 1) return;
|
||||||
|
dragging.value = true;
|
||||||
|
moved = false;
|
||||||
|
axisLocked = false;
|
||||||
|
startX = e.clientX;
|
||||||
|
startY = e.clientY;
|
||||||
|
dragDelta.value = 0;
|
||||||
|
pauseAuto();
|
||||||
|
// 注意:不在此处 setPointerCapture,否则会把后续 click 改派到容器,
|
||||||
|
// 导致 PC 上卡片的 @click 不触发、无法点击查看。仅在确认拖动后再捕获。
|
||||||
|
}
|
||||||
|
function onDragMove(e: PointerEvent) {
|
||||||
|
if (!dragging.value) return;
|
||||||
|
const dx = e.clientX - startX;
|
||||||
|
const dy = e.clientY - startY;
|
||||||
|
if (!axisLocked) {
|
||||||
|
if (Math.abs(dx) < 6 && Math.abs(dy) < 6) return;
|
||||||
|
axisLocked = true;
|
||||||
|
if (Math.abs(dy) > Math.abs(dx)) {
|
||||||
|
// 纵向手势 → 放弃拖动,交还页面滚动
|
||||||
|
dragging.value = false;
|
||||||
|
dragDelta.value = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 确认为横向拖动后再捕获指针,保证拖出元素也能继续跟手
|
||||||
|
carouselEl.value?.setPointerCapture?.(e.pointerId);
|
||||||
|
}
|
||||||
|
moved = true;
|
||||||
|
dragDelta.value = dx;
|
||||||
|
}
|
||||||
|
function onDragEnd(e?: PointerEvent) {
|
||||||
|
if (!dragging.value) return;
|
||||||
|
dragging.value = false;
|
||||||
|
const dd = dragDelta.value;
|
||||||
|
dragDelta.value = 0;
|
||||||
|
if (e && carouselEl.value?.hasPointerCapture?.(e.pointerId)) {
|
||||||
|
carouselEl.value.releasePointerCapture(e.pointerId);
|
||||||
|
}
|
||||||
|
const threshold = Math.max(40, slideW.value * 0.18);
|
||||||
|
if (dd <= -threshold) go(pos.value + 1);
|
||||||
|
else if (dd >= threshold) go(pos.value - 1);
|
||||||
|
else scheduleAuto(); // 位移不够 → 回弹(pos 不变,过渡自动复位),恢复自动
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCarouselResize() {
|
||||||
|
noAnim.value = true;
|
||||||
|
measureCarousel();
|
||||||
|
requestAnimationFrame(() =>
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
noAnim.value = false;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据 / 间隔变化时重置轮播
|
||||||
|
async function resetCarousel() {
|
||||||
|
clearAuto();
|
||||||
|
ro?.disconnect();
|
||||||
|
pos.value = carouselCount.value > 1 ? 1 : 0;
|
||||||
|
noAnim.value = true;
|
||||||
|
dragDelta.value = 0;
|
||||||
|
await nextTick();
|
||||||
|
measureCarousel();
|
||||||
|
if (carouselEl.value) {
|
||||||
|
ro = new ResizeObserver(onCarouselResize);
|
||||||
|
ro.observe(carouselEl.value);
|
||||||
|
}
|
||||||
|
requestAnimationFrame(() =>
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
noAnim.value = false;
|
||||||
|
scheduleAuto();
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
function toggleLang() {
|
function toggleLang() {
|
||||||
setLocale(locale.value === 'zh-CN' ? 'en-US' : 'zh-CN');
|
setLocale(locale.value === 'zh-CN' ? 'en-US' : 'zh-CN');
|
||||||
@@ -270,7 +515,6 @@ async function copy(text?: string) {
|
|||||||
async function load(code: string) {
|
async function load(code: string) {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
data.value = null;
|
data.value = null;
|
||||||
viewerShow.value = false;
|
|
||||||
expanded.value = new Set();
|
expanded.value = new Set();
|
||||||
try {
|
try {
|
||||||
data.value = await fetchTrace(code);
|
data.value = await fetchTrace(code);
|
||||||
@@ -285,11 +529,23 @@ onMounted(async () => {
|
|||||||
try {
|
try {
|
||||||
const info = await fetchAppInfo();
|
const info = await fetchAppInfo();
|
||||||
appName.value = info?.appName || t('app.name');
|
appName.value = info?.appName || t('app.name');
|
||||||
|
const iv = Number(info?.carouselInterval);
|
||||||
|
if (Number.isFinite(iv) && iv >= 0) carouselInterval.value = iv;
|
||||||
} catch {
|
} catch {
|
||||||
appName.value = t('app.name');
|
appName.value = t('app.name');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 数据或间隔变化时重置轮播
|
||||||
|
watch([() => data.value?.artwork?.images, carouselInterval], () => {
|
||||||
|
resetCarousel();
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
clearAuto();
|
||||||
|
ro?.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => route.params.code,
|
() => route.params.code,
|
||||||
(code) => {
|
(code) => {
|
||||||
@@ -401,23 +657,120 @@ watch(
|
|||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
.carousel {
|
.carousel {
|
||||||
display: flex;
|
|
||||||
gap: 8px;
|
|
||||||
overflow-x: auto;
|
|
||||||
scroll-snap-type: x mandatory;
|
|
||||||
padding: 0 12px;
|
|
||||||
-webkit-overflow-scrolling: touch;
|
|
||||||
}
|
|
||||||
.carousel-item {
|
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 86%;
|
overflow: hidden;
|
||||||
|
touch-action: pan-y; /* 纵向交还页面滚动,横向手势由 JS 处理 */
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
.carousel-track {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
transition-property: transform;
|
||||||
|
transition-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
|
||||||
|
will-change: transform;
|
||||||
|
}
|
||||||
|
.carousel-slide {
|
||||||
|
position: relative;
|
||||||
|
flex: 0 0 80%;
|
||||||
|
max-width: 420px;
|
||||||
height: 240px;
|
height: 240px;
|
||||||
border-radius: 14px;
|
border-radius: 14px;
|
||||||
scroll-snap-align: center;
|
|
||||||
flex-shrink: 0;
|
|
||||||
background: #e7ecf3;
|
background: #e7ecf3;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
/* 非当前张略缩小并降低不透明度,突出居中张 */
|
||||||
|
transform: scale(0.9);
|
||||||
|
opacity: 0.55;
|
||||||
|
transition:
|
||||||
|
transform 0.45s cubic-bezier(0.22, 0.61, 0.36, 1),
|
||||||
|
opacity 0.45s ease;
|
||||||
|
}
|
||||||
|
.carousel-slide.current {
|
||||||
|
transform: scale(1);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
/* 左右切换箭头 */
|
||||||
|
.carousel-nav {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
width: 36px;
|
||||||
|
height: 56px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: rgba(15, 123, 99, 0.42);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 26px;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 2;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
.carousel:hover .carousel-nav {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.carousel-nav.prev {
|
||||||
|
left: 14px;
|
||||||
|
}
|
||||||
|
.carousel-nav.next {
|
||||||
|
right: 14px;
|
||||||
|
}
|
||||||
|
.carousel-nav:active {
|
||||||
|
background: rgba(15, 123, 99, 0.7);
|
||||||
|
}
|
||||||
|
/* 触摸设备没有 hover:常驻显示,方便点击 */
|
||||||
|
@media (hover: none) {
|
||||||
|
.carousel-nav {
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* 媒体计数 + 当前位置指示 */
|
||||||
|
.carousel-ind {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.carousel-dots {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.carousel-dots .dot {
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #cfd8e3;
|
||||||
|
cursor: pointer;
|
||||||
|
transition:
|
||||||
|
width 0.25s ease,
|
||||||
|
background 0.25s ease;
|
||||||
|
}
|
||||||
|
.carousel-dots .dot.active {
|
||||||
|
width: 18px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: #0f7b63;
|
||||||
|
}
|
||||||
|
.carousel-count {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 3px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #6b7785;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
.carousel-count-ico {
|
||||||
|
font-size: 10px;
|
||||||
|
color: #0f7b63;
|
||||||
}
|
}
|
||||||
.carousel-media {
|
.carousel-media {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Generated
+9
@@ -189,6 +189,9 @@ importers:
|
|||||||
dayjs:
|
dayjs:
|
||||||
specifier: ^1.11.13
|
specifier: ^1.11.13
|
||||||
version: 1.11.21
|
version: 1.11.21
|
||||||
|
photoswipe:
|
||||||
|
specifier: ^5.4.4
|
||||||
|
version: 5.4.4
|
||||||
vue:
|
vue:
|
||||||
specifier: ^3.5.13
|
specifier: ^3.5.13
|
||||||
version: 3.5.39(typescript@5.9.3)
|
version: 3.5.39(typescript@5.9.3)
|
||||||
@@ -3116,6 +3119,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==}
|
resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|
||||||
|
photoswipe@5.4.4:
|
||||||
|
resolution: {integrity: sha512-WNFHoKrkZNnvFFhbHL93WDkW3ifwVOXSW3w1UuZZelSmgXpIGiZSNlZJq37rR8YejqME2rHs9EhH9ZvlvFH2NA==}
|
||||||
|
engines: {node: '>= 0.12.0'}
|
||||||
|
|
||||||
picocolors@1.1.1:
|
picocolors@1.1.1:
|
||||||
resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==}
|
resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==}
|
||||||
|
|
||||||
@@ -7380,6 +7387,8 @@ snapshots:
|
|||||||
|
|
||||||
path-type@4.0.0: {}
|
path-type@4.0.0: {}
|
||||||
|
|
||||||
|
photoswipe@5.4.4: {}
|
||||||
|
|
||||||
picocolors@1.1.1: {}
|
picocolors@1.1.1: {}
|
||||||
|
|
||||||
picomatch@2.3.2: {}
|
picomatch@2.3.2: {}
|
||||||
|
|||||||
Reference in New Issue
Block a user