feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -24,7 +24,12 @@ type RadarTrackFixture = {
|
||||
stayDurationMs: number;
|
||||
scrollDepth: number;
|
||||
viewedBlocks: string[];
|
||||
viewedContents?: { key: string; title?: string }[];
|
||||
visitorName?: string;
|
||||
visitorCompany?: string;
|
||||
avatarUrl?: string;
|
||||
createdAt?: string | Date;
|
||||
createTime?: string | Date;
|
||||
};
|
||||
|
||||
type OwnerPageQueryFixture = {
|
||||
@@ -61,12 +66,37 @@ type LoadTracksResult = {
|
||||
total: number;
|
||||
};
|
||||
|
||||
type RadarStateFixture = {
|
||||
cardIdRaw: string;
|
||||
page: number;
|
||||
size: number;
|
||||
total: number;
|
||||
loading: boolean;
|
||||
empty: boolean;
|
||||
errorMessage: string;
|
||||
tracks: RadarTrackFixture[];
|
||||
};
|
||||
|
||||
type UseRadarModule = {
|
||||
formatStay: (ms: number | null | undefined) => string;
|
||||
formatDepth: (depth: number | null | undefined) => string;
|
||||
formatLocation: (country?: string, city?: string) => string;
|
||||
isHighIntent: (stayDurationMs: number, scrollDepth: number) => boolean;
|
||||
loadTracks: (input: LoadTracksInput, api?: RadarFetchApi) => Promise<LoadTracksResult>;
|
||||
createRadarState: () => RadarStateFixture;
|
||||
refreshTracks: (
|
||||
state: RadarStateFixture,
|
||||
api?: RadarFetchApi
|
||||
) => Promise<LoadTracksResult>;
|
||||
resolveRadarText: (key: string) => string;
|
||||
};
|
||||
|
||||
/** 与后端热线索 / 页面既有阈值一致:停留 ≥ 3 分钟 */
|
||||
const HIGH_INTENT_STAY_MS = 180000;
|
||||
/** tokens.uts light error */
|
||||
const ERROR_TOKEN = '#F04438';
|
||||
const ERROR_CSS_VAR = '--oc-error';
|
||||
|
||||
type UniToastOption = {
|
||||
title: string;
|
||||
icon?: string;
|
||||
@@ -296,6 +326,139 @@ describe('OmniCard AI 名片主移动实时雷达业务逻辑测试 (useRadar.ut
|
||||
expect(result.total).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('3. isHighIntent 高意向阈值(停留 ≥ 3 分钟)', () => {
|
||||
it('3.1 停留达到 180000ms 判定为高意向,未达阈值且深度不足则为否', () => {
|
||||
const { isHighIntent } = loadUseRadar();
|
||||
|
||||
expect(isHighIntent(HIGH_INTENT_STAY_MS, 0)).toBe(true);
|
||||
expect(isHighIntent(HIGH_INTENT_STAY_MS - 1, 0)).toBe(false);
|
||||
expect(isHighIntent(0, 0.6)).toBe(true);
|
||||
expect(isHighIntent(0, 60)).toBe(true);
|
||||
expect(isHighIntent(29999, 0.2)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('4. formatLocation 空国家显示未知,禁止默认示例城市', () => {
|
||||
it('4.1 无国家或国家为空时走 i18n 未知,不回退迪拜/阿联酋', () => {
|
||||
const { formatLocation, resolveRadarText } = loadUseRadar();
|
||||
const unknownText = resolveRadarText('unknown');
|
||||
|
||||
expect(unknownText).toBeTruthy();
|
||||
expect(unknownText).toBe('未知');
|
||||
expect(formatLocation(undefined, undefined)).toBe(unknownText);
|
||||
expect(formatLocation(null as unknown as string, null as unknown as string)).toBe(
|
||||
unknownText
|
||||
);
|
||||
expect(formatLocation('', '')).toBe(unknownText);
|
||||
expect(formatLocation(' ', ' ')).toBe(unknownText);
|
||||
expect(formatLocation('', 'Paris')).toBe(`${unknownText} / Paris`);
|
||||
expect(formatLocation('China', 'Shanghai')).toBe('China / Shanghai');
|
||||
expect(formatLocation('Japan', '')).toBe('Japan');
|
||||
|
||||
expect(formatLocation(undefined, undefined)).not.toContain('Dubai');
|
||||
expect(formatLocation('', '')).not.toContain('United Arab Emirates');
|
||||
expect(formatLocation('', '')).not.toContain('阿联酋');
|
||||
});
|
||||
|
||||
it('4.2 接口失败时 refreshTracks 清空既有列表,不保留示例国家', async () => {
|
||||
const { createRadarState, refreshTracks } = loadUseRadar();
|
||||
const state = createRadarState();
|
||||
state.tracks = [
|
||||
buildTrack({ id: 1, country: 'United Arab Emirates', city: 'Dubai' }),
|
||||
buildTrack({ id: 2, country: 'China', city: 'Shanghai' }),
|
||||
];
|
||||
state.empty = false;
|
||||
state.total = 2;
|
||||
|
||||
const fetchOwnerRadarPage = jest.fn(async () => {
|
||||
throw new Error('雷达服务暂不可用');
|
||||
});
|
||||
|
||||
const result = await refreshTracks(state, { fetchOwnerRadarPage });
|
||||
|
||||
expect(fetchOwnerRadarPage).toHaveBeenCalledTimes(1);
|
||||
expect(result.list).toEqual([]);
|
||||
expect(state.tracks).toEqual([]);
|
||||
expect(state.empty).toBe(true);
|
||||
expect(state.total).toBe(0);
|
||||
expect(state.errorMessage).toBe('雷达服务暂不可用');
|
||||
expect(JSON.stringify(state.tracks)).not.toContain('Dubai');
|
||||
expect(JSON.stringify(state.tracks)).not.toContain('United Arab Emirates');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('OmniCard AI 雷达监控准确性 (useRadar.uts)', () => {
|
||||
function loadRadar(): {
|
||||
formatLocation: (country?: string, city?: string) => string;
|
||||
formatPublicIp: (ip?: string) => string;
|
||||
formatViewedLabels: (item: RadarTrackFixture) => string[];
|
||||
consolidateRadarTracks: (tracks: RadarTrackFixture[]) => RadarTrackFixture[];
|
||||
isVisitorOnline: (
|
||||
item: RadarTrackFixture,
|
||||
now?: number
|
||||
) => boolean;
|
||||
formatVisitorAction: (item: RadarTrackFixture) => string;
|
||||
formatClockTime: (createdAt?: string | Date) => string;
|
||||
RADAR_ONLINE_WINDOW_MS: number;
|
||||
} {
|
||||
return require('../../../mpuniapp/pages/owner/useRadar.uts');
|
||||
}
|
||||
|
||||
it('内网与 Unknown 不当成真实城市,公网 IP 才保留', () => {
|
||||
const { formatLocation, formatPublicIp } = loadRadar();
|
||||
expect(formatLocation('Local', 'Local')).toBe('本地网络');
|
||||
expect(formatLocation('Unknown', 'Unknown')).toBe('未知');
|
||||
expect(formatPublicIp('127.0.0.1')).toBe('');
|
||||
expect(formatPublicIp('192.168.1.8')).toBe('');
|
||||
expect(formatPublicIp('8.8.8.8')).toBe('8.8.8.8');
|
||||
});
|
||||
|
||||
it('同一访客的进入与离开合并,停留、深度和浏览模块取完整会话', () => {
|
||||
const { consolidateRadarTracks, formatViewedLabels, formatVisitorAction } = loadRadar();
|
||||
const rows = consolidateRadarTracks([
|
||||
buildTrack({
|
||||
id: 1,
|
||||
stayDurationMs: 0,
|
||||
scrollDepth: 0,
|
||||
viewedBlocks: ['hero'],
|
||||
createdAt: '2026-09-23T08:00:00.000Z',
|
||||
}),
|
||||
buildTrack({
|
||||
id: 2,
|
||||
stayDurationMs: 45000,
|
||||
scrollDepth: 80,
|
||||
viewedBlocks: ['case', 'article'],
|
||||
visitorName: 'Alex',
|
||||
avatarUrl: 'https://cdn.example.com/a.png',
|
||||
visitorCompany: 'Nexus',
|
||||
createdAt: '2026-09-23T08:02:00.000Z',
|
||||
viewedContents: [
|
||||
{ key: 'case', title: 'Middle East Hub' },
|
||||
{ key: 'article', title: '' },
|
||||
],
|
||||
}),
|
||||
]);
|
||||
expect(rows).toHaveLength(1);
|
||||
expect(rows[0].stayDurationMs).toBe(45000);
|
||||
expect(rows[0].scrollDepth).toBe(80);
|
||||
expect(rows[0].visitorName).toBe('Alex');
|
||||
expect(rows[0].avatarUrl).toBe('https://cdn.example.com/a.png');
|
||||
expect(formatViewedLabels(rows[0])).toEqual(['Middle East Hub', '文章']);
|
||||
expect(formatVisitorAction(rows[0])).toBe('通过 NFC 碰一碰打开名片');
|
||||
expect(formatVisitorAction(buildTrack({ touchType: 'link' }))).not.toContain('留资');
|
||||
});
|
||||
|
||||
it('5 分钟内算在线,更早的足迹不算在线', () => {
|
||||
const { isVisitorOnline, formatClockTime, RADAR_ONLINE_WINDOW_MS } = loadRadar();
|
||||
const now = Date.parse('2026-09-23T10:00:00.000Z');
|
||||
const recent = buildTrack({ createdAt: new Date(now - 60 * 1000).toISOString() });
|
||||
const stale = buildTrack({ createdAt: new Date(now - RADAR_ONLINE_WINDOW_MS - 1000).toISOString() });
|
||||
expect(isVisitorOnline(recent, now)).toBe(true);
|
||||
expect(isVisitorOnline(stale, now)).toBe(false);
|
||||
expect(formatClockTime('2026-09-23T10:05:00.000Z')).toMatch(/^\d{2}-\d{2} \d{2}:\d{2}$/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('OmniCard AI 名片主移动实时雷达页契约 (radar.uvue)', () => {
|
||||
@@ -338,4 +501,90 @@ describe('OmniCard AI 名片主移动实时雷达页契约 (radar.uvue)', () =>
|
||||
expect(/[\u4e00-\u9fff]/.test(template)).toBe(false);
|
||||
expect(pageSource.includes('innerAudioContext') || pageSource.includes('autoplay')).toBe(false);
|
||||
});
|
||||
|
||||
it('高意向行用 error token 标出,不用品牌蓝当警告', () => {
|
||||
const pageSource = fs.readFileSync(RADAR_PAGE, 'utf8');
|
||||
const logicSource = fs.readFileSync(RADAR_UTS, 'utf8');
|
||||
const styleBlock = pageSource.includes('<style')
|
||||
? pageSource.slice(pageSource.indexOf('<style'))
|
||||
: '';
|
||||
|
||||
expect(logicSource.includes('180000')).toBe(true);
|
||||
expect(pageSource.includes('isHighIntent')).toBe(true);
|
||||
expect(pageSource.includes('radar-row-hot')).toBe(true);
|
||||
expect(pageSource.includes(`'--oc-error'`) || pageSource.includes(`"--oc-error"`) || pageSource.includes(ERROR_CSS_VAR)).toBe(
|
||||
true
|
||||
);
|
||||
expect(pageSource.includes(ERROR_TOKEN) || pageSource.includes('utsLightColors.error')).toBe(true);
|
||||
|
||||
const hotRuleMatch = styleBlock.match(/\.radar-row-hot\s*\{[^}]+\}/);
|
||||
expect(hotRuleMatch).not.toBeNull();
|
||||
const hotRule = hotRuleMatch != null ? hotRuleMatch[0] : '';
|
||||
expect(hotRule.includes('#E3E7ED')).toBe(true);
|
||||
expect(hotRule.includes(ERROR_TOKEN)).toBe(false);
|
||||
expect(hotRule.includes('#F04438')).toBe(false);
|
||||
expect(hotRule.includes('#FEF3F2')).toBe(false);
|
||||
expect(hotRule.includes('#0088FF')).toBe(false);
|
||||
expect(hotRule.includes('#0B5CFF')).toBe(false);
|
||||
expect(hotRule.includes('#3894FF')).toBe(false);
|
||||
expect(hotRule.includes('var(--oc-primary')).toBe(false);
|
||||
|
||||
const intentHighMatch = styleBlock.match(/\.intent-high\s*\{[^}]+\}/);
|
||||
expect(intentHighMatch).not.toBeNull();
|
||||
const intentHighRule = intentHighMatch != null ? intentHighMatch[0] : '';
|
||||
expect(intentHighRule.includes('#0088FF')).toBe(false);
|
||||
expect(intentHighRule.includes('#0B5CFF')).toBe(false);
|
||||
|
||||
const intentHighTextMatch = styleBlock.match(/\.intent-high\s+\.intent-text\s*\{[^}]+\}/);
|
||||
expect(intentHighTextMatch).not.toBeNull();
|
||||
const intentHighTextRule = intentHighTextMatch != null ? intentHighTextMatch[0] : '';
|
||||
expect(
|
||||
intentHighTextRule.includes(ERROR_CSS_VAR) || intentHighTextRule.includes(ERROR_TOKEN)
|
||||
).toBe(true);
|
||||
expect(intentHighTextRule.includes('#0088FF')).toBe(false);
|
||||
expect(intentHighTextRule.includes('#0B5CFF')).toBe(false);
|
||||
});
|
||||
|
||||
it('R42: 足迹空国家显示未知;源码不以 Dubai/阿联酋为默认;失败清空列表', () => {
|
||||
const pageSource = fs.readFileSync(RADAR_PAGE, 'utf8');
|
||||
const logicSource = fs.readFileSync(RADAR_UTS, 'utf8');
|
||||
const template = pageSource.split('<script')[0];
|
||||
|
||||
expect(logicSource.includes("'unknown'") || logicSource.includes('"unknown"')).toBe(true);
|
||||
expect(logicSource.includes('resolveRadarText(') && logicSource.includes('unknown')).toBe(
|
||||
true
|
||||
);
|
||||
expect(logicSource.includes('formatLocation')).toBe(true);
|
||||
expect(pageSource.includes('formatLocation')).toBe(true);
|
||||
expect(template.includes('formatLocation(item.country, item.city)')).toBe(true);
|
||||
|
||||
expect(logicSource.includes('Dubai')).toBe(false);
|
||||
expect(logicSource.includes('United Arab Emirates')).toBe(false);
|
||||
expect(logicSource.includes('阿联酋')).toBe(false);
|
||||
expect(pageSource.includes('Dubai')).toBe(false);
|
||||
expect(pageSource.includes('United Arab Emirates')).toBe(false);
|
||||
expect(pageSource.includes('阿联酋')).toBe(false);
|
||||
|
||||
expect(logicSource.includes('list: []')).toBe(true);
|
||||
expect(logicSource.includes('tracks: []')).toBe(true);
|
||||
expect(logicSource.includes('state.tracks = result.list')).toBe(true);
|
||||
});
|
||||
|
||||
it('监控行展示头像、地址、时刻与浏览内容', () => {
|
||||
const pageSource = fs.readFileSync(RADAR_PAGE, 'utf8');
|
||||
const logicSource = fs.readFileSync(RADAR_UTS, 'utf8');
|
||||
const template = pageSource.split('<script')[0];
|
||||
|
||||
expect(template.includes('formatLocation(item.country, item.city)')).toBe(true);
|
||||
expect(template.includes('avatar-img')).toBe(true);
|
||||
expect(template.includes('mini-avatar-img')).toBe(true);
|
||||
expect(template.includes('avatar-online')).toBe(true);
|
||||
expect(template.includes('formatBlocks(item)')).toBe(true);
|
||||
expect(logicSource.includes('formatMonitorTime')).toBe(true);
|
||||
expect(logicSource.includes('formatViewedLine')).toBe(true);
|
||||
expect(logicSource.includes('isVisitorOnline')).toBe(true);
|
||||
expect(logicSource.includes('consolidateRadarTracks')).toBe(true);
|
||||
expect(logicSource.includes('saved your contact card')).toBe(false);
|
||||
expect(logicSource.includes('? 32')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
在新工单中引用
屏蔽一个用户