fix: 精选封面刷新预热与铺满,修指示点抖动,首页 CTA 改为开始寄件黑底。
All checks were successful
Build and Deploy Front / deploy (push) Successful in 10m38s
All checks were successful
Build and Deploy Front / deploy (push) Successful in 10m38s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
40fe09b62f
commit
cd27fc3029
@ -178,11 +178,16 @@
|
||||
fetchRoutesCatalog,
|
||||
formatRouteTimeliness,
|
||||
inferRouteDestIds,
|
||||
peekRoutesCatalog,
|
||||
pickFeaturedRoutes,
|
||||
routeCoverageLabel,
|
||||
type RouteItem,
|
||||
} from './lib/portal-catalog';
|
||||
import { resolveRouteCoverUrl, routeHasRealCover } from './lib/route-cover';
|
||||
import {
|
||||
preloadFeaturedRouteCovers,
|
||||
resolveRouteCoverUrl,
|
||||
routeHasRealCover,
|
||||
} from './lib/route-cover';
|
||||
|
||||
const AUTOPLAY_MS = 4500;
|
||||
|
||||
@ -234,7 +239,28 @@
|
||||
|
||||
function cardBgStyle(item: RouteItem) {
|
||||
const url = resolveRouteCoverUrl(item);
|
||||
return url ? { backgroundImage: `url(${url})` } : undefined;
|
||||
// 3D rotateY 下 background-size:cover 比 img+object-fit 更稳,不会露底
|
||||
return url
|
||||
? {
|
||||
backgroundImage: `url("${url}")`,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'center',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
backgroundOrigin: 'border-box',
|
||||
backgroundClip: 'border-box',
|
||||
}
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function applyFeatured(items: RouteItem[], opts?: { keepIndex?: boolean }) {
|
||||
featured.value = items;
|
||||
const len = items.length;
|
||||
if (!opts?.keepIndex) {
|
||||
activeIndex.value = len > 0 ? Math.floor((len - 1) / 2) : 0;
|
||||
} else if (activeIndex.value >= len) {
|
||||
activeIndex.value = Math.max(0, len - 1);
|
||||
}
|
||||
preloadFeaturedRouteCovers(items, activeIndex.value);
|
||||
}
|
||||
|
||||
/** 环形最短偏移:末张右侧接首张,首张左侧接末张 */
|
||||
@ -423,19 +449,27 @@
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
activeIndex.value = 0;
|
||||
stopAutoplay();
|
||||
const warm = peekRoutesCatalog(lang.value);
|
||||
if (warm?.items?.length) {
|
||||
applyFeatured(pickFeaturedRoutes(warm, 10));
|
||||
loading.value = false;
|
||||
await nextTick();
|
||||
measureStage();
|
||||
startAutoplay();
|
||||
} else {
|
||||
loading.value = true;
|
||||
activeIndex.value = 0;
|
||||
featured.value = [];
|
||||
}
|
||||
try {
|
||||
const catalog = await fetchRoutesCatalog(lang.value);
|
||||
featured.value = pickFeaturedRoutes(catalog, 10);
|
||||
applyFeatured(pickFeaturedRoutes(catalog, 10), { keepIndex: !loading.value });
|
||||
} catch {
|
||||
featured.value = [];
|
||||
if (!featured.value.length) featured.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
await nextTick();
|
||||
const len = featured.value.length;
|
||||
activeIndex.value = len > 0 ? Math.floor((len - 1) / 2) : 0;
|
||||
measureStage();
|
||||
startAutoplay();
|
||||
}
|
||||
@ -485,4 +519,9 @@
|
||||
await nextTick();
|
||||
measureStage();
|
||||
});
|
||||
|
||||
watch(activeIndex, (idx) => {
|
||||
if (!featured.value.length) return;
|
||||
preloadFeaturedRouteCovers(featured.value, idx);
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -222,12 +222,57 @@ export function normalizeRoutesCatalog(raw: unknown, lang: SiteLang): RoutesCata
|
||||
|
||||
let routesCatalogCache: { lang: SiteLang; data: RoutesCatalog; at: number } | null = null;
|
||||
const ROUTES_CATALOG_TTL_MS = 5 * 60 * 1000;
|
||||
/** sessionStorage 可跨刷新复用;超长仅防永久脏数据,仍会后台 revalidate */
|
||||
const ROUTES_CATALOG_SESSION_MAX_MS = 24 * 60 * 60 * 1000;
|
||||
const ROUTES_CATALOG_SESSION_PREFIX = 'oms-portal-routes-catalog:';
|
||||
|
||||
export async function fetchRoutesCatalog(lang: SiteLang): Promise<RoutesCatalog> {
|
||||
const cached = routesCatalogCache;
|
||||
if (cached && cached.lang === lang && Date.now() - cached.at < ROUTES_CATALOG_TTL_MS) {
|
||||
return cached.data;
|
||||
type RoutesCatalogStore = { lang: SiteLang; data: RoutesCatalog; at: number };
|
||||
|
||||
let routesCatalogRevalidate: Promise<RoutesCatalog> | null = null;
|
||||
|
||||
function routesCatalogSessionKey(lang: SiteLang) {
|
||||
return ROUTES_CATALOG_SESSION_PREFIX + lang;
|
||||
}
|
||||
|
||||
function writeRoutesCatalogStore(store: RoutesCatalogStore) {
|
||||
routesCatalogCache = store;
|
||||
if (typeof sessionStorage === 'undefined') return;
|
||||
try {
|
||||
sessionStorage.setItem(routesCatalogSessionKey(store.lang), JSON.stringify(store));
|
||||
} catch {
|
||||
/* quota / private mode */
|
||||
}
|
||||
}
|
||||
|
||||
function readRoutesCatalogSession(lang: SiteLang): RoutesCatalogStore | null {
|
||||
if (typeof sessionStorage === 'undefined') return null;
|
||||
try {
|
||||
const raw = sessionStorage.getItem(routesCatalogSessionKey(lang));
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as RoutesCatalogStore;
|
||||
if (!parsed || parsed.lang !== lang || !parsed.data?.items || !Array.isArray(parsed.data.items)) {
|
||||
return null;
|
||||
}
|
||||
if (typeof parsed.at !== 'number' || Date.now() - parsed.at > ROUTES_CATALOG_SESSION_MAX_MS) {
|
||||
return null;
|
||||
}
|
||||
return parsed;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 同步读内存或 sessionStorage(刷新首帧预热封面用,不发网络) */
|
||||
export function peekRoutesCatalog(lang: SiteLang): RoutesCatalog | null {
|
||||
const mem = routesCatalogCache;
|
||||
if (mem && mem.lang === lang) return mem.data;
|
||||
const session = readRoutesCatalogSession(lang);
|
||||
if (!session) return null;
|
||||
routesCatalogCache = session;
|
||||
return session.data;
|
||||
}
|
||||
|
||||
async function fetchRoutesCatalogNetwork(lang: SiteLang): Promise<RoutesCatalog> {
|
||||
const res = await fetch(resolveAdminApiPath('/channel/sales-product/portal/catalog'), {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
@ -235,10 +280,38 @@ export async function fetchRoutesCatalog(lang: SiteLang): Promise<RoutesCatalog>
|
||||
});
|
||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||
const data = normalizeRoutesCatalog(await res.json(), lang);
|
||||
routesCatalogCache = { lang, data, at: Date.now() };
|
||||
writeRoutesCatalogStore({ lang, data, at: Date.now() });
|
||||
return data;
|
||||
}
|
||||
|
||||
function revalidateRoutesCatalog(lang: SiteLang): Promise<RoutesCatalog> {
|
||||
if (routesCatalogRevalidate) return routesCatalogRevalidate;
|
||||
routesCatalogRevalidate = fetchRoutesCatalogNetwork(lang).finally(() => {
|
||||
routesCatalogRevalidate = null;
|
||||
});
|
||||
return routesCatalogRevalidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取线路目录:内存 TTL → sessionStorage 立刻返回并后台刷新 → 网络。
|
||||
* 刷新页时 session 命中可马上拿到 coverImageUrl,封面可提前开下。
|
||||
*/
|
||||
export async function fetchRoutesCatalog(lang: SiteLang): Promise<RoutesCatalog> {
|
||||
const cached = routesCatalogCache;
|
||||
if (cached && cached.lang === lang && Date.now() - cached.at < ROUTES_CATALOG_TTL_MS) {
|
||||
return cached.data;
|
||||
}
|
||||
|
||||
const session = readRoutesCatalogSession(lang);
|
||||
if (session) {
|
||||
routesCatalogCache = session;
|
||||
void revalidateRoutesCatalog(lang);
|
||||
return session.data;
|
||||
}
|
||||
|
||||
return fetchRoutesCatalogNetwork(lang);
|
||||
}
|
||||
|
||||
/** 欢迎区精选:按目的地区尽量分散,优先有时效的线路 */
|
||||
export function pickFeaturedRoutes(catalog: RoutesCatalog | null, limit = 6): RouteItem[] {
|
||||
const items = catalog?.items || [];
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import type { RouteItem } from './portal-catalog';
|
||||
|
||||
const warmedCoverUrls = new Set<string>();
|
||||
|
||||
export function routeHasRealCover(item: RouteItem): boolean {
|
||||
return Boolean(item.coverImageUrl?.trim());
|
||||
}
|
||||
@ -8,3 +10,53 @@ export function routeHasRealCover(item: RouteItem): boolean {
|
||||
export function resolveRouteCoverUrl(item: RouteItem): string {
|
||||
return item.coverImageUrl?.trim() || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 把精选封面提前推进浏览器缓存。
|
||||
* highPriorityUrl 额外挂 link rel=preload,优先中心卡。
|
||||
*/
|
||||
export function preloadRouteCovers(
|
||||
urls: string[],
|
||||
opts?: { highPriorityUrl?: string },
|
||||
): void {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
const high = opts?.highPriorityUrl?.trim();
|
||||
if (!high || typeof document === 'undefined') return;
|
||||
const marker = 'data-oms-route-cover-preload';
|
||||
const existed = Array.from(document.head.querySelectorAll(`link[${marker}="1"]`)).some(
|
||||
(el) => (el as HTMLLinkElement).href === new URL(high, window.location.href).href,
|
||||
);
|
||||
if (existed) return;
|
||||
try {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'preload';
|
||||
link.as = 'image';
|
||||
link.href = high;
|
||||
link.setAttribute(marker, '1');
|
||||
document.head.appendChild(link);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
export function preloadFeaturedRouteCovers(items: RouteItem[], activeIndex = 0): void {
|
||||
const urls = items.map(resolveRouteCoverUrl).filter(Boolean);
|
||||
if (!urls.length) return;
|
||||
const high =
|
||||
resolveRouteCoverUrl(items[Math.max(0, Math.min(activeIndex, items.length - 1))] || items[0]) ||
|
||||
urls[0];
|
||||
preloadRouteCovers(urls, { highPriorityUrl: high });
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ export const WELCOME_COPY = {
|
||||
newChat: 'New chat',
|
||||
newChatHint: 'New chat started — ask here',
|
||||
emptyHistory: 'No conversations yet',
|
||||
heroCta: 'Register to see rates',
|
||||
heroCta: 'Start shipping',
|
||||
composeLead: 'Where are you shipping? Pick a destination, or ask below.',
|
||||
destAria: 'Pick a destination',
|
||||
intentAria: 'Shipping and benefits shortcuts',
|
||||
@ -37,7 +37,7 @@ export const WELCOME_COPY = {
|
||||
newChat: '新会话',
|
||||
newChatHint: '已开启新会话,在这里提问',
|
||||
emptyHistory: '暂无会话',
|
||||
heroCta: '去注册看价',
|
||||
heroCta: '开始寄件',
|
||||
composeLead: '发到哪?点目的地看线路,或直接提问。',
|
||||
destAria: '选择目的地',
|
||||
intentAria: '履约与权益入口',
|
||||
|
||||
@ -2536,7 +2536,7 @@ body.command-home #navbar .site-nav-avatar:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Perplexity / ChatGPT 式:实心 CTA */
|
||||
/* 实心 CTA:黑底白字 */
|
||||
.ai-ask__cta--solid {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@ -2544,14 +2544,14 @@ body.command-home #navbar .site-nav-avatar:hover {
|
||||
min-height: 32px;
|
||||
padding: 0 14px;
|
||||
border-radius: 999px;
|
||||
background: var(--ai-accent, #e96a26);
|
||||
background: #121820;
|
||||
color: #fff;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 650;
|
||||
letter-spacing: 0.01em;
|
||||
text-decoration: none;
|
||||
opacity: 1;
|
||||
box-shadow: 0 4px 12px color-mix(in srgb, var(--ai-accent, #e96a26) 28%, transparent);
|
||||
box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
|
||||
transition:
|
||||
background 0.16s var(--ai-ease),
|
||||
box-shadow 0.16s var(--ai-ease),
|
||||
@ -2560,10 +2560,10 @@ body.command-home #navbar .site-nav-avatar:hover {
|
||||
|
||||
.ai-ask__cta--solid:hover,
|
||||
.ai-ask__cta--solid:focus-visible {
|
||||
background: var(--ai-accent-hover, #d45e1f);
|
||||
background: #000;
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
box-shadow: 0 6px 16px color-mix(in srgb, var(--ai-accent, #e96a26) 34%, transparent);
|
||||
box-shadow: 0 6px 16px rgba(15, 23, 42, 0.28);
|
||||
}
|
||||
|
||||
.ai-ask__cta--solid:active {
|
||||
@ -2654,6 +2654,7 @@ body.command-home #ai-advisor-shell:not(:has(.ai-stage-tools)) .ai-composer-dock
|
||||
margin: clamp(14px, 2.2vh, 24px) auto 0;
|
||||
padding: 0 0 4px;
|
||||
box-sizing: border-box;
|
||||
isolation: isolate;
|
||||
}
|
||||
|
||||
.ai-home-bottom > .ai-featured-routes,
|
||||
@ -2664,8 +2665,10 @@ body.command-home #ai-advisor-shell:not(:has(.ai-stage-tools)) .ai-composer-dock
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
/* 履约/权益条:一排全展示,不做跑马灯 */
|
||||
/* 履约/权益条:一排全展示,不做跑马灯;独立合成层,不跟封面流一起抖 */
|
||||
.ai-intent-section {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-shrink: 0;
|
||||
@ -2673,9 +2676,13 @@ body.command-home #ai-advisor-shell:not(:has(.ai-stage-tools)) .ai-composer-dock
|
||||
margin-top: 0;
|
||||
padding: 0 var(--ai-home-rail-pad, 16px) 2px;
|
||||
overflow: visible;
|
||||
isolation: isolate;
|
||||
transform: translateZ(0);
|
||||
contain: layout paint style;
|
||||
}
|
||||
|
||||
/* 精选线路:竖版封面流(加宽、高度克制 + 大幅后仰 + 中心正对) */
|
||||
/* 精选线路:竖版封面流(加宽、高度克制 + 大幅后仰 + 中心正对)
|
||||
overflow 必须裁切:3D translateZ/rotateY 否则会撑祖先 scrollHeight,下方意图条跟着抖 */
|
||||
.ai-featured-routes {
|
||||
--ai-featured-card-w: min(17.5rem, 42vw);
|
||||
--ai-featured-card-h: min(17rem, 34vh);
|
||||
@ -2683,11 +2690,16 @@ body.command-home #ai-advisor-shell:not(:has(.ai-stage-tools)) .ai-composer-dock
|
||||
--ai-featured-stage-h: calc(var(--ai-featured-card-h) + 2.6rem);
|
||||
--ai-featured-perspective: 980px;
|
||||
--ai-featured-radius: 18px;
|
||||
position: relative;
|
||||
z-index: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 0;
|
||||
margin-top: 0;
|
||||
padding: 4px 0 0;
|
||||
overflow: visible;
|
||||
overflow: hidden;
|
||||
isolation: isolate;
|
||||
transform: translateZ(0);
|
||||
contain: layout style;
|
||||
}
|
||||
|
||||
.ai-featured-routes__head {
|
||||
@ -2789,7 +2801,8 @@ body.command-home #ai-advisor-shell:not(:has(.ai-stage-tools)) .ai-composer-dock
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 0.2rem var(--ai-featured-head-pad) 0.1rem;
|
||||
overflow: visible;
|
||||
overflow: hidden;
|
||||
isolation: isolate;
|
||||
}
|
||||
|
||||
.ai-featured-routes__stage {
|
||||
@ -2801,6 +2814,7 @@ body.command-home #ai-advisor-shell:not(:has(.ai-stage-tools)) .ai-composer-dock
|
||||
list-style: none;
|
||||
outline: none;
|
||||
box-sizing: border-box;
|
||||
/* 舞台本身勿 overflow/transform:会把 preserve-3d 打平;裁切交给 __rail */
|
||||
perspective: var(--ai-featured-perspective);
|
||||
perspective-origin: 50% 48%;
|
||||
transform-style: preserve-3d;
|
||||
@ -2830,7 +2844,7 @@ body.command-home #ai-advisor-shell:not(:has(.ai-stage-tools)) .ai-composer-dock
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
transform-style: preserve-3d;
|
||||
will-change: transform, opacity;
|
||||
/* 勿常驻 will-change:会把整排永久提到合成层,切换时连带下方意图条重绘抖动 */
|
||||
transition:
|
||||
transform 0.66s cubic-bezier(0.32, 0.72, 0, 1),
|
||||
opacity 0.45s ease;
|
||||
@ -2857,6 +2871,10 @@ body.command-home #ai-advisor-shell:not(:has(.ai-stage-tools)) .ai-composer-dock
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-origin: border-box;
|
||||
background-clip: border-box;
|
||||
/* 勿用近白描边,否则像图没铺到边 */
|
||||
border-color: rgba(255, 255, 255, 0.42);
|
||||
}
|
||||
|
||||
.ai-featured-routes__item.is-active .ai-featured-routes__card::after {
|
||||
@ -2949,6 +2967,8 @@ body.command-home .ai-composer-slot--welcome .ai-composer {
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-origin: border-box;
|
||||
background-clip: border-box;
|
||||
border-color: rgba(255, 255, 255, 0.28);
|
||||
color: #fff;
|
||||
}
|
||||
@ -3211,7 +3231,8 @@ body.command-home .ai-composer-slot--welcome .ai-composer {
|
||||
color: color-mix(in srgb, var(--ai-text-3, #6a7380) 82%, #fff);
|
||||
}
|
||||
|
||||
/* 参考图:竖刻度指示条 */
|
||||
/* 参考图:竖刻度指示条
|
||||
高度必须钉死:active 点 height 10↔16 过渡时若容器跟着塌,整段 featured 变矮,意图条会上下抖 */
|
||||
.ai-featured-routes__dots {
|
||||
position: relative;
|
||||
z-index: 9;
|
||||
@ -3219,8 +3240,14 @@ body.command-home .ai-composer-slot--welcome .ai-composer {
|
||||
align-items: flex-end;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
height: 22px;
|
||||
min-height: 22px;
|
||||
margin: 0.05rem 0 0;
|
||||
padding: 0.2rem 0 0.1rem;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ai-featured-routes__dot {
|
||||
@ -3232,15 +3259,17 @@ body.command-home .ai-composer-slot--welcome .ai-composer {
|
||||
border-radius: 1px;
|
||||
background: color-mix(in srgb, var(--ai-text-3, #6a7380) 28%, transparent);
|
||||
cursor: pointer;
|
||||
transform-origin: bottom center;
|
||||
transition:
|
||||
height 0.28s cubic-bezier(0.32, 0.72, 0, 1),
|
||||
transform 0.28s cubic-bezier(0.32, 0.72, 0, 1),
|
||||
background 0.22s ease,
|
||||
opacity 0.22s ease;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
.ai-featured-routes__dot.is-active {
|
||||
height: 16px;
|
||||
height: 10px;
|
||||
transform: scaleY(1.6);
|
||||
background: var(--ai-action);
|
||||
}
|
||||
|
||||
@ -5250,16 +5279,19 @@ body.command-home .ai-welcome-plane img {
|
||||
filter: none;
|
||||
}
|
||||
|
||||
/* 扇形封面流需要溢出可见;home-bottom / featured 勿 paint contain */
|
||||
/* 封面流已在 section/rail/stage 内 overflow:hidden;意图条独立 paint contain,避免跟着抖 */
|
||||
body.command-home .ai-intent-section {
|
||||
contain: layout paint;
|
||||
contain: layout paint style;
|
||||
}
|
||||
|
||||
body.command-home .ai-home-bottom,
|
||||
body.command-home .ai-featured-routes {
|
||||
body.command-home .ai-home-bottom {
|
||||
contain: layout;
|
||||
}
|
||||
|
||||
body.command-home .ai-featured-routes {
|
||||
contain: layout style;
|
||||
}
|
||||
|
||||
body.command-home .ai-history-sidebar {
|
||||
background: #f7f8fa;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user