From 119fa9cb9475853374c5ae379ad5f9f67e0166ac Mon Sep 17 00:00:00 2001 From: TianyangZhang Date: Fri, 15 May 2026 17:03:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(wf):=20=E5=B7=A5=E5=8D=95=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E5=81=B6=E5=B0=94=E4=B8=8D=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ticketd_b 原先用 setTimeout 1s 后调 init(),挂载瞬间 props.ticket_ 还是 null,1 秒等待无法保证父表单 getTid 已完成且 props 已传到。 init 读到的 props.ticket_ 仍为 falsy 时会错误地走 workflow_key 分支调 init_key,把 transitions 初始化成新建工单的初始 transition, 导致审批人看不到"同意"等操作按钮。 改用 watch props.ticket_ / props.workflow_key 触发 init,并加 lastInitTicketId 去重避免重复调用。 复现:cuishuai 登录 → /ofm/publicity → 点详情 → 看不到"同意"按钮。 影响范围:所有使用 ticketd_b 的审批表单(请假/合同/宣传/维修等)。 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/views/wf/ticketd_b.vue | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/views/wf/ticketd_b.vue b/src/views/wf/ticketd_b.vue index 0078a9de..54f3eaed 100644 --- a/src/views/wf/ticketd_b.vue +++ b/src/views/wf/ticketd_b.vue @@ -34,18 +34,27 @@ const props = defineProps({ const workflow = ref(null); const transitions = ref([]); -onMounted(async () => { - setTimeout(()=>{init()}, 1000) - // watch( - // () => props.ticket_, - // async (newVal) => { - // if (newVal && Object.keys(newVal).length > 0) { - // init(); - // } - // }, - // { deep: true } - // ) -}) +let lastInitTicketId = null; +const tryInit = () => { + // 优先用 ticket_ 分支:等到 ticket_.id 出现再调 + if (props.ticket_ && props.ticket_.id) { + if (lastInitTicketId !== props.ticket_.id) { + lastInitTicketId = props.ticket_.id; + init(); + } + return; + } + // 没有 ticket_,退化到 workflow_key 分支(创建工单场景) + if (props.workflow_key) { + if (lastInitTicketId !== '__wf_key__:' + props.workflow_key) { + lastInitTicketId = '__wf_key__:' + props.workflow_key; + init(); + } + } +}; +onMounted(() => { tryInit(); }); +watch(() => props.ticket_, () => { tryInit(); }, { deep: true }); +watch(() => props.workflow_key, () => { tryInit(); }); const ticketId = ref(null); const actionShow = ref(false);