瀏覽代碼

feat(home): 优化时间显示,提取时间格式化逻辑,避免日期信息污染

xieyong 4 天之前
父節點
當前提交
781c0c7021
共有 1 個文件被更改,包括 11 次插入3 次删除
  1. 11 3
      src/pages/home/index.vue

+ 11 - 3
src/pages/home/index.vue

@@ -24,12 +24,12 @@
         </view>
         <view class="check-times">
           <view class="time-item"
-            ><text class="time">{{ inText }}</text
+            ><text class="time">{{ extractTime(inText) }}</text
             ><text class="time-label">上班 · {{ inLabel }}</text></view
           >
           <view class="time-line"></view>
           <view class="time-item"
-            ><text class="time" :class="{ muted: !daily.actualOut }">{{ outText }}</text
+            ><text class="time" :class="{ muted: !daily.actualOut }">{{ extractTime(outText) }}</text
             ><text class="time-label">下班 · {{ outLabel }}</text></view
           >
         </view>
@@ -172,9 +172,17 @@ const shiftText = computed(() => {
   const end = daily.scheduledEnd || shiftInfo.endTime;
   if (!start || !end) return "休息日";
   const name = shiftInfo.ruleName || "今日班次";
-  return `${name} · ${start} - ${end}`;
+  return `${name} · ${extractTime(start)} - ${extractTime(end)}`;
 });
 
+// 后端返回的班次时间是 "2026-09-14 09:00:00" / ISO 等带日期的字符串,
+// 这里只展示 HH:MM,避免 2026-09-14 这种信息污染卡片
+function extractTime(value) {
+  if (value == null || value === "") return "";
+  const m = String(value).match(/(\d{1,2}:\d{2})(:\d{2})?/);
+  return m ? m[1] : String(value);
+}
+
 const inText = computed(() => daily.actualIn || "--:--");
 const outText = computed(() => daily.actualOut || "--:--");