flat: 支付宝刷脸登录
This commit is contained in:
@@ -101,10 +101,6 @@ export class FaceLoginService {
|
|||||||
this._retryTimer = null;
|
this._retryTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 【新增】生命周期 - 开始
|
|
||||||
* 统一入口,通常在页面加载 (onLoad/onMounted) 时调用
|
|
||||||
*/
|
|
||||||
start(scope = null) {
|
start(scope = null) {
|
||||||
// 启动前先清理可能存在的旧状态
|
// 启动前先清理可能存在的旧状态
|
||||||
this.close();
|
this.close();
|
||||||
@@ -113,10 +109,6 @@ export class FaceLoginService {
|
|||||||
this.init(scope);
|
this.init(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 【新增】生命周期 - 关闭
|
|
||||||
* 统一出口,通常在页面卸载 (onUnload/onUnmounted) 时调用
|
|
||||||
*/
|
|
||||||
close() {
|
close() {
|
||||||
// 1. 清除正在等待执行的重试定时器
|
// 1. 清除正在等待执行的重试定时器
|
||||||
if (this._retryTimer) {
|
if (this._retryTimer) {
|
||||||
@@ -131,10 +123,6 @@ export class FaceLoginService {
|
|||||||
console.log("[FaceLogin] 服务已关闭");
|
console.log("[FaceLogin] 服务已关闭");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 1. 初始化刷脸服务
|
|
||||||
* (已修改:增加了对定时器的管理)
|
|
||||||
*/
|
|
||||||
async init(scope = null, retryCount = 1) {
|
async init(scope = null, retryCount = 1) {
|
||||||
const params = {
|
const params = {
|
||||||
action: "initFace",
|
action: "initFace",
|
||||||
@@ -154,7 +142,6 @@ export class FaceLoginService {
|
|||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[FaceLogin] 初始化失败: ${err.message}`);
|
console.error(`[FaceLogin] 初始化失败: ${err.message}`);
|
||||||
// 如果还有重试次数,且服务没有被手动 close 关闭
|
|
||||||
if (retryCount > 0) {
|
if (retryCount > 0) {
|
||||||
console.log("[FaceLogin] 3秒后尝试重新初始化...");
|
console.log("[FaceLogin] 3秒后尝试重新初始化...");
|
||||||
this._retryTimer = setTimeout(() => {
|
this._retryTimer = setTimeout(() => {
|
||||||
@@ -162,8 +149,7 @@ export class FaceLoginService {
|
|||||||
this.init(scope, retryCount - 1); // 递归重试
|
this.init(scope, retryCount - 1); // 递归重试
|
||||||
}, 3000);
|
}, 3000);
|
||||||
} else {
|
} else {
|
||||||
// 重试耗尽,抛出错误
|
// throw err; // 视业务逻辑决定是否阻断
|
||||||
// throw err; // 可选:视业务逻辑决定是否阻断
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,11 +158,9 @@ export class FaceLoginService {
|
|||||||
* 2. 唤起 1:N 刷脸并获取 AuthCode
|
* 2. 唤起 1:N 刷脸并获取 AuthCode
|
||||||
*/
|
*/
|
||||||
async startFaceLogin() {
|
async startFaceLogin() {
|
||||||
// 防御性编程:确保已初始化
|
|
||||||
if (!this.isInitialized) {
|
if (!this.isInitialized) {
|
||||||
console.warn("[FaceLogin] 服务未初始化,尝试自动补救初始化...");
|
console.warn("[FaceLogin] 服务未初始化,尝试自动补救初始化...");
|
||||||
try {
|
try {
|
||||||
// 尝试一次即时初始化(不重试)
|
|
||||||
await this.init(null, 0);
|
await this.init(null, 0);
|
||||||
if (!this.isInitialized) throw new Error("初始化未完成");
|
if (!this.isInitialized) throw new Error("初始化未完成");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -218,9 +202,6 @@ export class FaceLoginService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 基础 Bridge 调用封装
|
|
||||||
*/
|
|
||||||
_bridgeCall(params) {
|
_bridgeCall(params) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (typeof hh === 'undefined' || !hh.call) {
|
if (typeof hh === 'undefined' || !hh.call) {
|
||||||
|
|||||||
@@ -331,7 +331,16 @@ async function handleFaceLogin() {
|
|||||||
try {
|
try {
|
||||||
const authCode = await faceService.startFaceLogin();
|
const authCode = await faceService.startFaceLogin();
|
||||||
console.log('拿到 AuthCode:', authCode);
|
console.log('拿到 AuthCode:', authCode);
|
||||||
// 调用后端登录接口...
|
$api.createRequest('/app/alipay/scanLogin', authCode, 'POST').then((resData) => {
|
||||||
|
loginSetToken(resData.token).then((resume) => {
|
||||||
|
if (resume.data.jobTitleId) {
|
||||||
|
useUserStore().initSeesionId();
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/index/index',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.$api.msg(err.message);
|
this.$api.msg(err.message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ const needToEncrypt = [
|
|||||||
["post", "/app/user/experience/edit"],
|
["post", "/app/user/experience/edit"],
|
||||||
["post", "/app/user/experience/delete"],
|
["post", "/app/user/experience/delete"],
|
||||||
["get", "/app/user/experience/getSingle/{value}"],
|
["get", "/app/user/experience/getSingle/{value}"],
|
||||||
["get", "/app/user/experience/list"]
|
["get", "/app/user/experience/list"],
|
||||||
|
["post", "/app/alipay/scanLogin"]
|
||||||
]
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,8 +119,8 @@ export function createRequest(url, data = {}, method = 'GET', loading = false, h
|
|||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.request({
|
uni.request({
|
||||||
url: config.baseUrl + '/app/proxy',
|
// url: config.baseUrl + '/app/proxy',
|
||||||
// url: config.baseUrl + url,
|
url: config.baseUrl + url,
|
||||||
method: method,
|
method: method,
|
||||||
data: requestData,
|
data: requestData,
|
||||||
header,
|
header,
|
||||||
|
|||||||
Reference in New Issue
Block a user