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 be7d59054..9be4e165b 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 @@ -93,41 +93,39 @@ patch(FormController.prototype, { // } async editButtonState() { this.buttonState.showEditButton = true; - // return; try { if (this.isAdmin) { this.buttonState.showEditButton = true; return; } - const fields = this.model.config.fields || this.model.root.model.config.fields || this.props.fields; 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; if (resModel && resId) { - // 1. 判断是否存在 self_users_ids(经办人)字段 - if (fields.self_users_ids) { - const result = await this.orm.read(resModel, [resId], ["self_users_ids"]); + // 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"]); const selfUsers = result[0]?.self_users_ids || []; - if (!selfUsers.includes(currentUserId)) { - this.buttonState.showEditButton = false; - return; // 如果不是经办人,直接返回 - } - } - // 2. 判断 work_end 字段是否存在,且是否为 true - if (fields.work_end) { - const result = await this.orm.read(resModel, [resId], ["work_end"]); - const record = result[0]; - if (record && record.work_end === true) { + // 经办人列表有值时,当前用户不在里面就隐藏编辑按钮 + if (selfUsers.length > 0 && !selfUsers.includes(currentUserId)) { this.buttonState.showEditButton = false; return; } + // 2. work_end 判断(同一次 ORM 读取,减少请求) + if (result[0]?.work_end === true) { + this.buttonState.showEditButton = false; + return; + } + } catch (e) { + // 模型没有 self_users_ids / work_end 字段,跳过检查,正常显示编辑按钮 } - // 3. 如果以上条件都不满足,则显示编辑按钮 + // 3. 以上条件都不满足,显示编辑按钮 this.buttonState.showEditButton = true; } } catch (error) { console.error("检查编辑按钮状态:", error); - this.buttonState.showEditButton = true; // 出错时默认显示编辑按钮 + this.buttonState.showEditButton = true; } } }) \ No newline at end of file