flat: 支付宝刷脸登录

This commit is contained in:
Apcallover
2025-12-25 10:52:14 +08:00
parent c0c93fffc4
commit e9674fcb40
3 changed files with 15 additions and 24 deletions

View File

@@ -101,10 +101,6 @@ export class FaceLoginService {
this._retryTimer = null;
}
/**
* 【新增】生命周期 - 开始
* 统一入口,通常在页面加载 (onLoad/onMounted) 时调用
*/
start(scope = null) {
// 启动前先清理可能存在的旧状态
this.close();
@@ -113,10 +109,6 @@ export class FaceLoginService {
this.init(scope);
}
/**
* 【新增】生命周期 - 关闭
* 统一出口,通常在页面卸载 (onUnload/onUnmounted) 时调用
*/
close() {
// 1. 清除正在等待执行的重试定时器
if (this._retryTimer) {
@@ -131,10 +123,6 @@ export class FaceLoginService {
console.log("[FaceLogin] 服务已关闭");
}
/**
* 1. 初始化刷脸服务
* (已修改:增加了对定时器的管理)
*/
async init(scope = null, retryCount = 1) {
const params = {
action: "initFace",
@@ -154,7 +142,6 @@ export class FaceLoginService {
return true;
} catch (err) {
console.error(`[FaceLogin] 初始化失败: ${err.message}`);
// 如果还有重试次数,且服务没有被手动 close 关闭
if (retryCount > 0) {
console.log("[FaceLogin] 3秒后尝试重新初始化...");
this._retryTimer = setTimeout(() => {
@@ -162,8 +149,7 @@ export class FaceLoginService {
this.init(scope, retryCount - 1); // 递归重试
}, 3000);
} else {
// 重试耗尽,抛出错误
// throw err; // 可选:视业务逻辑决定是否阻断
// throw err; // 视业务逻辑决定是否阻断
}
}
}
@@ -172,11 +158,9 @@ export class FaceLoginService {
* 2. 唤起 1:N 刷脸并获取 AuthCode
*/
async startFaceLogin() {
// 防御性编程:确保已初始化
if (!this.isInitialized) {
console.warn("[FaceLogin] 服务未初始化,尝试自动补救初始化...");
try {
// 尝试一次即时初始化(不重试)
await this.init(null, 0);
if (!this.isInitialized) throw new Error("初始化未完成");
} catch (e) {
@@ -218,9 +202,6 @@ export class FaceLoginService {
}
}
/**
* 基础 Bridge 调用封装
*/
_bridgeCall(params) {
return new Promise((resolve, reject) => {
if (typeof hh === 'undefined' || !hh.call) {