fix(wf): 工单审批按钮偶尔不渲染

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) <noreply@anthropic.com>
This commit is contained in:
TianyangZhang 2026-05-15 17:03:30 +08:00
parent a9c3903864
commit 119fa9cb94
1 changed files with 21 additions and 12 deletions

View File

@ -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);