feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口

补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。

Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
wikiboss
2026-09-23 18:01:47 +08:00
父节点 8ea9c25386
当前提交 62e0ae4435
共有 227 个文件被更改,包括 21855 次插入 和 5264 次删除

查看文件

@@ -1,9 +1,10 @@
/**
* OmniCard AI (CRMmp) - 名片主独立数据统计与销售漏斗业务驱动层
* 纯函数计算转化率、漏斗阶段折损、渠道成效矩阵与国际化
* R31: 数字与柱状仅来自接口;失败/缺字段时归零且图表为空
*/
import { LeadEntity, OwnerPageQuery } from '../../common/types.uts';
import { LeadEntity, OwnerPageData, OwnerPageQuery } from '../../common/types.uts';
import { fetchOwnerLeadPage } from '../../common/api.uts';
import { getCurrentLocale, getOmniText } from '../../common/locale.uts';
@@ -40,6 +41,12 @@ export type StatsState = {
errorMessage: string;
};
export type LoadStatsApi = {
fetchOwnerLeadPage?: (
query: OwnerPageQuery
) => Promise<OwnerPageData<LeadEntity> | Record<string, unknown> | null>;
};
function isZhLocale(): boolean {
return getCurrentLocale() === 'zh-CN';
}
@@ -166,40 +173,71 @@ export function resolveStatsText(key: string): string {
if (key === 'stepDescWon') {
return isZhLocale() ? '签约成交' : 'Closed';
}
if (key === 'badgeTotal') {
return isZhLocale() ? '总量' : 'TOTAL';
}
if (key === 'badgeHot') {
return isZhLocale() ? '高意向' : 'HOT';
}
if (key === 'badgeWon') {
return isZhLocale() ? '成交' : 'WON';
}
if (key === 'badgeRate') {
return isZhLocale() ? '转化' : 'CVR';
}
if (key === 'funnelStages') {
return isZhLocale() ? '四阶' : '4 STAGES';
}
return key;
}
function emptySummary(): StatsSummary {
return {
totalLeads: 0,
hotLeads: 0,
wonLeads: 0,
overallRate: 0,
};
}
export function createStatsState(): StatsState {
return {
period: 'all',
summary: {
totalLeads: 0,
hotLeads: 0,
wonLeads: 0,
overallRate: 0,
},
funnel: [
{ key: 'new', label: resolveStatsText('stepNew'), count: 0, rate: 0 },
{ key: 'hot', label: resolveStatsText('stepHot'), count: 0, rate: 0 },
{ key: 'contacted', label: resolveStatsText('stepContacted'), count: 0, rate: 0 },
{ key: 'won', label: resolveStatsText('stepWon'), count: 0, rate: 0 },
],
channels: [
{ source: 'nfc', label: resolveStatsText('sourceNfc'), leadsCount: 0, wonCount: 0, conversionRate: 0 },
{ source: 'qr', label: resolveStatsText('sourceQr'), leadsCount: 0, wonCount: 0, conversionRate: 0 },
{ source: 'link', label: resolveStatsText('sourceLink'), leadsCount: 0, wonCount: 0, conversionRate: 0 },
{ source: 'ai_chat', label: resolveStatsText('sourceAi'), leadsCount: 0, wonCount: 0, conversionRate: 0 },
],
summary: emptySummary(),
funnel: [],
channels: [],
loading: false,
errorMessage: '',
};
}
/** R31: 失败或缺字段时数字归零、图表清空 */
export function resetStatsToEmpty(state: StatsState): void {
state.summary = emptySummary();
state.funnel = [];
state.channels = [];
}
function parseLeadList(res: OwnerPageData<LeadEntity> | Record<string, unknown> | null): LeadEntity[] {
if (res == null) {
return [];
}
const list = (res as OwnerPageData<LeadEntity>).list;
if (list == null || !Array.isArray(list)) {
return [];
}
return list;
}
export function computeStatsFromLeads(leads: LeadEntity[], period: StatsPeriod): StatsState {
const state = createStatsState();
state.period = period;
if (leads == null || leads.length === 0) {
return state;
}
let totalCount = 0;
let hotCount = 0;
let newCount = 0;
@@ -217,7 +255,8 @@ export function computeStatsFromLeads(leads: LeadEntity[], period: StatsPeriod):
const item = leads[i];
totalCount++;
if (item.status === 'hot' || item.intentScore >= 80) {
const score = item.intentScore != null ? item.intentScore : 0;
if (item.status === 'hot' || score >= 80) {
hotCount++;
}
if (item.status === 'new') {
@@ -242,55 +281,90 @@ export function computeStatsFromLeads(leads: LeadEntity[], period: StatsPeriod):
state.summary.wonLeads = wonCount;
state.summary.overallRate = calcConversionRate(totalCount, wonCount);
// 漏斗阶梯与转化率
state.funnel[0].count = totalCount;
state.funnel[0].rate = totalCount > 0 ? 100 : 0;
state.funnel = [
{
key: 'new',
label: resolveStatsText('stepNew'),
count: totalCount,
rate: totalCount > 0 ? 100 : 0,
},
{
key: 'hot',
label: resolveStatsText('stepHot'),
count: hotCount,
rate: calcFunnelStepRate(hotCount, totalCount),
},
{
key: 'contacted',
label: resolveStatsText('stepContacted'),
count: contactedCount,
rate: calcFunnelStepRate(contactedCount, totalCount),
},
{
key: 'won',
label: resolveStatsText('stepWon'),
count: wonCount,
rate: calcFunnelStepRate(wonCount, totalCount),
},
];
state.funnel[1].count = hotCount;
state.funnel[1].rate = calcFunnelStepRate(hotCount, totalCount);
state.funnel[2].count = contactedCount;
state.funnel[2].rate = calcFunnelStepRate(contactedCount, totalCount);
state.funnel[3].count = wonCount;
state.funnel[3].rate = calcFunnelStepRate(wonCount, totalCount);
// 渠道成效
state.channels[0].leadsCount = channelMap['nfc'].leads;
state.channels[0].wonCount = channelMap['nfc'].won;
state.channels[0].conversionRate = calcConversionRate(channelMap['nfc'].leads, channelMap['nfc'].won);
state.channels[1].leadsCount = channelMap['qr'].leads;
state.channels[1].wonCount = channelMap['qr'].won;
state.channels[1].conversionRate = calcConversionRate(channelMap['qr'].leads, channelMap['qr'].won);
state.channels[2].leadsCount = channelMap['link'].leads;
state.channels[2].wonCount = channelMap['link'].won;
state.channels[2].conversionRate = calcConversionRate(channelMap['link'].leads, channelMap['link'].won);
state.channels[3].leadsCount = channelMap['ai_chat'].leads;
state.channels[3].wonCount = channelMap['ai_chat'].won;
state.channels[3].conversionRate = calcConversionRate(channelMap['ai_chat'].leads, channelMap['ai_chat'].won);
state.channels = [
{
source: 'nfc',
label: resolveStatsText('sourceNfc'),
leadsCount: channelMap['nfc'].leads,
wonCount: channelMap['nfc'].won,
conversionRate: calcConversionRate(channelMap['nfc'].leads, channelMap['nfc'].won),
},
{
source: 'qr',
label: resolveStatsText('sourceQr'),
leadsCount: channelMap['qr'].leads,
wonCount: channelMap['qr'].won,
conversionRate: calcConversionRate(channelMap['qr'].leads, channelMap['qr'].won),
},
{
source: 'link',
label: resolveStatsText('sourceLink'),
leadsCount: channelMap['link'].leads,
wonCount: channelMap['link'].won,
conversionRate: calcConversionRate(channelMap['link'].leads, channelMap['link'].won),
},
{
source: 'ai_chat',
label: resolveStatsText('sourceAi'),
leadsCount: channelMap['ai_chat'].leads,
wonCount: channelMap['ai_chat'].won,
conversionRate: calcConversionRate(channelMap['ai_chat'].leads, channelMap['ai_chat'].won),
},
];
return state;
}
export async function loadStatsData(state: StatsState): Promise<void> {
export async function loadStatsData(state: StatsState, api?: LoadStatsApi): Promise<void> {
state.loading = true;
state.errorMessage = '';
const fetchPage =
api != null && api.fetchOwnerLeadPage != null
? api.fetchOwnerLeadPage
: fetchOwnerLeadPage;
try {
const query: OwnerPageQuery = {
page: 1,
size: 100,
};
const res = await fetchOwnerLeadPage(query);
const computed = computeStatsFromLeads(res.list, state.period);
const res = await fetchPage(query);
const list = parseLeadList(res);
const computed = computeStatsFromLeads(list, state.period);
state.summary = computed.summary;
state.funnel = computed.funnel;
state.channels = computed.channels;
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : String(err);
resetStatsToEmpty(state);
state.errorMessage = msg !== '' ? msg : resolveStatsText('error');
} finally {
state.loading = false;