Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const props = defineProps<{ currentRole: RoleItem }>()
const loading = ref(false)
const permissionData = ref<PermissionTableRow[]>([])
const showCategory = ref(true)
const disabled = computed(() => props.currentRole.internal)
// 内置角色或当前用户无角色编辑权限时,权限矩阵只读。
const disabled = computed(() => props.currentRole.internal || !perm.system.role.edit())
const permissionTableKey = computed(() => `${props.currentRole.id}:${disabled.value ? 'readonly' : 'editable'}`)

function loadPermissions() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

1. perm.system.role.edit() called inside a computed

const disabled = computed(() => props.currentRole.internal || !perm.system.role.edit())

Issues:

  • If perm.system.role.edit() is a function returning a plain boolean (not reading reactive state), this is fine — but the ! negation combined with short-circuit means it's only evaluated when internal === false. Not a bug, just noted.
  • If perm.system.role.edit() internally reads reactive state, the computed will track it correctly. ✔ Good.

Potential concern: If perm.system.role.edit() reads from a store/composable that may not be initialized yet at setup time, and the permission resolves asynchronously later, make sure the underlying source is reactive so the computed re-evaluates. If permissions are fetched via an async call into a non-reactive variable, disabled will be stale.

2. permissionTableKey tied to disabled

const permissionTableKey = computed(() => `${props.currentRole.id}:${disabled.value ? 'readonly' : 'editable'}`)

This forces a remount of the table whenever disabled flips — reasonable if the child really needs remount (e.g., different internal state), but if the only difference is read-only behavior, a plain prop would suffice and avoid a full teardown/re-render cost. Optimization suggestion: prefer passing disabled down as a prop unless there's a concrete reason for a key-based reset.

3. showCategory declared but unused in diff

const showCategory = ref(true) — verify it's still used elsewhere; otherwise dead code.

4. Minor style / consistency

  • Inline Chinese comment is helpful but mixing languages in one file may violate team convention — confirm it matches the rest of the file.
  • Naming: disabled is generic; isReadonly or isPermissionMatrixDisabled conveys intent better.

5. Logic check

For a built-in role (internal === true), the second operand isn't evaluated — good for performance and avoids unnecessary permission-store access. For non-internal roles, edit permission is required to allow editing — matches the comment. ✔

Summary

  • No functional bugs in the snippet.
  • Main thing to verify: perm.system.role.edit() reads reactive state (so disabled updates on permission changes).
  • Consider whether permissionTableKey remount is truly needed vs. a prop.

Expand Down
Loading