fix: crossDomain 重复收集 — 真实树中的 system_mgmt/crossDomain 与虚拟 global_privileges 冲突,从真实树中移除 crossDomain 避免双重收集

This commit is contained in:
yueli
2026-07-17 16:22:59 +08:00
parent 0e6294890c
commit 29de22b575
2 changed files with 13 additions and 18 deletions

View File

@ -152,9 +152,6 @@ class PermissionService:
) )
).all() ).all()
crossDomain_deleted = any(p.target_code == 'crossDomain' for p in old_perms)
print(f"[权限保存] company_name={repr(company_name)} role={role_code}")
print(f"[权限保存] 删除旧权限 {len(old_perms)} 条, crossDomain 在其中: {crossDomain_deleted}")
for p in old_perms: for p in old_perms:
db.session.delete(p) db.session.delete(p)
@ -183,16 +180,8 @@ class PermissionService:
if new_records: if new_records:
session.add_all(new_records) session.add_all(new_records)
crossDomain_inserted = 'crossDomain' in (permissions or [])
print(f"[权限保存] 新权限 {len(permissions or [])} 条, crossDomain 在提交列表中: {crossDomain_inserted}")
# 4. 提交 # 4. 提交
session.commit() session.commit()
# 验证:提交后 crossDomain 是否还在
after = SysRolePermission.query.filter_by(
role_code=role_code, target_code='crossDomain'
).first()
print(f"[权限保存] 提交后 crossDomain 仍在: {after is not None} (company_name={repr(after.company_name) if after else 'N/A'})")
return True return True
except SQLAlchemyError as e: except SQLAlchemyError as e:

View File

@ -256,8 +256,19 @@ const fetchTree = async () => {
] ]
}; };
// 将虚拟节点放在最前面,然后交给 transformData 处理 // 将虚拟节点放在最前面,然后交给 transformData 处理
const rawData = [globalNode, ...(res.data || [])]; // ★ 从真实树中移除 crossDomain已由虚拟节点 global_privileges 统一管理,避免重复)
const stripCrossDomain = (nodes: any[]) => {
nodes.forEach(node => {
if (node.children) {
node.children = node.children.filter((c: any) => c.code !== 'crossDomain')
stripCrossDomain(node.children)
}
})
}
const realData = res.data || []
stripCrossDomain(realData)
const rawData = [globalNode, ...realData];
rawTreeData.value = rawData; rawTreeData.value = rawData;
tableData.value = transformData(rawData); tableData.value = transformData(rawData);
} }
@ -468,13 +479,8 @@ const handleSave = async () => {
// 2. 操作权限 (crossDomain 不依赖页面可读) // 2. 操作权限 (crossDomain 不依赖页面可读)
if (row.hasWrite && row.operationCode) { if (row.hasWrite && row.operationCode) {
if (row.operationCode === 'crossDomain' || row.hasRead) { if (row.operationCode === 'crossDomain' || row.hasRead) {
if (row.operationCode === 'crossDomain') {
console.log('[DEBUG crossDomain] hasWrite=true, 将被加入提交列表. row.code=', row.code)
}
permissions.push(row.operationCode) permissions.push(row.operationCode)
} }
} else if (row.operationCode === 'crossDomain') {
console.log('[DEBUG crossDomain] hasWrite=', row.hasWrite, ', hasRead=', row.hasRead, ', 不会被加入提交列表')
} }
// 3. 字段权限 (只有当页面可读时才有效) // 3. 字段权限 (只有当页面可读时才有效)