feat: 追溯码客户端预览(TOTP式令牌保护,不激活不计数,可切换激活状态预览)
This commit is contained in:
@@ -366,7 +366,7 @@ const outboundModalTitle = computed(() => outboundMenuLabel(outboundTarget.value
|
||||
const columns = computed<DataTableColumns<any>>(() => {
|
||||
const cols: DataTableColumns<any> = [
|
||||
{ type: 'selection' },
|
||||
// 追溯码:点击打开该码的 C 端溯源页
|
||||
// 追溯码:点击进入预览页(不激活、不计数)
|
||||
{
|
||||
title: () => t('pages.traceCode.shortCode'),
|
||||
key: 'shortCode',
|
||||
@@ -376,7 +376,7 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
render: (r) =>
|
||||
h(
|
||||
'a',
|
||||
{ href: r.url, target: '_blank', rel: 'noopener', class: 'cell-link', title: t('pages.traceCode.openTrace') },
|
||||
{ class: 'cell-link', title: t('pages.traceCode.previewHint'), onClick: () => openPreview(r) },
|
||||
r.shortCode,
|
||||
),
|
||||
},
|
||||
@@ -464,7 +464,7 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 100, align: 'center' },
|
||||
// 激活时间
|
||||
{ title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 150, align: 'center', render: (r) => fmt(r.firstActivatedAt), ...sortProps('firstActivatedAt') },
|
||||
// 链接
|
||||
// 链接:拦截直跳,先告知「直接访问会激活/计数」,再让用户选预览或实际访问
|
||||
{
|
||||
title: () => t('pages.traceCode.url'),
|
||||
key: 'url',
|
||||
@@ -473,7 +473,15 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
render: (r) =>
|
||||
h(
|
||||
'a',
|
||||
{ href: r.url, target: '_blank', rel: 'noopener', style: 'color: var(--brand); text-decoration: none' },
|
||||
{
|
||||
href: r.url,
|
||||
style: 'color: var(--brand); text-decoration: none',
|
||||
title: t('pages.traceCode.visitWarnTitle'),
|
||||
onClick: (e: MouseEvent) => {
|
||||
e.preventDefault();
|
||||
confirmVisitReal(r);
|
||||
},
|
||||
},
|
||||
[r.url, h(NIcon, { component: OpenOutline, style: 'vertical-align:-2px;margin-left:4px' })],
|
||||
),
|
||||
},
|
||||
@@ -514,6 +522,68 @@ function goArtwork(id?: number) {
|
||||
router.push({ name: 'artwork-detail', params: { id: String(id) } });
|
||||
}
|
||||
|
||||
// 预览令牌缓存:令牌自取用起至少 10 分钟有效(当前+上一窗口),缓存 8 分钟内复用,过期自动重取。
|
||||
// 预览 URL 仅在点击时临时拼接,不进入行数据,因此导出永远只含真实短链。
|
||||
let previewCache: { token: string; clientBase: string; fetchedAt: number } | null = null;
|
||||
async function getPreviewInfo() {
|
||||
if (!previewCache || Date.now() - previewCache.fetchedAt > 8 * 60_000) {
|
||||
const res = await traceCodeApi.previewToken();
|
||||
previewCache = { token: res.token, clientBase: res.clientBase, fetchedAt: Date.now() };
|
||||
}
|
||||
return previewCache;
|
||||
}
|
||||
|
||||
// 先同步开空白窗口再异步填充地址,避免 await 后 window.open 被浏览器拦截
|
||||
function openPreview(row: any) {
|
||||
const win = window.open('about:blank', '_blank');
|
||||
getPreviewInfo()
|
||||
.then((info) => {
|
||||
const url = `${info.clientBase}/#/trace/preview/${encodeURIComponent(row.shortCode)}?token=${info.token}&state=inactive`;
|
||||
if (win) win.location.href = url;
|
||||
else window.open(url, '_blank');
|
||||
})
|
||||
.catch(() => {
|
||||
win?.close();
|
||||
message.error(t('pages.traceCode.previewOpenFailed'));
|
||||
});
|
||||
}
|
||||
|
||||
// 点「链接」列:告知直接访问会激活/计数,提供预览与实际两个入口
|
||||
function confirmVisitReal(row: any) {
|
||||
const d = dialog.warning({
|
||||
title: t('pages.traceCode.visitWarnTitle'),
|
||||
content: t('pages.traceCode.visitWarnContent'),
|
||||
action: () =>
|
||||
h('div', { style: 'display:flex;gap:8px;justify-content:flex-end' }, [
|
||||
h(NButton, { size: 'small', onClick: () => d.destroy() }, { default: () => t('common.action.cancel') }),
|
||||
h(
|
||||
NButton,
|
||||
{
|
||||
size: 'small',
|
||||
type: 'primary',
|
||||
onClick: () => {
|
||||
d.destroy();
|
||||
openPreview(row);
|
||||
},
|
||||
},
|
||||
{ default: () => t('pages.traceCode.visitPreview') },
|
||||
),
|
||||
h(
|
||||
NButton,
|
||||
{
|
||||
size: 'small',
|
||||
type: 'warning',
|
||||
onClick: () => {
|
||||
d.destroy();
|
||||
window.open(row.url, '_blank');
|
||||
},
|
||||
},
|
||||
{ default: () => t('pages.traceCode.visitReal') },
|
||||
),
|
||||
]),
|
||||
});
|
||||
}
|
||||
|
||||
type HeaderFilterField = 'batchId' | 'groupId' | 'status' | 'outboundStatus';
|
||||
type HeaderFilterValue = string | number | null;
|
||||
type HeaderFilterOption = { label: string; value: string | number };
|
||||
|
||||
Reference in New Issue
Block a user