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

查看文件

@@ -4,6 +4,7 @@
*/
import { ExchangeForm } from './useExchange.uts';
import { httpPost } from '../../common/request.uts';
export type ExtractedContactInfo = {
name: string;
@@ -15,6 +16,14 @@ export type ExtractedContactInfo = {
rawText: string;
};
export type OcrApiRecognizeResult = {
name: string;
company: string;
phone: string;
email: string;
title: string;
};
export type OcrScanState = {
scanning: boolean;
rawText: string;
@@ -27,6 +36,10 @@ export type HandleOcrUploadOptions = {
mockText?: string;
sourceType?: string[];
overwrite?: boolean;
httpPost?: (
url: string,
data?: Record<string, string>
) => Promise<OcrApiRecognizeResult>;
};
/**
@@ -526,7 +539,7 @@ export function fillFormFromOcr(
}
/**
* 模拟 OCR 识别返回预设样例名片,用于客户端无外部云 OCR 时的交互演示与离线测试
* 模拟 OCR 识别返回预设样例名片,仅供离线演示/单测;真实上传路径不得依赖此函数
*/
export function simulateOcrScan(sampleType?: string): ExtractedContactInfo {
if (sampleType === 'uae' || sampleType === 'dubai') {
@@ -558,6 +571,87 @@ export function simulateOcrScan(sampleType?: string): ExtractedContactInfo {
`);
}
/**
* 将后端 OCR 识别结果映射为本地填单结构
*/
export function mapOcrApiResult(apiResult: OcrApiRecognizeResult): ExtractedContactInfo {
const name = apiResult != null && apiResult.name != null ? String(apiResult.name).trim() : '';
const company =
apiResult != null && apiResult.company != null ? String(apiResult.company).trim() : '';
const phoneRaw =
apiResult != null && apiResult.phone != null ? String(apiResult.phone).trim() : '';
const email = apiResult != null && apiResult.email != null ? String(apiResult.email).trim() : '';
const title = apiResult != null && apiResult.title != null ? String(apiResult.title).trim() : '';
const phone = phoneRaw !== '' ? normalizeE164Phone(phoneRaw) : '';
return {
name,
company,
phone,
email,
title,
notes: '',
rawText: [name, title, company, phone, email].filter((v) => v !== '').join('\n'),
};
}
/**
* 读取本地图片为 base64;不可读时返回空串
*/
function readLocalImageBase64(filePath: string): Promise<string> {
return new Promise<string>((resolve) => {
try {
if (typeof uni === 'undefined' || typeof uni.getFileSystemManager !== 'function') {
resolve('');
return;
}
const fs = uni.getFileSystemManager();
if (fs == null || typeof fs.readFile !== 'function') {
resolve('');
return;
}
fs.readFile({
filePath: filePath,
encoding: 'base64',
success: (res: unknown) => {
let data = '';
if (res != null && typeof res === 'object') {
const r = res as Record<string, unknown>;
if (r.data != null) {
data = String(r.data);
}
}
resolve(data);
},
fail: (_err: unknown) => {
resolve('');
},
});
} catch (_e) {
resolve('');
}
});
}
/**
* 根据选图路径组装 OCR 请求体:优先 imageBase64,其次 imageUrl
*/
async function buildOcrRecognizeBody(
imagePath: string
): Promise<Record<string, string>> {
const path = imagePath.trim();
if (path.startsWith('http://') || path.startsWith('https://')) {
return { imageUrl: path };
}
const base64 = await readLocalImageBase64(path);
if (base64 !== '') {
return { imageBase64: base64 };
}
return { imageUrl: path };
}
/**
* 拍照或上传名片 OCR 识别流程处理入口
*/
@@ -568,11 +662,16 @@ export async function handleCardOcrUpload(
): Promise<boolean> {
const opt = options != null ? options : {};
const overwrite = opt.overwrite !== undefined ? opt.overwrite : true;
const postFn =
opt.httpPost != null
? opt.httpPost
: (url: string, data?: Record<string, string>) =>
httpPost<OcrApiRecognizeResult>(url, data);
ocrState.scanning = true;
ocrState.errorMessage = '';
// 1. 如果传入 mockText,直接模拟完成识别 (用于测试或开发模拟)
// 1. 如果传入 mockText,走本地 parseOcrCardText(供测试/离线模拟)
if (opt.mockText && opt.mockText.trim() !== '') {
const extracted = parseOcrCardText(opt.mockText);
ocrState.rawText = opt.mockText;
@@ -587,7 +686,7 @@ export async function handleCardOcrUpload(
return true;
}
// 2. 调用客户端拍照/选图 API
// 2. 调用客户端拍照/选图 API,成功后请求后端 OCR
return new Promise<boolean>((resolve) => {
try {
const sourceTypes = opt.sourceType != null && opt.sourceType.length > 0
@@ -607,18 +706,32 @@ export async function handleCardOcrUpload(
}
ocrState.imagePath = path !== '' ? path : 'https://cdn.omnicard.ai/mock-card.jpg';
// 图像上传与 OCR 解析
const sample = simulateOcrScan('cn');
ocrState.rawText = sample.rawText;
ocrState.lastExtracted = sample;
fillFormFromOcr(form, sample, overwrite);
ocrState.scanning = false;
void (async () => {
try {
const body = await buildOcrRecognizeBody(ocrState.imagePath);
const apiResult = await postFn('/open/ai/ocr/recognize', body);
const extracted = mapOcrApiResult(apiResult);
ocrState.rawText = extracted.rawText;
ocrState.lastExtracted = extracted;
fillFormFromOcr(form, extracted, overwrite);
ocrState.scanning = false;
ocrState.errorMessage = '';
uni.showToast({
title: '名片识别成功,已自动填入',
icon: 'none',
});
resolve(true);
uni.showToast({
title: '名片识别成功,已自动填入',
icon: 'none',
});
resolve(true);
} catch (err: unknown) {
ocrState.scanning = false;
let msg = '名片识别失败';
if (err instanceof Error && err.message !== '') {
msg = err.message;
}
ocrState.errorMessage = msg;
resolve(false);
}
})();
},
fail: (err: unknown) => {
ocrState.scanning = false;