From 45dbacb0bffd1a3f61ceb57602e48ce302594fd4 Mon Sep 17 00:00:00 2001 From: guanyu Date: Tue, 19 May 2026 09:05:09 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#548:=20isInitializing=20=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E8=B5=8B=E5=80=BC=E4=BD=86=20Vue=20watcher=20?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E6=89=A7=E8=A1=8C=E5=AF=BC=E8=87=B4=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E5=A4=B1=E6=95=88=20=E2=80=94=20transferValue=20?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E5=90=8E=E5=8A=A0=20await=20nextTick()=20?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=20watcher=20=E5=9C=A8=E6=A0=87=E5=BF=97?= =?UTF-8?q?=E4=B8=BA=20true=20=E6=97=B6=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- BUG548_ANALYSIS.md | 27 +++++++++++++++++++ .../order/applicationForm/laboratoryTests.vue | 9 ++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/BUG548_ANALYSIS.md b/BUG548_ANALYSIS.md index 0173115b..6dbeb40c 100644 --- a/BUG548_ANALYSIS.md +++ b/BUG548_ANALYSIS.md @@ -33,3 +33,30 @@ 2. `transferValue` 的 watch 增加 `if (isInitializing.value) return;` 拦截 3. `applyEditTransferSelection()` 中设置 `transferValue` 前后加 `isInitializing` 标志 4. `applicationListAll` 的 watch 中设置 `transferValue` 前后也加 `isInitializing` 标志 + +## 二次修复(isInitializing 时序问题) + +### 二次根因 + +Vue 的 `watch()` 回调默认是**异步刷新**的(在下一个 microtask 执行)。前一轮修复使用了同步模式: + +```js +isInitializing.value = true +transferValue.value = uniq // watcher 被排队,尚未执行 +isInitializing.value = false // 在 watcher 回调执行前已重置 +// → watcher 触发时 isInitializing 已为 false → 拦截失效 +``` + +导致 `projectWithDepartment(newValue, 1)` 仍然被调用,`form.targetDepartment = ''` 仍然清空了 descJson 中的科室值。 + +### 修复方案 + +在 `applyEditTransferSelection` 和 `applicationListAll` watch 中,设置 `transferValue` 后使用 `await nextTick()` 确保 Vue 的 watcher 在 `isInitializing` 为 `true` 的状态下执行完毕,然后再重置为 `false`。 + +### 修复结果:✅ 成功,5行改动 + +**改动文件**: `openhis-ui-vue3/src/views/inpatientDoctor/home/components/order/applicationForm/laboratoryTests.vue` + +1. import 增加 `nextTick` +2. `applyEditTransferSelection` 改为 `async` 函数,`transferValue` 赋值后加 `await nextTick()` +3. `applicationListAll` 的 watch 回调改为 `async`,`transferValue` 赋值后加 `await nextTick()` diff --git a/openhis-ui-vue3/src/views/inpatientDoctor/home/components/order/applicationForm/laboratoryTests.vue b/openhis-ui-vue3/src/views/inpatientDoctor/home/components/order/applicationForm/laboratoryTests.vue index 6c8fe53c..a30ead08 100755 --- a/openhis-ui-vue3/src/views/inpatientDoctor/home/components/order/applicationForm/laboratoryTests.vue +++ b/openhis-ui-vue3/src/views/inpatientDoctor/home/components/order/applicationForm/laboratoryTests.vue @@ -134,7 +134,7 @@