Fix Bug #548: isInitializing 同步赋值但 Vue watcher 异步执行导致拦截失效 — transferValue 赋值后加 await nextTick() 确保 watcher 在标志为 true 时执行

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 09:05:09 +08:00
parent d4f67a994a
commit 45dbacb0bf
2 changed files with 33 additions and 3 deletions

View File

@@ -134,7 +134,7 @@
</div>
</template>
<script setup name="LaboratoryTests">
import {getCurrentInstance, onMounted, reactive, ref, watch, computed} from 'vue';
import {getCurrentInstance, nextTick, onMounted, reactive, ref, watch, computed} from 'vue';
import {patientInfo} from '../../../store/patient.js';
import {getApplicationList, saveInspection} from './api';
import {getOrgList} from '@/views/doctorstation/components/api.js';
@@ -349,7 +349,7 @@ watch(
);
/** 编辑弹窗:根据申请单明细把右侧「已选择」与 transferValue 对齐(依赖 applicationListAll 已加载) */
const applyEditTransferSelection = () => {
const applyEditTransferSelection = async () => {
const newData = props.editData
if (!newData?.requestFormId || !newData.requestFormDetailList?.length) {
return
@@ -383,6 +383,8 @@ const applyEditTransferSelection = () => {
// 设置初始化标志,防止 transferValue 变化触发 projectWithDepartment 覆盖 descJson 中的科室值
isInitializing.value = true
transferValue.value = uniq
// Vue watcher 默认异步刷新,必须 await nextTick 确保 watcher 在 isInitializing 为 true 时执行
await nextTick()
isInitializing.value = false
if (newData.requestFormDetailList.length && uniq.length === 0) {
console.warn(
@@ -419,7 +421,7 @@ watch(
// 编辑模式下applicationListAll 加载完成后重新回显已选项目
watch(
() => applicationListAll.value,
() => {
async () => {
if (!props.editData?.requestFormId) return;
if (!props.editData.requestFormDetailList?.length) return;
if (!applicationListAll.value.length) return;
@@ -435,6 +437,7 @@ watch(
});
isInitializing.value = true;
transferValue.value = selectedIds;
await nextTick();
isInitializing.value = false;
}
);