feat: 追溯码客户端预览(TOTP式令牌保护,不激活不计数,可切换激活状态预览)
This commit is contained in:
@@ -24,6 +24,11 @@ export function fetchTrace(shortCode: string): Promise<any> {
|
||||
return instance.get(`/public/trace/${shortCode}`) as unknown as Promise<any>;
|
||||
}
|
||||
|
||||
// 后台预览:凭时间令牌访问,零副作用(不激活/不计数/不写日志);state 控制未激活/已激活形态
|
||||
export function fetchTracePreview(shortCode: string, token: string, state: 'inactive' | 'active'): Promise<any> {
|
||||
return instance.get(`/public/trace/${shortCode}/preview`, { params: { token, state } }) as unknown as Promise<any>;
|
||||
}
|
||||
|
||||
export function fetchAppInfo(): Promise<any> {
|
||||
return instance.get('/settings/public') as unknown as Promise<any>;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,15 @@
|
||||
"disabledTitle": "Code Disabled",
|
||||
"disabledDesc": "This code has been disabled. Please verify carefully.",
|
||||
"abnormalTitle": "Abnormal Status",
|
||||
"abnormalDesc": "This code status is abnormal. Please verify carefully."
|
||||
"abnormalDesc": "This code status is abnormal. Please verify carefully.",
|
||||
"previewExpiredTitle": "Preview Link Expired",
|
||||
"previewExpiredDesc": "Preview links are time-limited. Please reopen the preview from the admin console."
|
||||
},
|
||||
"preview": {
|
||||
"title": "Preview Mode",
|
||||
"note": "Internal preview only. No activation, no query counting.",
|
||||
"inactive": "Inactive",
|
||||
"active": "Activated"
|
||||
},
|
||||
"viewer": {
|
||||
"zoomIn": "Zoom in",
|
||||
|
||||
@@ -57,7 +57,15 @@
|
||||
"disabledTitle": "防伪码已停用",
|
||||
"disabledDesc": "该防伪码已停用,请谨慎核验。",
|
||||
"abnormalTitle": "防伪码状态异常",
|
||||
"abnormalDesc": "该防伪码状态异常,请谨慎核验。"
|
||||
"abnormalDesc": "该防伪码状态异常,请谨慎核验。",
|
||||
"previewExpiredTitle": "预览链接已过期",
|
||||
"previewExpiredDesc": "预览地址具有时效性,请回到管理后台重新打开预览页面。"
|
||||
},
|
||||
"preview": {
|
||||
"title": "预览模式",
|
||||
"note": "仅供内部预览,不激活、不计入查询次数",
|
||||
"inactive": "未激活",
|
||||
"active": "已激活"
|
||||
},
|
||||
"viewer": {
|
||||
"zoomIn": "放大",
|
||||
|
||||
@@ -5,6 +5,8 @@ export default createRouter({
|
||||
routes: [
|
||||
{ path: '/', component: () => import('@/views/Home.vue') },
|
||||
{ path: '/trace/:code', component: () => import('@/views/Trace.vue') },
|
||||
// 后台预览模式:复用 Trace.vue,凭 ?token= 时间令牌访问,不激活/不计数
|
||||
{ path: '/trace/preview/:code', component: () => import('@/views/Trace.vue') },
|
||||
{ path: '/:pathMatch(.*)*', redirect: '/' },
|
||||
],
|
||||
});
|
||||
|
||||
@@ -43,6 +43,30 @@
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 预览模式条:后台预览专用,可切换未激活/已激活展示形态 -->
|
||||
<div v-if="isPreview" class="preview-bar">
|
||||
<span class="preview-badge">{{ t('preview.title') }}</span>
|
||||
<span class="preview-note">{{ t('preview.note') }}</span>
|
||||
<div class="preview-toggle">
|
||||
<button
|
||||
type="button"
|
||||
class="preview-toggle-btn"
|
||||
:class="{ active: previewState === 'inactive' }"
|
||||
@click="setPreviewState('inactive')"
|
||||
>
|
||||
{{ t('preview.inactive') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="preview-toggle-btn"
|
||||
:class="{ active: previewState === 'active' }"
|
||||
@click="setPreviewState('active')"
|
||||
>
|
||||
{{ t('preview.active') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 加载 -->
|
||||
<div v-if="loading" class="state">
|
||||
<div class="spinner" />
|
||||
@@ -392,7 +416,7 @@ import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchTrace, fetchAppInfo } from '@/api';
|
||||
import { fetchTrace, fetchTracePreview, fetchAppInfo } from '@/api';
|
||||
import { setLocale, SUPPORTED_LOCALES } from '@/locales';
|
||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
|
||||
@@ -420,6 +444,17 @@ const antiModalOpen = ref(false);
|
||||
const certIndex = ref(0);
|
||||
const currentCert = computed(() => data.value?.certificates?.[certIndex.value] || null);
|
||||
|
||||
// 后台预览模式:/trace/preview/:code?token=xxx,零副作用(不激活/不计数),可切换未激活/已激活形态
|
||||
const isPreview = computed(() => route.path.startsWith('/trace/preview/'));
|
||||
const previewState = ref<'inactive' | 'active'>('inactive');
|
||||
const previewExpired = computed(() => data.value?.status === 'PREVIEW_EXPIRED');
|
||||
function setPreviewState(state: 'inactive' | 'active') {
|
||||
if (previewState.value === state) return;
|
||||
previewState.value = state;
|
||||
const code = route.params.code;
|
||||
if (code) load(String(code));
|
||||
}
|
||||
|
||||
// 节点图片默认收缩,避免页面过长;点击展开
|
||||
const expanded = ref<Set<number>>(new Set());
|
||||
function toggleNode(i: number) {
|
||||
@@ -432,6 +467,7 @@ const stateKey = computed(() => {
|
||||
const s = data.value?.status;
|
||||
if (s === 'DISABLED') return 'disabled';
|
||||
if (s === 'ABNORMAL') return 'abnormal';
|
||||
if (s === 'PREVIEW_EXPIRED') return 'previewExpired';
|
||||
return 'invalid';
|
||||
});
|
||||
|
||||
@@ -703,7 +739,9 @@ async function load(code: string) {
|
||||
data.value = null;
|
||||
expanded.value = new Set();
|
||||
try {
|
||||
data.value = await fetchTrace(code);
|
||||
data.value = isPreview.value
|
||||
? await fetchTracePreview(code, String(route.query.token || ''), previewState.value)
|
||||
: await fetchTrace(code);
|
||||
} catch {
|
||||
data.value = { status: 'INVALID' };
|
||||
} finally {
|
||||
@@ -867,6 +905,56 @@ watch(
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.preview-bar {
|
||||
position: sticky;
|
||||
top: 48px;
|
||||
z-index: 4;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
padding: 8px 14px;
|
||||
background: #fff7e6;
|
||||
color: #ad6800;
|
||||
border-bottom: 1px solid #ffe7ba;
|
||||
font-size: 13px;
|
||||
}
|
||||
:root[data-theme='dark'] .preview-bar,
|
||||
.dark .preview-bar {
|
||||
background: rgba(173, 104, 0, 0.18);
|
||||
color: #ffd591;
|
||||
border-bottom-color: rgba(255, 213, 145, 0.25);
|
||||
}
|
||||
.preview-badge {
|
||||
font-weight: 700;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.preview-note {
|
||||
flex: 1;
|
||||
min-width: 120px;
|
||||
opacity: 0.85;
|
||||
}
|
||||
.preview-toggle {
|
||||
display: inline-flex;
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.preview-toggle-btn {
|
||||
padding: 4px 12px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.preview-toggle-btn.active {
|
||||
background: #ad6800;
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
}
|
||||
.state {
|
||||
padding: 80px 32px;
|
||||
text-align: center;
|
||||
|
||||
Reference in New Issue
Block a user