refine: 官网 AI 首页输入台布局、精选封面与信任条,顶栏 Logo 圆角方标
All checks were successful
Build and Deploy Front / deploy (push) Successful in 11m49s
All checks were successful
Build and Deploy Front / deploy (push) Successful in 11m49s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
a8d71d821d
commit
c3c00eb764
@ -1408,7 +1408,7 @@ onUnmounted(() => {
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
/* 独立白底圆标:大图标 + 克制高级感(细描边 / 轻环境光) */
|
||||
/* 独立白底圆角方标 */
|
||||
.top-nav-logo {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
@ -1419,7 +1419,7 @@ onUnmounted(() => {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
margin: 0;
|
||||
border-radius: 50%;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
border: 1px solid rgba(15, 23, 42, 0.08);
|
||||
box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
|
||||
@ -1442,8 +1442,8 @@ onUnmounted(() => {
|
||||
}
|
||||
|
||||
img {
|
||||
height: 30px;
|
||||
width: 30px;
|
||||
height: 36px;
|
||||
width: 36px;
|
||||
box-sizing: border-box;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
<SiteRunway :text="heroTitle" />
|
||||
<h1 class="ai-welcome-title ai-welcome-title--sr">{{ heroTitle }}</h1>
|
||||
</div>
|
||||
<p class="ai-welcome-fullname">{{ brandCopy.navFullName }}</p>
|
||||
<div class="ai-welcome__stack">
|
||||
<div class="ai-welcome__command">
|
||||
<div class="ai-ask">
|
||||
@ -66,11 +65,25 @@
|
||||
</button>
|
||||
</div>
|
||||
<a
|
||||
class="ai-ask__cta ai-ask__cta--solid"
|
||||
class="ai-ask__cta ai-ask__cta--solid ai-welcome-cta"
|
||||
:href="loginUrl"
|
||||
@pointerenter="$emit('warm-login')"
|
||||
@focus="$emit('warm-login')"
|
||||
>{{ copy.heroCta }}</a>
|
||||
>
|
||||
<span>{{ copy.heroCta }}</span>
|
||||
<svg
|
||||
class="ai-welcome-cta__arrow"
|
||||
viewBox="0 0 16 16"
|
||||
width="14"
|
||||
height="14"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M2.5 8a.75.75 0 0 1 .75-.75h7.69L8.22 4.53a.75.75 0 0 1 1.06-1.06l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 1 1-1.06-1.06l2.72-2.72H3.25A.75.75 0 0 1 2.5 8"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
</template>
|
||||
</EdiComposer>
|
||||
@ -167,24 +180,25 @@
|
||||
@submit="$emit('submit', draft)"
|
||||
/>
|
||||
</div>
|
||||
<div class="ai-trust-bar">
|
||||
<SitePartnerMarquee
|
||||
:is-zh="isZh"
|
||||
:tag="copy.partnerTag"
|
||||
:aria="copy.partnerAria"
|
||||
/>
|
||||
<a class="ai-trust-icp" href="https://beian.miit.gov.cn" target="_blank" rel="noopener">
|
||||
<svg class="ai-trust-glyph" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M8 0c-.69 0-1.843.265-2.928.56-1.111.3-2.229.655-2.887.87a1.54 1.54 0 0 0-1.044 1.262c-.596 4.477.787 7.795 2.465 9.99a11.8 11.8 0 0 0 2.517 2.453c.386.273.744.482 1.048.625.28.132.581.24.829.24s.548-.108.829-.24c.304-.143.662-.352 1.048-.625a11.8 11.8 0 0 0 2.517-2.453c1.678-2.195 3.061-5.513 2.465-9.99a1.54 1.54 0 0 0-1.044-1.262 62.4 62.4 0 0 0-2.887-.87C9.843.266 8.69 0 8 0m2.146 5.146a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 1 1 .708-.708L7.5 7.793z"
|
||||
/>
|
||||
</svg>
|
||||
<span class="ai-trust-label">{{ brandCopy.icp }}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 贴视口底:不进 flex 内容流,避免随 VV/矮屏一起被挤缩 -->
|
||||
<div class="ai-trust-bar">
|
||||
<SitePartnerMarquee
|
||||
:is-zh="isZh"
|
||||
:tag="brandCopy.navFullName"
|
||||
:aria="copy.partnerAria"
|
||||
/>
|
||||
<a class="ai-trust-icp" href="https://beian.miit.gov.cn" target="_blank" rel="noopener">
|
||||
<svg class="ai-trust-glyph" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M8 0c-.69 0-1.843.265-2.928.56-1.111.3-2.229.655-2.887.87a1.54 1.54 0 0 0-1.044 1.262c-.596 4.477.787 7.795 2.465 9.99a11.8 11.8 0 0 0 2.517 2.453c.386.273.744.482 1.048.625.28.132.581.24.829.24s.548-.108.829-.24c.304-.143.662-.352 1.048-.625a11.8 11.8 0 0 0 2.517-2.453c1.678-2.195 3.061-5.513 2.465-9.99a1.54 1.54 0 0 0-1.044-1.262 62.4 62.4 0 0 0-2.887-.87C9.843.266 8.69 0 8 0m2.146 5.146a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 1 1 .708-.708L7.5 7.793z"
|
||||
/>
|
||||
</svg>
|
||||
<span class="ai-trust-label">{{ brandCopy.icp }}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<aside
|
||||
class="ai-history-sidebar ai-history-sidebar--chat"
|
||||
|
||||
@ -88,13 +88,21 @@
|
||||
:tabindex="index === activeIndex ? 0 : -1"
|
||||
:aria-current="index === activeIndex ? 'true' : undefined"
|
||||
:aria-label="cardAria(item)"
|
||||
:style="cardBgStyle(item)"
|
||||
@click="onCard(item, index)"
|
||||
>
|
||||
<!-- 封面独立图层:可做 Ken Burns,且不跟文字一起被 3D 糊边 -->
|
||||
<span
|
||||
v-if="routeHasRealCover(item)"
|
||||
class="ai-featured-routes__media"
|
||||
:class="{ 'is-ready': isCoverReady(item) }"
|
||||
aria-hidden="true"
|
||||
:style="cardBgStyle(item)"
|
||||
/>
|
||||
<span class="ai-featured-routes__card-top">
|
||||
<span
|
||||
v-if="!routeHasRealCover(item)"
|
||||
v-if="routeCoverageLabel(item, lang)"
|
||||
class="ai-featured-routes__dest"
|
||||
:class="{ 'is-on-cover': routeHasRealCover(item) }"
|
||||
>{{ routeCoverageLabel(item, lang) }}</span>
|
||||
<span
|
||||
v-else
|
||||
@ -140,6 +148,11 @@
|
||||
>
|
||||
{{ item.productDescription }}
|
||||
</p>
|
||||
<span
|
||||
v-if="index === activeIndex"
|
||||
class="ai-featured-routes__ask-hint"
|
||||
aria-hidden="true"
|
||||
>{{ copy.featuredRoutesAsk }}</span>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
@ -184,9 +197,11 @@
|
||||
type RouteItem,
|
||||
} from './lib/portal-catalog';
|
||||
import {
|
||||
isRouteCoverReady,
|
||||
preloadFeaturedRouteCovers,
|
||||
resolveRouteCoverUrl,
|
||||
routeHasRealCover,
|
||||
subscribeRouteCoverReady,
|
||||
} from './lib/route-cover';
|
||||
|
||||
const AUTOPLAY_MS = 4500;
|
||||
@ -213,6 +228,9 @@
|
||||
const paused = ref(false);
|
||||
const stageWidth = ref(1100);
|
||||
const cardWidth = ref(280);
|
||||
/** 驱动封面 is-ready 重绘;实际就绪态在 route-cover 模块里 */
|
||||
const coverReadyTick = ref(0);
|
||||
const coverReadyUnsubs: Array<() => void> = [];
|
||||
|
||||
const visible = computed(() => loading.value || featured.value.length > 0);
|
||||
const canPrev = computed(() => featured.value.length > 1);
|
||||
@ -239,19 +257,33 @@
|
||||
|
||||
function cardBgStyle(item: RouteItem) {
|
||||
const url = resolveRouteCoverUrl(item);
|
||||
// 3D rotateY 下 background-size:cover 比 img+object-fit 更稳,不会露底
|
||||
// 封面走独立 media 层;cover + overflow 裁切,比 img 在 rotateY 下更稳
|
||||
return url
|
||||
? {
|
||||
backgroundImage: `url("${url}")`,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'center',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
backgroundOrigin: 'border-box',
|
||||
backgroundClip: 'border-box',
|
||||
}
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function isCoverReady(item: RouteItem) {
|
||||
void coverReadyTick.value;
|
||||
const url = resolveRouteCoverUrl(item);
|
||||
return Boolean(url && isRouteCoverReady(url));
|
||||
}
|
||||
|
||||
function bindCoverReady(items: RouteItem[]) {
|
||||
while (coverReadyUnsubs.length) coverReadyUnsubs.pop()?.();
|
||||
for (const item of items) {
|
||||
const url = resolveRouteCoverUrl(item);
|
||||
if (!url) continue;
|
||||
coverReadyUnsubs.push(
|
||||
subscribeRouteCoverReady(url, () => {
|
||||
coverReadyTick.value += 1;
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function applyFeatured(items: RouteItem[], opts?: { keepIndex?: boolean }) {
|
||||
featured.value = items;
|
||||
const len = items.length;
|
||||
@ -261,6 +293,7 @@
|
||||
activeIndex.value = Math.max(0, len - 1);
|
||||
}
|
||||
preloadFeaturedRouteCovers(items, activeIndex.value);
|
||||
bindCoverReady(items);
|
||||
}
|
||||
|
||||
/** 环形最短偏移:末张右侧接首张,首张左侧接末张 */
|
||||
@ -497,6 +530,7 @@
|
||||
ro?.disconnect();
|
||||
ro = null;
|
||||
stopAutoplay();
|
||||
while (coverReadyUnsubs.length) coverReadyUnsubs.pop()?.();
|
||||
});
|
||||
|
||||
watch(stageRef, (el) => {
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 欢迎标题 canvas:保留逐字入场 / 斜切;整行蓝→橙均分斜切。
|
||||
* 欢迎标题 canvas:逐字入场 / 斜切;按文字实测宽度收缩,避免旁边按钮盖住字。
|
||||
*/
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { isPortalIrisActive } from '@/utils/page-transition-flag';
|
||||
@ -52,12 +52,12 @@
|
||||
let cachedChars: string[] = [];
|
||||
let cachedLabel = '';
|
||||
let brandColor = '#023e8a';
|
||||
let accentColor = '#e96a26';
|
||||
let accentColor = '#f56668';
|
||||
|
||||
const syncThemeColors = () => {
|
||||
const css = getComputedStyle(root);
|
||||
brandColor = css.getPropertyValue('--ai-brand').trim() || '#023e8a';
|
||||
accentColor = css.getPropertyValue('--ai-accent').trim() || '#e96a26';
|
||||
accentColor = css.getPropertyValue('--ai-accent').trim() || '#f56668';
|
||||
};
|
||||
|
||||
const easeOutCubic = (t: number) => 1 - (1 - t) ** 3;
|
||||
@ -65,25 +65,15 @@
|
||||
const enterTotalMs = (charCount: number) =>
|
||||
TEXT_AT + Math.max(0, charCount - 1) * CHAR_STAGGER + CHAR_DUR;
|
||||
|
||||
const paint = () => {
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
if (width < 40 || height < 24) return;
|
||||
const shearOf = () => (isNarrow ? -0.22 : -0.36);
|
||||
|
||||
const label = currentText.trim();
|
||||
if (!label) return;
|
||||
|
||||
const cx = width / 2;
|
||||
const cy = height / 2;
|
||||
// 约为原大标题一半
|
||||
const fontSize = Math.max(
|
||||
const fontSizeOf = (h: number) =>
|
||||
Math.max(
|
||||
isNarrow ? 13 : 14,
|
||||
Math.min(
|
||||
height * (isNarrow ? 0.5 : 0.48),
|
||||
width / Math.max(9, (label.length || 1) * (isNarrow ? 0.72 : 0.82)),
|
||||
),
|
||||
Math.min(h * (isNarrow ? 0.5 : 0.48), isNarrow ? 20 : 30),
|
||||
);
|
||||
// 原 shear -0.32 ≈ 更明显斜体;窄屏略收,避免长标题裁切
|
||||
const shear = isNarrow ? -0.22 : -0.36;
|
||||
|
||||
const measureLabel = (label: string, fontSize: number) => {
|
||||
const font = `600 ${fontSize}px "PingFang SC","Hiragino Sans GB","Microsoft YaHei","Segoe UI",sans-serif`;
|
||||
if (font !== cachedFont || label !== cachedLabel) {
|
||||
ctx.font = font;
|
||||
@ -94,12 +84,32 @@
|
||||
} else {
|
||||
ctx.font = font;
|
||||
}
|
||||
|
||||
const chars = cachedChars;
|
||||
const letterGap = fontSize * 0.14;
|
||||
const charWidths = cachedCharWidths;
|
||||
const totalW =
|
||||
charWidths.reduce((s, w) => s + w, 0) + letterGap * Math.max(0, chars.length - 1);
|
||||
cachedCharWidths.reduce((s, w) => s + w, 0) +
|
||||
letterGap * Math.max(0, cachedChars.length - 1);
|
||||
return { font, letterGap, totalW, chars: cachedChars, charWidths: cachedCharWidths };
|
||||
};
|
||||
|
||||
/** 文字宽 + 斜切/阴影边距,避免裁字 */
|
||||
const fitWidthOf = (totalW: number, fontSize: number) => {
|
||||
const shearExtra = Math.abs(shearOf()) * fontSize * 0.7;
|
||||
const padX = Math.max(12, fontSize * 0.32) + shearExtra;
|
||||
return Math.ceil(totalW + padX * 2);
|
||||
};
|
||||
|
||||
const paint = () => {
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
if (width < 40 || height < 24) return;
|
||||
|
||||
const label = currentText.trim();
|
||||
if (!label) return;
|
||||
|
||||
const cx = width / 2;
|
||||
const cy = height / 2;
|
||||
const fontSize = fontSizeOf(height);
|
||||
const shear = shearOf();
|
||||
const { font, letterGap, totalW, chars, charWidths } = measureLabel(label, fontSize);
|
||||
const whooshMax = Math.min(36, width * 0.05);
|
||||
const yGlyph = fontSize * 0.02;
|
||||
const shadowX = fontSize * 0.045;
|
||||
@ -113,7 +123,7 @@
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.font = font;
|
||||
|
||||
// 整行左上蓝 → 右下橙均分斜切
|
||||
// 整行左上蓝 → 右下珊瑚均分斜切
|
||||
const titleFill = ctx.createLinearGradient(
|
||||
-totalW / 2,
|
||||
-fontSize * 0.42,
|
||||
@ -190,8 +200,23 @@
|
||||
const rebuild = () => {
|
||||
syncThemeColors();
|
||||
const rect = root.getBoundingClientRect();
|
||||
const nextW = Math.max(1, Math.floor(rect.width));
|
||||
const nextH = Math.max(1, Math.floor(rect.height));
|
||||
const nextH = Math.max(
|
||||
1,
|
||||
Math.floor(rect.height || parseFloat(getComputedStyle(root).height) || 48),
|
||||
);
|
||||
const label = currentText.trim();
|
||||
const fontSize = fontSizeOf(nextH);
|
||||
cachedFont = '';
|
||||
const { totalW } = measureLabel(label || ' ', fontSize);
|
||||
const fitW = fitWidthOf(totalW, fontSize);
|
||||
const maxW = Math.floor(window.innerWidth * (isNarrow ? 0.58 : 0.7));
|
||||
const nextW = Math.max(80, Math.min(fitW, maxW));
|
||||
|
||||
// 按字宽写回,避免 CSS 固定大宽导致按钮盖字 / 离太远
|
||||
if (Math.abs((parseFloat(root.style.width) || 0) - nextW) > 0.5) {
|
||||
root.style.width = `${nextW}px`;
|
||||
}
|
||||
|
||||
const dpr = Math.min(window.devicePixelRatio || 1, dprCap);
|
||||
if (nextW === width && nextH === height) {
|
||||
paint();
|
||||
@ -199,7 +224,6 @@
|
||||
}
|
||||
width = nextW;
|
||||
height = nextH;
|
||||
cachedFont = '';
|
||||
canvas.width = Math.floor(width * dpr);
|
||||
canvas.height = Math.floor(height * dpr);
|
||||
canvas.style.width = `${width}px`;
|
||||
@ -224,7 +248,10 @@
|
||||
ro.observe(root);
|
||||
rebuild();
|
||||
|
||||
const kick = () => startEnter();
|
||||
const kick = () => {
|
||||
rebuild();
|
||||
startEnter();
|
||||
};
|
||||
if ('fonts' in document) {
|
||||
void document.fonts.ready.then(kick);
|
||||
} else {
|
||||
@ -257,7 +284,9 @@
|
||||
.ai-runway {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
width: min(760px, 96%);
|
||||
/* 宽度由脚本按文字实测写入;这里只定高度兜底 */
|
||||
width: auto;
|
||||
max-width: 100%;
|
||||
height: clamp(44px, 5.5vw, 64px);
|
||||
margin: 0 auto;
|
||||
pointer-events: none;
|
||||
@ -271,14 +300,12 @@
|
||||
|
||||
@media (max-height: 900px) {
|
||||
.ai-runway {
|
||||
width: min(480px, 90%);
|
||||
height: 42px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.ai-runway {
|
||||
width: 100%;
|
||||
height: 46px;
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,7 +312,7 @@ export async function fetchRoutesCatalog(lang: SiteLang): Promise<RoutesCatalog>
|
||||
return fetchRoutesCatalogNetwork(lang);
|
||||
}
|
||||
|
||||
/** 欢迎区精选:按目的地区尽量分散,优先有时效的线路 */
|
||||
/** 欢迎区精选:封面优先 + 目的地分散;封面不足时再补无封面,避免空段 */
|
||||
export function pickFeaturedRoutes(catalog: RoutesCatalog | null, limit = 6): RouteItem[] {
|
||||
const items = catalog?.items || [];
|
||||
if (!items.length) return [];
|
||||
@ -326,40 +326,48 @@ export function pickFeaturedRoutes(catalog: RoutesCatalog | null, limit = 6): Ro
|
||||
if (formatRouteTimeliness(item)) s += 3;
|
||||
if (item.tradeTerms === 'DDP' || item.tradeTerms === 'DDU') s += 1;
|
||||
if (item.productDescription) s += 1;
|
||||
if (item.coverImageUrl) s += 2;
|
||||
if (item.coverImageUrl?.trim()) s += 5;
|
||||
return s;
|
||||
};
|
||||
|
||||
const byDest = new Map<string, RouteItem[]>();
|
||||
for (const item of items) {
|
||||
const ids = inferRouteDestIds(item);
|
||||
const key = ids.find((id) => id !== 'other') || 'other';
|
||||
const list = byDest.get(key) || [];
|
||||
list.push(item);
|
||||
byDest.set(key, list);
|
||||
}
|
||||
for (const list of byDest.values()) {
|
||||
list.sort((a, b) => score(b) - score(a));
|
||||
}
|
||||
const hasCover = (item: RouteItem) => Boolean(item.coverImageUrl?.trim());
|
||||
|
||||
for (const destId of destOrder) {
|
||||
if (picked.length >= limit) break;
|
||||
const list = byDest.get(destId);
|
||||
const hit = list?.find((item) => !used.has(item.id));
|
||||
if (!hit) continue;
|
||||
used.add(hit.id);
|
||||
picked.push(hit);
|
||||
}
|
||||
const fillFromPool = (pool: RouteItem[]) => {
|
||||
if (!pool.length || picked.length >= limit) return;
|
||||
|
||||
if (picked.length < limit) {
|
||||
const rest = [...items].sort((a, b) => score(b) - score(a));
|
||||
const byDest = new Map<string, RouteItem[]>();
|
||||
for (const item of pool) {
|
||||
if (used.has(item.id)) continue;
|
||||
const ids = inferRouteDestIds(item);
|
||||
const key = ids.find((id) => id !== 'other') || 'other';
|
||||
const list = byDest.get(key) || [];
|
||||
list.push(item);
|
||||
byDest.set(key, list);
|
||||
}
|
||||
for (const list of byDest.values()) {
|
||||
list.sort((a, b) => score(b) - score(a));
|
||||
}
|
||||
|
||||
for (const destId of destOrder) {
|
||||
if (picked.length >= limit) break;
|
||||
const hit = byDest.get(destId)?.find((item) => !used.has(item.id));
|
||||
if (!hit) continue;
|
||||
used.add(hit.id);
|
||||
picked.push(hit);
|
||||
}
|
||||
|
||||
if (picked.length >= limit) return;
|
||||
const rest = [...pool].sort((a, b) => score(b) - score(a));
|
||||
for (const item of rest) {
|
||||
if (picked.length >= limit) break;
|
||||
if (used.has(item.id)) continue;
|
||||
used.add(item.id);
|
||||
picked.push(item);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fillFromPool(items.filter(hasCover));
|
||||
if (picked.length < limit) fillFromPool(items.filter((item) => !hasCover(item)));
|
||||
|
||||
return picked;
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import type { RouteItem } from './portal-catalog';
|
||||
|
||||
const warmedCoverUrls = new Set<string>();
|
||||
const readyCoverUrls = new Set<string>();
|
||||
const readyListeners = new Map<string, Set<() => void>>();
|
||||
|
||||
export function routeHasRealCover(item: RouteItem): boolean {
|
||||
return Boolean(item.coverImageUrl?.trim());
|
||||
@ -11,6 +13,69 @@ export function resolveRouteCoverUrl(item: RouteItem): string {
|
||||
return item.coverImageUrl?.trim() || '';
|
||||
}
|
||||
|
||||
export function isRouteCoverReady(url: string): boolean {
|
||||
const u = String(url || '').trim();
|
||||
return Boolean(u && readyCoverUrls.has(u));
|
||||
}
|
||||
|
||||
function notifyCoverReady(url: string) {
|
||||
const set = readyListeners.get(url);
|
||||
if (!set?.size) return;
|
||||
readyListeners.delete(url);
|
||||
for (const cb of set) {
|
||||
try {
|
||||
cb();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function markCoverReady(url: string) {
|
||||
const u = String(url || '').trim();
|
||||
if (!u || readyCoverUrls.has(u)) return;
|
||||
readyCoverUrls.add(u);
|
||||
notifyCoverReady(u);
|
||||
}
|
||||
|
||||
/** 订阅封面就绪(命中缓存则同步回调);返回取消函数 */
|
||||
export function subscribeRouteCoverReady(url: string, cb: () => void): () => void {
|
||||
const u = String(url || '').trim();
|
||||
if (!u) return () => {};
|
||||
if (readyCoverUrls.has(u)) {
|
||||
cb();
|
||||
return () => {};
|
||||
}
|
||||
let set = readyListeners.get(u);
|
||||
if (!set) {
|
||||
set = new Set();
|
||||
readyListeners.set(u, set);
|
||||
}
|
||||
set.add(cb);
|
||||
return () => {
|
||||
set?.delete(cb);
|
||||
if (set && set.size === 0) readyListeners.delete(u);
|
||||
};
|
||||
}
|
||||
|
||||
function warmOneCover(url: string) {
|
||||
const u = String(url || '').trim();
|
||||
if (!u || typeof window === 'undefined') return;
|
||||
if (readyCoverUrls.has(u)) return;
|
||||
|
||||
const finish = () => markCoverReady(u);
|
||||
try {
|
||||
const img = new Image();
|
||||
img.decoding = 'async';
|
||||
img.onload = finish;
|
||||
img.onerror = finish;
|
||||
img.src = u;
|
||||
if (img.complete && img.naturalWidth > 0) finish();
|
||||
} catch {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把精选封面提前推进浏览器缓存。
|
||||
* highPriorityUrl 额外挂 link rel=preload,优先中心卡。
|
||||
@ -22,15 +87,8 @@ export function preloadRouteCovers(
|
||||
if (typeof window === 'undefined') return;
|
||||
const list = [...new Set(urls.map((u) => String(u || '').trim()).filter(Boolean))];
|
||||
for (const url of list) {
|
||||
if (warmedCoverUrls.has(url)) continue;
|
||||
warmedCoverUrls.add(url);
|
||||
try {
|
||||
const img = new Image();
|
||||
img.decoding = 'async';
|
||||
img.src = url;
|
||||
} catch {
|
||||
warmedCoverUrls.delete(url);
|
||||
}
|
||||
if (!warmedCoverUrls.has(url)) warmedCoverUrls.add(url);
|
||||
warmOneCover(url);
|
||||
}
|
||||
|
||||
const high = opts?.highPriorityUrl?.trim();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user