增加异常处理
This commit is contained in:
@@ -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; // 出错时默认显示编辑按钮
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user