diff --git a/ln_jq_app/lib/pages/b_page/reservation/controller.dart b/ln_jq_app/lib/pages/b_page/reservation/controller.dart index 6bc7718..0b58aab 100644 --- a/ln_jq_app/lib/pages/b_page/reservation/controller.dart +++ b/ln_jq_app/lib/pages/b_page/reservation/controller.dart @@ -66,8 +66,8 @@ class ReservationController extends GetxController with BaseControllerMixin { // 先停止已存在的定时器,防止重复启动 stopAutoRefresh(); - // 创建一个每1分钟执行一次的周期性定时器 - _refreshTimer = Timer.periodic(const Duration(minutes: 1), (timer) { + // 创建一个每5分钟执行一次的周期性定时器 + _refreshTimer = Timer.periodic(const Duration(minutes: 5), (timer) { renderData(); }); } @@ -124,28 +124,52 @@ class ReservationController extends GetxController with BaseControllerMixin { hydStatusStr = "暂停营业"; } - jobDetailsStr = "当前站点已设置$beginTime-$endTime为$hydStatusStr状态"; + //现在的时间晚于开始时间就不显示文案 + bool isJobStarted = false; + try { + if (beginTime.isNotEmpty) { + DateTime beginDateTime = DateTime.parse(beginTime); + if (DateTime.now().isAfter(beginDateTime)) { + isJobStarted = true; + } + } + } catch (e) { + print("开始时间解析失败: $e"); + } + if (isJobStarted) { + jobTipStr = ""; + } + //结束时间 if (endTime.isNotEmpty) { try { // 解析时间字符串 DateTime endDateTime = DateTime.parse(endTime); DateTime beginDateTime = DateTime.parse(beginTime); - DateTime now = DateTime.now(); // 2. 计算时间差 (endTime - now) + DateTime now = DateTime.now(); //计算时间差 (endTime - now) Duration diff = endDateTime.difference(now); // 计算小时数 (允许小数,例如 0.5) // inMinutes / 60 可以得到更精确的小数小时 double hoursLeft = diff.inMinutes / 60.0; - if (hoursLeft > 0) { + //计算当前时间-开始时间 + Duration startDiff = beginDateTime.difference(now); + double hoursUntilStart = startDiff.inMinutes / 60.0; + + + // 只有在【当前时间早于开始时间】且【剩余时间大于0】时才显示文案 + if (now.isBefore(beginDateTime) && hoursLeft > 0) { // 如果是正数,表示还有多久结束 - String timeTip = " ${hoursLeft.toStringAsFixed(1)}小时后"; + String timeTip = " ${hoursUntilStart.toStringAsFixed(1)}小时后"; jobTipStr = "$timeTip$hydStatusStr"; } else { jobTipStr = ""; } + jobDetailsStr = + "当前站点已设置$beginTime至$endTime,共${hoursLeft.toStringAsFixed(2)}小时,为$hydStatusStr状态"; + // 如果是处于非营运状态,自动回填开始和结束时间 // 假设 customStartTime 是现在,customEndTime 是接口返回的结束时间 customStartTime = beginDateTime; diff --git a/ln_jq_app/lib/pages/b_page/reservation/view.dart b/ln_jq_app/lib/pages/b_page/reservation/view.dart index 22f459c..aedac93 100644 --- a/ln_jq_app/lib/pages/b_page/reservation/view.dart +++ b/ln_jq_app/lib/pages/b_page/reservation/view.dart @@ -198,7 +198,7 @@ class ReservationPage extends GetView { style: TextStyle(color: Colors.yellow[800], fontSize: 14), ), SizedBox(width: 2.w), - Icon(AntdIcon.question_circle, size: 14, color: Colors.yellow[800]), + Icon(AntdIcon.info_circle, size: 14, color: Colors.yellow[800]), ], ), ),