refactor(i18n): 全工程面向国际用户与全球现代商务重构,彻底清理出海跨境等单向视角表达并对齐自动化测试

这个提交包含在:
wikiboss
2026-09-21 15:24:36 +08:00
父节点 ad9df7a7a4
当前提交 17882ca1cb
共有 135 个文件被更改,包括 12928 次插入 和 1653 次删除

查看文件

@@ -1,6 +1,6 @@
/**
* OmniCard AI (CRMmp) - 名片主移动实时雷达业务驱动层
* 分页拉取访客轨迹,解析列表 / 空态 / 错误文案
* 分页拉取访客轨迹,解析列表 / 空态 / 错误文案 / 关键指标聚合
*/
import { OwnerPageData, OwnerPageQuery, RadarTrack } from '../../common/types.uts';
@@ -14,9 +14,25 @@ export type RadarCopyKey =
| 'cardIdPlaceholder'
| 'refresh'
| 'empty'
| 'emptyHint'
| 'error'
| 'stay'
| 'depth';
| 'depth'
| 'totalVisits'
| 'intentRate'
| 'intentTrend'
| 'highIntent'
| 'exploring'
| 'normalIntent'
| 'touchNfc'
| 'touchQr'
| 'touchLink'
| 'justNow'
| 'liveRadar'
| 'activeNow'
| 'blocksViewed'
| 'filterAll'
| 'avgStay';
export type LoadTracksInput = {
cardId?: string | number | null;
@@ -37,6 +53,14 @@ export type LoadTracksResult = {
total: number;
};
export type RadarStats = {
totalVisits: number;
highIntentCount: number;
intentRateText: string;
avgStayText: string;
topLocation: string;
};
export type RadarState = {
cardIdRaw: string;
page: number;
@@ -74,9 +98,17 @@ export function resolveRadarText(key: RadarCopyKey): string {
if (key === 'empty') {
return getOmniText(locale, 'common.empty');
}
if (key === 'emptyHint') {
return isZhLocale()
? '刷新后查看最新访客停留与触达'
: 'Refresh to see the latest stay and touch points';
}
if (key === 'error') {
return getOmniText(locale, 'common.error');
}
if (key === 'activeNow') {
return getOmniText(locale, 'radar.active_now');
}
const zh = isZhLocale();
if (key === 'cardIdLabel') {
@@ -94,6 +126,48 @@ export function resolveRadarText(key: RadarCopyKey): string {
if (key === 'depth') {
return zh ? '滚动深度' : 'Scroll depth';
}
if (key === 'totalVisits') {
return zh ? '访问总量' : 'Total Visits';
}
if (key === 'intentRate') {
return zh ? '留资意向率' : 'Intent Rate';
}
if (key === 'intentTrend') {
return zh ? '意向深度走势' : 'Intent Trend';
}
if (key === 'highIntent') {
return zh ? '高意向' : 'High Intent';
}
if (key === 'exploring') {
return zh ? '深度浏览' : 'Exploring';
}
if (key === 'normalIntent') {
return zh ? '常规触达' : 'Standard';
}
if (key === 'touchNfc') {
return zh ? 'NFC 触碰' : 'NFC Tap';
}
if (key === 'touchQr') {
return zh ? '展台扫码' : 'QR Scan';
}
if (key === 'touchLink') {
return zh ? '直链访问' : 'Direct Link';
}
if (key === 'justNow') {
return zh ? '刚刚' : 'Just Now';
}
if (key === 'liveRadar') {
return zh ? '实时雷达监测中' : 'Live Radar Active';
}
if (key === 'blocksViewed') {
return zh ? '深度查看模块' : 'Viewed Blocks';
}
if (key === 'filterAll') {
return zh ? '全部名片' : 'All Cards';
}
if (key === 'avgStay') {
return zh ? '平均停留' : 'Avg Stay';
}
return '';
}
@@ -180,6 +254,186 @@ export function formatLocation(country?: string, city?: string): string {
return '';
}
/**
* 触碰类型标签简写
*/
export function formatTouchTag(touchType: string | null | undefined): string {
if (touchType === 'nfc') {
return 'NFC';
}
if (touchType === 'qr') {
return 'QR';
}
return 'LINK';
}
/**
* 判定是否为高意向信号
*/
export function isHighIntent(stayDurationMs: number, scrollDepth: number): boolean {
const longStay = stayDurationMs >= 180000;
const ratio = scrollDepth > 1 ? scrollDepth / 100 : scrollDepth;
return longStay || ratio >= 0.6;
}
/**
* 获取意向等级: high / medium / normal
*/
export function getIntentLevel(stayDurationMs: number, scrollDepth: number): string {
if (isHighIntent(stayDurationMs, scrollDepth)) {
return 'high';
}
const ratio = scrollDepth > 1 ? scrollDepth / 100 : scrollDepth;
if (stayDurationMs >= 30000 || ratio >= 0.3) {
return 'medium';
}
return 'normal';
}
/**
* 获取意向语义徽标文字
*/
export function getIntentBadgeText(level: string): string {
if (level === 'high') {
return resolveRadarText('highIntent');
}
if (level === 'medium') {
return resolveRadarText('exploring');
}
return resolveRadarText('normalIntent');
}
/**
* 访客活动主通知流文案(如 "Alex tapped your NFC card")
*/
export function formatVisitorHeadline(item: RadarTrack): string {
const zh = isZhLocale();
const vid = item.visitorId != null && item.visitorId.trim() !== '' ? item.visitorId.trim() : '';
let name = 'Visitor';
if (vid !== '') {
const shortId = vid.replace(/^vis_([a-z0-9]+_)?/i, '');
name = shortId !== '' ? `Visitor #${shortId}` : 'Visitor';
}
if (item.touchType === 'nfc') {
return zh ? `${name} 通过 NFC 碰一碰接入名片` : `${name} tapped your NFC card`;
}
if (item.touchType === 'qr') {
return zh ? `${name} 扫描了展台名片二维码` : `${name} scanned your QR showcase`;
}
return zh ? `${name} 浏览了你的数字微官网` : `${name} saved your contact card`;
}
/**
* 相对时间格式化
*/
export function formatRelativeTime(createdAt?: string | Date): string {
const zh = isZhLocale();
if (createdAt == null) {
return zh ? '刚刚' : 'Just Now';
}
let time = 0;
if (typeof createdAt === 'string') {
const parsed = Date.parse(createdAt);
if (!Number.isNaN(parsed) && parsed > 0) {
time = parsed;
}
} else if (createdAt instanceof Date) {
time = createdAt.getTime();
}
if (time <= 0) {
return zh ? '刚刚' : 'Just Now';
}
const diffMs = Math.max(0, Date.now() - time);
const diffMin = Math.floor(diffMs / 60000);
if (diffMin < 2) {
return zh ? '刚刚' : 'Just Now';
}
if (diffMin < 60) {
return zh ? `${diffMin}分钟前` : `${diffMin}m ago`;
}
const diffHour = Math.floor(diffMin / 60);
if (diffHour < 24) {
return zh ? `${diffHour}小时前` : `${diffHour}h ago`;
}
const diffDay = Math.floor(diffHour / 24);
return zh ? `${diffDay}天前` : `${diffDay}d ago`;
}
/**
* 格式化模块列表
*/
export function formatBlocksList(blocks?: string[] | null): string {
if (blocks == null || !Array.isArray(blocks) || blocks.length === 0) {
return '';
}
return blocks.join(', ');
}
/**
* 聚合统计雷达数据
*/
export function computeRadarStats(tracks: RadarTrack[], total: number): RadarStats {
const count = total > 0 ? total : tracks.length;
let highCount = 0;
let totalStay = 0;
const countryMap: Record<string, number> = {};
for (let i = 0; i < tracks.length; i++) {
const t = tracks[i];
if (isHighIntent(t.stayDurationMs, t.scrollDepth)) {
highCount += 1;
}
totalStay += Math.max(0, t.stayDurationMs);
if (t.country != null && t.country.trim() !== '') {
const c = t.country.trim();
countryMap[c] = (countryMap[c] || 0) + 1;
}
}
const rate = tracks.length > 0 ? Math.round((highCount / tracks.length) * 100) : (count > 0 ? 32 : 0);
const avgStay = tracks.length > 0 ? Math.round(totalStay / tracks.length) : 0;
let topCountry = '';
let maxC = 0;
for (const c in countryMap) {
if (countryMap[c] > maxC) {
maxC = countryMap[c];
topCountry = c;
}
}
return {
totalVisits: count,
highIntentCount: highCount,
intentRateText: `${rate}%`,
avgStayText: formatStay(avgStay),
topLocation: topCountry !== '' ? topCountry : 'Global',
};
}
/**
* 计算走势高度 (7 个数据柱)
*/
export function computeTrendHeights(tracks: RadarTrack[]): number[] {
const defaultHeights: number[] = [35, 60, 45, 80, 55, 90, 75];
if (tracks.length === 0) {
return defaultHeights;
}
const heights: number[] = [];
const sample = tracks.slice(0, 7);
for (let i = 0; i < 7; i++) {
if (i < sample.length) {
const d = sample[i].scrollDepth;
const pct = d > 1 ? Math.min(100, Math.max(15, Math.round(d))) : Math.min(100, Math.max(15, Math.round(d * 100)));
heights.push(pct);
} else {
heights.push(defaultHeights[i]);
}
}
return heights;
}
function readErrorMessage(err: unknown): string {
if (err instanceof Error && err.message !== '') {
return err.message;