ソースを参照

fix: 报告进度

刘秀芳 3 時間 前
親
コミット
daf5674067

+ 80 - 13
src/views/old_mini/agri_file/pages/diagnosisReport.vue

@@ -5,13 +5,22 @@
         element-loading-background="rgba(15, 15, 15, 0.55)"
     >
         <div v-if="reportGenerating" class="report-progress">
-            <el-progress
-                :percentage="progressPercent"
-                :stroke-width="15"
-                status="warning"
-                striped
-                striped-flow
-            />
+            <div class="report-progress__content">
+                <div>
+                    <el-progress
+                        :percentage="progressPercent"
+                        :stroke-width="15"
+                        :duration="30"
+                        status="warning"
+                        striped
+                        striped-flow
+                    />
+                </div>
+                <div class="report-progress__desc">
+                    依据您的定位和作物品类,
+                    <div>正在生成专属报告,预计耗时2分钟...</div>
+            </div>
+            </div>
         </div>
         <template v-else>
         <div class="diagnosis-header">
@@ -142,6 +151,10 @@ const router = useRouter();
 const REPORT_POLL_INTERVAL = 6000;
 /** exists=0 时进度条走满的模拟时长 */
 const PROGRESS_DURATION_MS = 2 * 60 * 1000;
+/** 进度只记这一次;切页回来从上次百分比接着走 */
+const PROGRESS_STORAGE_KEY = "DIAGNOSIS_REPORT_PROGRESS";
+const PROGRESS_MIN = 10;
+const PROGRESS_CAP = 99;
 /** 无农场时默认作物编码:水稻 */
 const NO_FARM_CROP = "PAD";
 /** 无定位时的默认点位(与录入页一致) */
@@ -178,7 +191,7 @@ const reportTabs = [
 // ---------------------------------------------------------------------------
 const loading = ref(false); // 接口尚未返回:只转圈,不带文字
 const reportGenerating = ref(false); // exists=0:模拟进度条,并继续轮询
-const progressPercent = ref(0);
+const progressPercent = ref(10);
 const varietyList = ref([]);
 const activeVarietyId = ref(null);
 const headerDesc = ref("");
@@ -437,15 +450,51 @@ function stopProgressTimer() {
     }
 }
 
-/** exists=0 才走进度条;两分钟内匀速走到 99,返回前一直停在进度条上 */
+function readProgressCache() {
+    try {
+        const raw = JSON.parse(localStorage.getItem(PROGRESS_STORAGE_KEY) || "null");
+        const percent = Number(raw?.percent ?? raw);
+        if (!Number.isFinite(percent)) return null;
+        return Math.min(PROGRESS_CAP, Math.max(PROGRESS_MIN, Math.floor(percent)));
+    } catch {
+        return null;
+    }
+}
+
+function writeProgressCache(percent) {
+    const value = Math.min(PROGRESS_CAP, Math.max(PROGRESS_MIN, Math.floor(percent)));
+    localStorage.setItem(PROGRESS_STORAGE_KEY, JSON.stringify({ percent: value }));
+}
+
+function clearProgressCache() {
+    localStorage.removeItem(PROGRESS_STORAGE_KEY);
+}
+
+/** 切页时记下当前进度,回来不要从头走 */
+function saveProgressSnapshot() {
+    if (!reportGenerating.value) return;
+    writeProgressCache(progressPercent.value || PROGRESS_MIN);
+}
+
+/** exists=0 才走进度条;从 10% 或已记下的进度接着走到 99 */
 function beginProgress() {
     reportGenerating.value = true;
     if (progressTimer) return;
+    const startPercent = readProgressCache() ?? PROGRESS_MIN;
+    progressPercent.value = startPercent;
+    writeProgressCache(startPercent);
+    const span = PROGRESS_CAP - startPercent;
+    const remainMs = ((PROGRESS_CAP - PROGRESS_MIN) > 0
+        ? span / (PROGRESS_CAP - PROGRESS_MIN)
+        : 0) * PROGRESS_DURATION_MS;
+    if (remainMs <= 0) return;
     const startedAt = Date.now();
-    progressPercent.value = 0;
     progressTimer = setInterval(() => {
-        const ratio = Math.min((Date.now() - startedAt) / PROGRESS_DURATION_MS, 1);
-        progressPercent.value = Math.min(99, Math.floor(ratio * 99));
+        const ratio = Math.min((Date.now() - startedAt) / remainMs, 1);
+        const next = Math.min(PROGRESS_CAP, Math.floor(startPercent + span * ratio));
+        progressPercent.value = next;
+        writeProgressCache(next);
+        if (ratio >= 1) stopProgressTimer();
     }, 200);
 }
 
@@ -455,6 +504,7 @@ async function revealReport(report, farm, token) {
     stopReportPolling();
     const showComplete = reportGenerating.value;
     stopProgressTimer();
+    clearProgressCache();
     if (!showComplete) {
         reportGenerating.value = false;
         applyReportData(report || {}, farm);
@@ -597,9 +647,9 @@ async function fetchDiagnosisReport() {
     viewToken += 1;
     const token = viewToken;
     stopReportPolling();
+    saveProgressSnapshot();
     stopProgressTimer();
     reportGenerating.value = false;
-    progressPercent.value = 0;
     loading.value = true;
 
     if (!hasFarmZone(farm)) {
@@ -656,12 +706,14 @@ onActivated(() => {
 
 onDeactivated(() => {
     viewToken += 1;
+    saveProgressSnapshot();
     stopReportPolling();
     stopProgressTimer();
 });
 
 onBeforeUnmount(() => {
     viewToken += 1;
+    saveProgressSnapshot();
     stopReportPolling();
     stopProgressTimer();
 });
@@ -700,9 +752,24 @@ onBeforeUnmount(() => {
         }
 
         :deep(.el-progress__text) {
+            display: none;
             color: #ffd489;
         }
     }
+    .report-progress__content {
+        width: 100%;
+    }
+    .report-progress__desc {
+        margin-top: 16px;
+        font-size: 16px;
+        line-height: 20px;
+        color: #A8A094;
+        gap: 4px;
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        justify-content: center;
+    }
 
     .diagnosis-header {
         padding: 42px 14px 8px;

+ 5 - 5
src/views/old_mini/work_detail/index.vue

@@ -41,13 +41,13 @@
                             <div class="status-card__sub">为您匹配最佳农事方案</div>
                         </div>
                     </div>
-                    <div class="status-card__right">
+                    <!-- <div class="status-card__right">
                         <div class="status-card__remain-label">剩余</div>
                         <div class="status-card__remain-value">
                             <span class="num">{{ remainingDays }}</span>
                             <span class="unit">天</span>
                         </div>
-                    </div>
+                    </div> -->
                 </div>
 
                 <!-- 异常类:发现异常后机动执行 -->
@@ -76,13 +76,13 @@
                         </span>
                         <span class="status-card__text">{{ displayStatusText }}</span>
                     </div>
-                    <div class="status-card__right">
+                    <!-- <div class="status-card__right">
                         <div class="status-card__remain-label">剩余</div>
                         <div class="status-card__remain-value">
                             <span class="num">{{ remainingDays }}</span>
                             <span class="unit">天</span>
                         </div>
-                    </div>
+                    </div> -->
                 </div>
             </div>
 
@@ -802,7 +802,7 @@ const handleViewArea = () => {
 
 const goGrowthTrack = () => {
     router.push({
-        path: "/growth_track",
+        path: "/abnormal_track",
         query: {
             id: farmData.value?.id || workId.value || route.query.id,
             type: farmData.value?.type || "growth",