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 次删除

查看文件

@@ -29,6 +29,7 @@ export type LeadDetailCopyKey =
| 'notes'
| 'notesPlaceholder'
| 'save'
| 'saving'
| 'back'
| 'empty'
| 'missingId'
@@ -52,7 +53,10 @@ export type LeadDetailCopyKey =
| 'scriptCopiedToast'
| 'savedContactToast'
| 'leadTitle'
| 'aiScriptTitle';
| 'aiScriptTitle'
| 'callFailed'
| 'noteSavedToast'
| 'notesRequiredToast';
export type LeadDetailPageOptions = {
id?: string;
@@ -91,6 +95,13 @@ export type SaveNoteApi = {
) => Promise<LeadEntity>;
};
export type SaveNoteResult = {
ok: boolean;
code?: number;
lead: LeadEntity | null;
errorMessage: string;
};
export type LeadDetailState = {
rawId: string;
leadId: string | number | null;
@@ -221,12 +232,18 @@ export function resolveLeadDetailText(key: LeadDetailCopyKey): string {
if (key === 'aiScriptTitle') {
return zh ? '建议跟进话术' : 'Follow-up Suggestion';
}
if (key === 'callFailed') {
return zh ? '无法拨打电话' : 'Unable to place the call';
}
if (key === 'noteSavedToast') {
return zh ? '备忘已保存' : 'Note saved';
}
if (key === 'notesRequiredToast') {
return zh ? '请输入备忘或上传附件' : 'Please enter note or upload attachment';
}
if (key === 'saving') {
return zh ? '保存中' : 'Saving';
}
return '';
}
@@ -313,6 +330,80 @@ export function formatWhatsAppUrl(rawPhone: string | null | undefined): string {
return `https://wa.me/${digits}`;
}
function toastNone(title: string): void {
uni.showToast({
title,
icon: 'none',
});
}
/**
* 打开外链:优先 window.open(H5),否则复制链接(对齐 useLogin openOrCopyAuthUrl)
*/
function openExternalUrl(url: string): boolean {
const safeUrl = url != null ? url.trim() : '';
if (safeUrl === '') {
return false;
}
let opened = false;
try {
if (typeof window !== 'undefined' && typeof window.open === 'function') {
window.open(safeUrl, '_blank');
opened = true;
}
} catch (_e) {}
if (opened) {
return true;
}
try {
uni.setClipboardData({
data: safeUrl,
showToast: true,
});
return true;
} catch (_e) {
return false;
}
}
/**
* 有合法电话号时调 uni.makePhoneCall;无号码 toast comingSoon。
* 不伪造成功:fail 回调提示 callFailed。
*/
export function callLeadPhone(phone: string | null | undefined): boolean {
const trimmed = phone != null ? String(phone).trim() : '';
const digits = trimmed.replace(/[^0-9]/g, '');
if (trimmed === '' || digits === '') {
toastNone(resolveLeadDetailText('comingSoon'));
return false;
}
uni.makePhoneCall({
phoneNumber: trimmed,
fail: () => {
toastNone(resolveLeadDetailText('callFailed'));
},
});
return true;
}
/**
* 有 WhatsApp/电话号码时打开 wa.me;无号码 toast comingSoon,不打开空链接。
*/
export function openLeadWhatsApp(
phoneOrWhatsApp: string | null | undefined
): boolean {
const waUrl = formatWhatsAppUrl(phoneOrWhatsApp);
if (waUrl === '') {
toastNone(resolveLeadDetailText('comingSoon'));
return false;
}
return openExternalUrl(waUrl);
}
/**
* 跟进话术生成器 (基于客户姓名、公司、渠道与意向板块)
*/
@@ -417,11 +508,19 @@ export function parseNoteAttachments(
return { cleanText, imageUrls };
}
export type DeviceContactDraft = {
id?: string | number;
name: string;
company?: string;
phone?: string;
email?: string;
};
/**
* 保存到手机系统通讯录 (深度复用通用 RFC 6350 / vCard 引擎)
*/
export async function saveContactToDevice(
lead: LeadEntity | null
lead: DeviceContactDraft | null
): Promise<boolean> {
if (lead == null) {
return false;
@@ -516,11 +615,12 @@ export async function loadDetail(
/**
* 更新 notes(支持附件结构化嵌入):POST /admin/crm/lead/update { id, notes }
* 仅 Cool-Admin code === 1000(http 层已解包成功)视为保存成功
*/
export async function saveNote(
input: SaveNoteInput,
api?: SaveNoteApi
): Promise<LeadEntity> {
): Promise<SaveNoteResult> {
const notes = appendStructuredNote(
input.notes,
input.next,
@@ -532,7 +632,22 @@ export async function saveNote(
id: input.id,
notes,
};
return post<LeadEntity>('/admin/crm/lead/update', payload);
try {
const lead = await post<LeadEntity>('/admin/crm/lead/update', payload);
return {
ok: true,
code: 1000,
lead,
errorMessage: '',
};
} catch (err) {
return {
ok: false,
code: undefined,
lead: null,
errorMessage: readErrorMessage(err),
};
}
}
export function createLeadDetailState(): LeadDetailState {
@@ -653,27 +768,27 @@ export async function submitLeadNote(
}
state.saving = true;
state.errorMessage = '';
try {
const saved = await saveNote(
{
id: state.leadId,
notes: state.existingNotes,
next,
status: state.lead != null ? state.lead.status : undefined,
attachments: state.attachments,
},
api
);
applyLeadToState(state, saved);
const result = await saveNote(
{
id: state.leadId,
notes: state.existingNotes,
next,
status: state.lead != null ? state.lead.status : undefined,
attachments: state.attachments,
},
api
);
// 仅接口 code === 1000 才清空输入并标成已保存
if (result.ok && result.code === 1000 && result.lead != null) {
applyLeadToState(state, result.lead);
state.nextNote = '';
state.attachments = [];
state.saving = false;
return true;
} catch (err) {
state.saving = false;
state.errorMessage = readErrorMessage(err);
return false;
}
state.saving = false;
state.errorMessage = result.errorMessage;
return false;
}
export async function updateLeadStage(