feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -107,6 +107,7 @@ export type PortalState = {
|
||||
errorMessage: string;
|
||||
visitorId: string;
|
||||
enterTime: number;
|
||||
scrollDepth: number;
|
||||
touchType: string;
|
||||
isPlayingAudio: boolean;
|
||||
audioContext: any | null;
|
||||
@@ -145,6 +146,7 @@ export function createPortalState(): PortalState {
|
||||
errorMessage: '',
|
||||
visitorId: getOrCreateVisitorId(),
|
||||
enterTime: Date.now(),
|
||||
scrollDepth: 0,
|
||||
touchType: 'link',
|
||||
isPlayingAudio: false,
|
||||
audioContext: null,
|
||||
@@ -162,6 +164,7 @@ export async function loadCardPortal(
|
||||
state.errorMessage = '';
|
||||
state.touchType = source;
|
||||
state.enterTime = Date.now();
|
||||
state.scrollDepth = 0;
|
||||
|
||||
// 1. 优先尝试秒级读取本地缓存快照,实现首屏 0ms 呈现
|
||||
const cached: CachedPortalData | null = getCachedPortal(cardIdOrSlug);
|
||||
@@ -194,6 +197,7 @@ export async function loadCardPortal(
|
||||
touchType: state.touchType,
|
||||
stayDurationMs: 0,
|
||||
scrollDepth: 0,
|
||||
viewedBlocks: ['hero'],
|
||||
}).catch((_e: unknown) => {
|
||||
// 轨迹上报容错,不阻断主流程
|
||||
});
|
||||
@@ -217,7 +221,68 @@ export async function loadCardPortal(
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报访客停留时长与阅读深度
|
||||
* 记录门户滚动深度,只升不降
|
||||
*/
|
||||
export function updatePortalScrollDepth(
|
||||
state: PortalState,
|
||||
scrollTop: number,
|
||||
scrollHeight: number,
|
||||
windowHeight: number
|
||||
): number {
|
||||
if (scrollHeight <= 0) {
|
||||
return state.scrollDepth;
|
||||
}
|
||||
const maxScroll = Math.max(1, scrollHeight - windowHeight);
|
||||
const currentRatio = Math.min(1, Math.max(0, scrollTop / maxScroll));
|
||||
const depth = Math.round(currentRatio * 100);
|
||||
if (depth > state.scrollDepth) {
|
||||
state.scrollDepth = depth;
|
||||
}
|
||||
return state.scrollDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按真实滚动深度收录已进入视口的模块,未滚动只记名片主页
|
||||
*/
|
||||
export function collectViewedBlockKeys(
|
||||
card: CardPortalDetail | null,
|
||||
scrollDepth: number
|
||||
): string[] {
|
||||
const keys: string[] = ['hero'];
|
||||
if (card == null) {
|
||||
return keys;
|
||||
}
|
||||
const depth = Math.min(100, Math.max(0, Math.round(scrollDepth)));
|
||||
const blocks = filterVisibleBentoBlocks(card.bentoBlocks);
|
||||
const sequence: string[] = [];
|
||||
if (depth > 0) {
|
||||
sequence.push('appointment');
|
||||
}
|
||||
const visibleCount = depth <= 0 ? 0 : Math.max(1, Math.ceil((depth / 100) * Math.max(blocks.length, 1)));
|
||||
const take = Math.min(blocks.length, visibleCount);
|
||||
for (let i = 0; i < take; i++) {
|
||||
const block = blocks[i];
|
||||
const id = block.id != null ? String(block.id).trim() : '';
|
||||
if (id !== '') {
|
||||
sequence.push(id);
|
||||
} else if (block.type != null && String(block.type).trim() !== '') {
|
||||
sequence.push(String(block.type).trim());
|
||||
}
|
||||
}
|
||||
const seen: Record<string, boolean> = { hero: true };
|
||||
for (let i = 0; i < sequence.length; i++) {
|
||||
const key = sequence[i];
|
||||
if (seen[key] === true) {
|
||||
continue;
|
||||
}
|
||||
seen[key] = true;
|
||||
keys.push(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报访客停留时长与阅读深度,并带上已查看模块
|
||||
*/
|
||||
export async function reportPortalStay(
|
||||
state: PortalState,
|
||||
@@ -227,6 +292,10 @@ export async function reportPortalStay(
|
||||
return null;
|
||||
}
|
||||
|
||||
const depth = Math.min(100, Math.max(0, Math.round(scrollDepth)));
|
||||
if (depth > state.scrollDepth) {
|
||||
state.scrollDepth = depth;
|
||||
}
|
||||
const stayDurationMs = Math.max(0, Date.now() - state.enterTime);
|
||||
try {
|
||||
const track = await recordRadarTrack({
|
||||
@@ -234,7 +303,8 @@ export async function reportPortalStay(
|
||||
visitorId: state.visitorId,
|
||||
touchType: state.touchType,
|
||||
stayDurationMs,
|
||||
scrollDepth,
|
||||
scrollDepth: state.scrollDepth,
|
||||
viewedBlocks: collectViewedBlockKeys(state.card, state.scrollDepth),
|
||||
});
|
||||
return track;
|
||||
} catch (e) {
|
||||
@@ -290,7 +360,23 @@ export type PortalQuickAction =
|
||||
| 'phone'
|
||||
| 'telegram'
|
||||
| 'twitter'
|
||||
| 'wechat';
|
||||
| 'wechat'
|
||||
| 'line'
|
||||
| 'kakao';
|
||||
|
||||
/**
|
||||
* Line / KakaoTalk 等外链入口:仅合法 http(s) URL 可渲染与触发
|
||||
*/
|
||||
export function isRenderableHttpUrl(value?: string | null): boolean {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
if (trimmed === '') {
|
||||
return false;
|
||||
}
|
||||
return /^https?:\/\//i.test(trimmed);
|
||||
}
|
||||
|
||||
export function triggerQuickAction(
|
||||
type: PortalQuickAction,
|
||||
@@ -304,6 +390,14 @@ export function triggerQuickAction(
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((type === 'line' || type === 'kakao') && !isRenderableHttpUrl(value)) {
|
||||
uni.showToast({
|
||||
title: getOmniText(getCurrentLocale(), 'portal.contact_unset'),
|
||||
icon: 'none',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type === 'phone') {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: value,
|
||||
@@ -394,6 +488,32 @@ export function triggerQuickAction(
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type === 'line') {
|
||||
uni.setClipboardData({
|
||||
data: value.trim(),
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: getOmniText(getCurrentLocale(), 'portal.copied_line'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type === 'kakao') {
|
||||
uni.setClipboardData({
|
||||
data: value.trim(),
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: getOmniText(getCurrentLocale(), 'portal.copied_kakao'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户