编辑按钮
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user