Jelajahi Sumber

feat:添加默认值

lxf 2 minggu lalu
induk
melakukan
a6d7fdb389
1 mengubah file dengan 21 tambahan dan 6 penghapusan
  1. 21 6
      src/views/old_mini/recordDetails/index.vue

+ 21 - 6
src/views/old_mini/recordDetails/index.vue

@@ -186,7 +186,7 @@ import customHeader from "@/components/customHeader.vue";
 import PhenologyTrackTimelineItem from "@/components/pageComponents/PhenologyTrackTimelineItem.vue";
 import GrowthStageTimeline from "@/components/pageComponents/GrowthStageTimeline.vue";
 import UploadProgressPopup from "@/components/popup/UploadProgressPopup.vue";
-import { ref, onMounted } from 'vue';
+import { ref, onMounted, watch } from 'vue';
 import { useRouter, useRoute } from 'vue-router';
 import { Uploader, TextEllipsis } from "vant";
 import { ElMessage } from "element-plus";
@@ -301,12 +301,10 @@ const beforeReadUpload = (file) => {
     return true;
 };
 
-const curStage = ref({})
+const curStage = ref({});
+
 function onStageScrollSettled(index, stage) {
-    console.log('index',index)
-    console.log('stage',stage)
-    curStage.value = stage
-  // index:当前节点下标;stage:当前项(含 label、tags、periodTitle 等)
+    if (stage) curStage.value = stage;
 }
 
 const hanldeSubmit = () =>{
@@ -426,6 +424,23 @@ const growthStages = ref([
     },
 ]);
 
+/** 与 GrowthStageTimeline 默认档一致:未绑 v-model 时用中间索引 */
+function syncCurStageFromModel() {
+    const stages = growthStages.value;
+    if (!Array.isArray(stages) || !stages.length) return;
+    const n = stages.length;
+    let i = growthStageIndex.value;
+    if (i === undefined || i === null) {
+        i = Math.max(0, Math.floor((n - 1) / 2));
+    } else {
+        i = Math.min(Math.max(0, i), n - 1);
+    }
+    const stage = stages[i];
+    if (stage) curStage.value = stage;
+}
+
+watch([growthStages, growthStageIndex], syncCurStageFromModel, { immediate: true });
+
 onMounted(() => {
     getWorkDetail();
     getFarmRecord()