From 04ec5dde0401a141c2a4e4a05f57751e47309b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E6=9C=AA=E5=A4=AE?= <2996985766@qq.com> Date: Thu, 17 Jul 2025 14:54:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/src/views/form/form_controller.js | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 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 cb5f7e5c7..0814ec248 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 @@ -26,11 +26,11 @@ patch(FormController.prototype, { showEditButton: true, }) onMounted(() => { - this.etitButtonState(); + this.editButtonState(); }) // 监听resId变化 useEffect(() => { - this.etitButtonState(); + this.editButtonState(); }, () => [this.model?.root?.resId]); // end edit originalSetup.call(this); @@ -65,7 +65,7 @@ patch(FormController.prototype, { // } } // 判断按钮状态 - this.etitButtonState(); + this.editButtonState(); // } else { // this.model.actionService.doAction({ type: 'ir.actions.act_window_close' }); // } @@ -98,32 +98,37 @@ patch(FormController.prototype, { // } // return true; // } - async etitButtonState() { - const fields = this.model.config.fields || this.props.fields; - const resModel = this.model.config.resModel || this.props.resModel; - const resId = this.model.config.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"]); - const selfUsers = result[0]?.self_users_ids || []; - if (!selfUsers.includes(currentUserId)) { - this.buttonState.showEditButton = false; - return; // 如果不是经办人,直接返回 + async editButtonState() { + try { + const fields = this.model.config.fields || this.props.fields; + const resModel = this.model.config.resModel || this.props.resModel; + const resId = this.model.config.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"]); + 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) { - 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) { + this.buttonState.showEditButton = false; + return; + } } + // 3. 如果以上条件都不满足,则显示编辑按钮 + this.buttonState.showEditButton = true; } - // 3. 如果以上条件都不满足,则显示编辑按钮 - this.buttonState.showEditButton = true; + } catch (error) { + console.error("检查编辑按钮状态:", error); + this.buttonState.showEditButton = true; // 出错时默认显示编辑按钮 } } }) \ No newline at end of file