Просмотр исходного кода

fix: CompleteDialog visible watcher不触发 on v-if创建

CompleteDialog使用v-if控制渲染,组件创建时visible已为true,watcher无immediate:true故永不触发。改为{immediate:true,handler}确保组件创建时立即执行预填逻辑。同时将actualWorkHour同步预填移至API调用前,避免异步时序问题。

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
程健 3 недель назад
Родитель
Сommit
79b6bd382b
1 измененных файлов с 27 добавлено и 25 удалено
  1. 27 25
      src/views/devops/software/components/CompleteDialog.vue

+ 27 - 25
src/views/devops/software/components/CompleteDialog.vue

@@ -85,32 +85,34 @@
       }
       }
     },
     },
     watch: {
     watch: {
-      async visible(val) {
-        if (!val || !this.taskId) return
-        // set default completion date to today
-        if (!this.form.completionDate) {
-          const today = new Date()
-          const y = today.getFullYear()
-          const m = String(today.getMonth() + 1).padStart(2, '0')
-          const d = String(today.getDate()).padStart(2, '0')
-          this.form.completionDate = `${y}-${m}-${d}`
-        }
-        // pre-fill actualWorkHour from registered work hours
-        try {
-          const res = await opsEventTaskApi.getWorkHourList(this.taskId)
-          const workHourList = res.data?.list || res.data || []
-          const totalRegisteredHours = workHourList.reduce((sum, row) => sum + (Number(row.actualHour) || 0), 0)
-          if (totalRegisteredHours > 0) {
-            this.form.actualWorkHour = Math.round(totalRegisteredHours * 10) / 10
-            return
+      visible: {
+        immediate: true,
+        async handler(val) {
+          if (!val || !this.taskId) return
+          // set default completion date to today
+          if (!this.form.completionDate) {
+            const today = new Date()
+            const y = today.getFullYear()
+            const m = String(today.getMonth() + 1).padStart(2, '0')
+            const d = String(today.getDate()).padStart(2, '0')
+            this.form.completionDate = `${y}-${m}-${d}`
+          }
+          // pre-fill actualWorkHour from taskData first (synchronous, guarantees the row value is used)
+          if (this.taskData && this.taskData.actualWorkHour != null) {
+            this.form.actualWorkHour = Number(this.taskData.actualWorkHour)
+          }
+          // then try to get more accurate registered work hours as enhancement
+          try {
+            const res = await opsEventTaskApi.getWorkHourList(this.taskId)
+            const workHourList = res.data?.list || res.data || []
+            const totalRegisteredHours = workHourList.reduce((sum, row) => sum + (Number(row.actualHour) || 0), 0)
+            if (totalRegisteredHours > 0) {
+              this.form.actualWorkHour = Math.round(totalRegisteredHours * 10) / 10
+            }
+          } catch (e) {
+            // keep the taskData value
           }
           }
-        } catch (e) {
-          // fallback to taskData if query fails
-        }
-        // fallback: use taskData.actualWorkHour
-        if (this.taskData && this.taskData.actualWorkHour != null) {
-          this.form.actualWorkHour = this.taskData.actualWorkHour
-        }
+        },
       },
       },
     },
     },
     methods: {
     methods: {