refactor: 优化日志输出,仅在调试模式下启用
- 为所有 print 语句添加 kDebugMode 检查 - 更新 KRLogUtil 工具类,Release 模式下禁用日志输出 - 优化 18 个文件中的 335+ 条日志语句 - 提升 Release 版本性能并增强安全性 (cherry picked from commit 301f1510ba81fe94fb08e013ca80b3ca708a2e15)
This commit is contained in:
@@ -10,6 +10,7 @@ import '../../../utils/kr_event_bus.dart';
|
||||
import '../../../utils/kr_common_util.dart';
|
||||
import '../../../localization/app_translations.dart';
|
||||
import '../../../utils/kr_log_util.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// 订单状态控制器(参考 Tauri 项目实现)
|
||||
class KROrderStatusController extends GetxController {
|
||||
@@ -71,12 +72,24 @@ class KROrderStatusController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
print('═══════════════════════════════════════');
|
||||
print('📊 订单状态页面初始化');
|
||||
print(' 订单号: $kr_order');
|
||||
print(' 支付方式: $kr_paymentType');
|
||||
print(' Checkout类型: $kr_checkoutType');
|
||||
print('═══════════════════════════════════════');
|
||||
if (kDebugMode) {
|
||||
print('═══════════════════════════════════════');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print('📊 订单状态页面初始化');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print(' 订单号: $kr_order');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print(' 支付方式: $kr_paymentType');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print(' Checkout类型: $kr_checkoutType');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print('═══════════════════════════════════════');
|
||||
}
|
||||
|
||||
// 立即查询一次订单状态,获取创建时间
|
||||
kr_checkPaymentStatus();
|
||||
@@ -92,7 +105,9 @@ class KROrderStatusController extends GetxController {
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
print('🔚 订单状态页面关闭,清理定时器');
|
||||
if (kDebugMode) {
|
||||
print('🔚 订单状态页面关闭,清理定时器');
|
||||
}
|
||||
kr_timer?.cancel();
|
||||
kr_countdownTimer?.cancel();
|
||||
super.onClose();
|
||||
@@ -100,7 +115,9 @@ class KROrderStatusController extends GetxController {
|
||||
|
||||
/// 开始检查支付状态(参考 Tauri 项目:5秒轮询一次)
|
||||
void kr_startCheckingPaymentStatus() {
|
||||
print('🔄 启动支付状态轮询(每5秒检查一次)');
|
||||
if (kDebugMode) {
|
||||
print('🔄 启动支付状态轮询(每5秒检查一次)');
|
||||
}
|
||||
|
||||
// 状态轮询:每5秒检查一次订单状态
|
||||
kr_timer = Timer.periodic(const Duration(seconds: 5), (timer) {
|
||||
@@ -118,7 +135,9 @@ class KROrderStatusController extends GetxController {
|
||||
if (kr_orderCreatedAt == null) {
|
||||
// 订单创建时间还未获取,显示默认倒计时
|
||||
kr_formattedCountdown.value = '15:00';
|
||||
print('⏱️ 倒计时更新: 等待订单创建时间...');
|
||||
if (kDebugMode) {
|
||||
print('⏱️ 倒计时更新: 等待订单创建时间...');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -128,12 +147,24 @@ class KROrderStatusController extends GetxController {
|
||||
|
||||
final timeLeft = targetTime - now;
|
||||
|
||||
print('⏱️ 倒计时调试信息:');
|
||||
print(' 当前时间(ms): $now');
|
||||
print(' 创建时间(ms): $createdAt');
|
||||
print(' 目标时间(ms): $targetTime');
|
||||
print(' 剩余时间(ms): $timeLeft');
|
||||
print(' 剩余时间(秒): ${(timeLeft / 1000).floor()}');
|
||||
if (kDebugMode) {
|
||||
print('⏱️ 倒计时调试信息:');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print(' 当前时间(ms): $now');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print(' 创建时间(ms): $createdAt');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print(' 目标时间(ms): $targetTime');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print(' 剩余时间(ms): $timeLeft');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print(' 剩余时间(秒): ${(timeLeft / 1000).floor()}');
|
||||
}
|
||||
|
||||
if (timeLeft > 0) {
|
||||
kr_countdown.value = timeLeft;
|
||||
@@ -141,7 +172,9 @@ class KROrderStatusController extends GetxController {
|
||||
final minutes = (timeLeft / 60000).floor();
|
||||
final seconds = ((timeLeft % 60000) / 1000).floor();
|
||||
kr_formattedCountdown.value = '${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';
|
||||
print(' 格式化倒计时: ${kr_formattedCountdown.value}');
|
||||
if (kDebugMode) {
|
||||
print(' 格式化倒计时: ${kr_formattedCountdown.value}');
|
||||
}
|
||||
} else {
|
||||
// 倒计时结束,订单超时
|
||||
kr_countdown.value = 0;
|
||||
@@ -149,7 +182,9 @@ class KROrderStatusController extends GetxController {
|
||||
kr_countdownTimer?.cancel();
|
||||
kr_timer?.cancel();
|
||||
|
||||
print('⏱️ 订单支付超时(15分钟)');
|
||||
if (kDebugMode) {
|
||||
print('⏱️ 订单支付超时(15分钟)');
|
||||
}
|
||||
kr_statusTitle.value = AppTranslations.kr_orderStatus.closedTitle;
|
||||
kr_statusDescription.value = AppTranslations.kr_orderStatus.timeoutMessage;
|
||||
kr_isLoading.value = false;
|
||||
@@ -161,14 +196,18 @@ class KROrderStatusController extends GetxController {
|
||||
final now = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
try {
|
||||
print('🔍 检查订单状态 [${kr_order}]');
|
||||
if (kDebugMode) {
|
||||
print('🔍 检查订单状态 [${kr_order}]');
|
||||
}
|
||||
|
||||
// 使用公开接口查询订单状态
|
||||
final result = await kr_subscribeApi.kr_queryOrderStatus(kr_order);
|
||||
|
||||
result.fold(
|
||||
(error) {
|
||||
print('❌ 查询失败: ${error.msg}');
|
||||
if (kDebugMode) {
|
||||
print('❌ 查询失败: ${error.msg}');
|
||||
}
|
||||
KRLogUtil.kr_e('检查支付状态失败: ${error.msg}', tag: 'OrderStatusController');
|
||||
kr_isLoading.value = false;
|
||||
kr_statusTitle.value = AppTranslations.kr_orderStatus.checkFailedTitle;
|
||||
@@ -186,13 +225,23 @@ class KROrderStatusController extends GetxController {
|
||||
isMilliseconds ? timestamp : timestamp * 1000
|
||||
);
|
||||
|
||||
print('📅 订单创建时间: ${kr_orderCreatedAt}');
|
||||
print('📅 原始时间戳: $timestamp');
|
||||
print('📅 时间戳类型: ${isMilliseconds ? "毫秒级" : "秒级"}');
|
||||
print('📅 转换后时间戳(ms): ${kr_orderCreatedAt!.millisecondsSinceEpoch}');
|
||||
if (kDebugMode) {
|
||||
print('📅 订单创建时间: ${kr_orderCreatedAt}');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print('📅 原始时间戳: $timestamp');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print('📅 时间戳类型: ${isMilliseconds ? "毫秒级" : "秒级"}');
|
||||
}
|
||||
if (kDebugMode) {
|
||||
print('📅 转换后时间戳(ms): ${kr_orderCreatedAt!.millisecondsSinceEpoch}');
|
||||
}
|
||||
}
|
||||
|
||||
print('📊 订单状态: ${kr_orderStatus.kr_status} (${_getStatusName(kr_orderStatus.kr_status)})');
|
||||
if (kDebugMode) {
|
||||
print('📊 订单状态: ${kr_orderStatus.kr_status} (${_getStatusName(kr_orderStatus.kr_status)})');
|
||||
}
|
||||
|
||||
switch (kr_orderStatus.kr_status) {
|
||||
case kr_statusPending:
|
||||
@@ -204,7 +253,9 @@ class KROrderStatusController extends GetxController {
|
||||
|
||||
case kr_statusPaid:
|
||||
// 已支付状态,继续轮询直到完成
|
||||
print('✅ 订单已支付,等待确认...');
|
||||
if (kDebugMode) {
|
||||
print('✅ 订单已支付,等待确认...');
|
||||
}
|
||||
kr_statusTitle.value = AppTranslations.kr_orderStatus.paidTitle;
|
||||
kr_statusDescription.value = AppTranslations.kr_orderStatus.paidDescription;
|
||||
kr_statusIcon.value = 'payment_success';
|
||||
@@ -212,7 +263,9 @@ class KROrderStatusController extends GetxController {
|
||||
|
||||
case kr_statusFinished:
|
||||
// 订单完成
|
||||
print('🎉 订单完成!停止轮询');
|
||||
if (kDebugMode) {
|
||||
print('🎉 订单完成!停止轮询');
|
||||
}
|
||||
kr_isPaymentSuccess.value = true;
|
||||
kr_isLoading.value = false;
|
||||
kr_timer?.cancel();
|
||||
@@ -226,7 +279,9 @@ class KROrderStatusController extends GetxController {
|
||||
|
||||
case kr_statusClose:
|
||||
// 订单已关闭
|
||||
print('❌ 订单已关闭');
|
||||
if (kDebugMode) {
|
||||
print('❌ 订单已关闭');
|
||||
}
|
||||
kr_isLoading.value = false;
|
||||
kr_timer?.cancel();
|
||||
kr_countdownTimer?.cancel();
|
||||
@@ -237,7 +292,9 @@ class KROrderStatusController extends GetxController {
|
||||
|
||||
case kr_statusFailed:
|
||||
// 支付失败
|
||||
print('❌ 支付失败');
|
||||
if (kDebugMode) {
|
||||
print('❌ 支付失败');
|
||||
}
|
||||
kr_isLoading.value = false;
|
||||
kr_timer?.cancel();
|
||||
kr_countdownTimer?.cancel();
|
||||
@@ -248,7 +305,9 @@ class KROrderStatusController extends GetxController {
|
||||
|
||||
default:
|
||||
// 未知状态
|
||||
print('⚠️ 未知状态: ${kr_orderStatus.kr_status}');
|
||||
if (kDebugMode) {
|
||||
print('⚠️ 未知状态: ${kr_orderStatus.kr_status}');
|
||||
}
|
||||
kr_isLoading.value = false;
|
||||
kr_timer?.cancel();
|
||||
kr_countdownTimer?.cancel();
|
||||
@@ -262,7 +321,9 @@ class KROrderStatusController extends GetxController {
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
print('❌ 异常: $error');
|
||||
if (kDebugMode) {
|
||||
print('❌ 异常: $error');
|
||||
}
|
||||
KRLogUtil.kr_e('检查支付状态失败: $error', tag: 'OrderStatusController');
|
||||
kr_isLoading.value = false;
|
||||
kr_statusTitle.value = AppTranslations.kr_orderStatus.checkFailedTitle;
|
||||
|
||||
Reference in New Issue
Block a user