From 42608ec5590bdde375c385e987dc9a862c153de1 Mon Sep 17 00:00:00 2001
From: zjk <852185829@qq.com>
Date: 星期五, 24 七月 2026 09:19:14 +0800
Subject: [PATCH] feat: 新增启动页,重构硬件回调与多项业务流程
---
utils/syncEngine.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 53 insertions(+), 1 deletions(-)
diff --git a/utils/syncEngine.js b/utils/syncEngine.js
index 4c02738..e0bf63f 100644
--- a/utils/syncEngine.js
+++ b/utils/syncEngine.js
@@ -24,14 +24,20 @@
* 4. 成功后:将数据库记录置为已同步,并删除本地沙盒图片释放内存
*/
export const startSyncQueue = async () => {
+ console.log('[Sync] startSyncQueue 进入,当前同步状态:', {
+ isSyncing,
+ });
if (isSyncing) {
+ console.warn('[Sync] 同步队列已在执行中,本次跳过');
return;
}
// 简单判断当前网络是否可用
const networkType = await getCurrentNetworkType();
+ console.log('[Sync] 当前网络状态:', networkType);
if (networkType === 'none') {
+ console.warn('[Sync] 当前离线,跳过同步队列');
return;
}
@@ -41,12 +47,22 @@
let pendingRecords = [];
try {
pendingRecords = await getPendingSyncRecords();
+ console.log('[Sync] 读取到待同步记录:', {
+ count: pendingRecords.length,
+ records: pendingRecords.map((record) => ({
+ id: record.id,
+ type: record.type,
+ localImgPath: record.local_img_path,
+ createTime: record.create_time,
+ })),
+ });
} catch (dbErr) {
+ console.error('[Sync] 读取待同步记录失败:', dbErr);
return;
}
if (pendingRecords.length === 0) {
- isSyncing = false;
+ console.warn('[Sync] 当前没有待同步记录');
return;
}
@@ -66,7 +82,18 @@
// 1. 如果存在本地图片,先上传图片,再把云端地址回填到业务 payload
if (record.local_img_path) {
+ console.log('[Sync] 开始上传本地图片:', {
+ recordId: record.id,
+ type: record.type,
+ localImgPath: record.local_img_path,
+ });
const uploadRes = await uploadImage(record.local_img_path);
+ console.log('[Sync] 图片上传结果:', {
+ recordId: record.id,
+ type: record.type,
+ localImgPath: record.local_img_path,
+ uploadRes,
+ });
if (uploadRes && uploadRes.code === 200 && uploadRes.url) {
// 根据记录类型,将云端 URL 赋值给不同的业务 payload 字段
if (record.type === 'signout') {
@@ -101,11 +128,26 @@
try {
let submitRes;
if (item.type === 'signout') {
+ console.log('[Sync] 开始调用签离接口:', {
+ recordId: item.recordId,
+ payload: item.payload,
+ });
submitRes = await idCardSingOut(item.payload);
} else {
// type 为 appointment, online, 或它们加上 _signedout 后缀时,都作为进场记录同步
+ console.log('[Sync] 开始调用登记接口:', {
+ recordId: item.recordId,
+ type: item.type,
+ payload: item.payload,
+ });
submitRes = await addVisitorRecord(item.payload);
}
+
+ console.log('[Sync] 单条业务接口返回:', {
+ recordId: item.recordId,
+ type: item.type,
+ submitRes,
+ });
if (submitRes && submitRes.code === 200) {
await markRecordSynced(item.recordId);
@@ -120,7 +162,12 @@
if (signinDataToPull.length > 0) {
try {
const payloads = signinDataToPull.map(item => item.payload);
+ console.log('[Sync] 开始调用批量补发签到接口:', {
+ count: payloads.length,
+ payloads,
+ });
const pullRes = await pullSigninData(payloads);
+ console.log('[Sync] 批量补发签到接口结果:', pullRes);
if (pullRes && pullRes.code === 200) {
for (let item of signinDataToPull) {
await markRecordSynced(item.recordId);
@@ -136,7 +183,12 @@
if (signoutDataToPull.length > 0) {
try {
const payloads = signoutDataToPull.map(item => item.payload);
+ console.log('[Sync] 开始调用批量补发签离接口:', {
+ count: payloads.length,
+ payloads,
+ });
const pullRes = await pullSignoutData(payloads);
+ console.log('[Sync] 批量补发签离接口结果:', pullRes);
if (pullRes && pullRes.code === 200) {
for (let item of signoutDataToPull) {
await markRecordSynced(item.recordId);
--
Gitblit v1.7.1