From 8daec4e1441a8c84e7f097f3c8a86c8eae2a6127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Fri, 3 Jul 2026 14:07:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/src/views/form/form_controller.js | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.js b/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.js index 9be4e165b..20034a041 100644 --- a/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.js +++ b/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.js @@ -39,6 +39,7 @@ patch(FormController.prototype, { }); // 监听resId变化 useEffect(() => { + console.log("[editButtonState] useEffect 触发, resId:", this.model?.root?.resId); this.editButtonState(); }, () => [this.model?.root?.resId]); // end edit @@ -94,37 +95,49 @@ patch(FormController.prototype, { async editButtonState() { this.buttonState.showEditButton = true; try { + console.log("[editButtonState] === 开始检查 ==="); + console.log("[editButtonState] isAdmin (session.is_system):", this.isAdmin); + if (this.isAdmin) { + console.log("[editButtonState] 管理员,直接显示编辑按钮"); this.buttonState.showEditButton = true; return; } + const resModel = this.model.config.resModel || this.model.root.resModel || this.props.resModel; const resId = this.model.config.resId || this.model.root.resId || this.props.resId; const currentUserId = this.env.services.user.userId; + console.log("[editButtonState] resModel:", resModel, "| resId:", resId, "| currentUserId:", currentUserId, "(session.uid:", session.uid, ")"); + if (resModel && resId) { - // 1. 判断 self_users_ids(经办人)— 不依赖 view fields,直接 ORM 读取 - // 因为 self_users_ids 可能不在表单视图里渲染,fields 元数据会缺失 try { const result = await this.orm.read(resModel, [resId], ["self_users_ids", "work_end"]); + console.log("[editButtonState] ORM read 结果:", JSON.stringify(result)); const selfUsers = result[0]?.self_users_ids || []; - // 经办人列表有值时,当前用户不在里面就隐藏编辑按钮 + const workEnd = result[0]?.work_end; + console.log("[editButtonState] self_users_ids:", selfUsers, "| work_end:", workEnd); + console.log("[editButtonState] 当前用户在经办人列表里?", selfUsers.includes(currentUserId)); + if (selfUsers.length > 0 && !selfUsers.includes(currentUserId)) { + console.log("[editButtonState] ❌ 当前用户不是经办人,隐藏编辑按钮"); this.buttonState.showEditButton = false; return; } - // 2. work_end 判断(同一次 ORM 读取,减少请求) - if (result[0]?.work_end === true) { + if (workEnd === true) { + console.log("[editButtonState] ❌ 流程已结束(work_end=true),隐藏编辑按钮"); this.buttonState.showEditButton = false; return; } } catch (e) { - // 模型没有 self_users_ids / work_end 字段,跳过检查,正常显示编辑按钮 + console.log("[editButtonState] ORM read 失败(模型可能没有 self_users_ids/work_end 字段):", e?.message || e); } - // 3. 以上条件都不满足,显示编辑按钮 + console.log("[editButtonState] ✅ 显示编辑按钮"); this.buttonState.showEditButton = true; + } else { + console.log("[editButtonState] resModel 或 resId 为空,跳过检查,显示编辑按钮"); } } catch (error) { - console.error("检查编辑按钮状态:", error); + console.error("[editButtonState] 检查编辑按钮状态出错:", error); this.buttonState.showEditButton = true; } }