Repository navigation
fix: role no permission disbaled check - #7873
Conversation
| const disabled = computed(() => props.currentRole.internal || !perm.system.role.edit()) | ||
| const permissionTableKey = computed(() => `${props.currentRole.id}:${disabled.value ? 'readonly' : 'editable'}`) | ||
|
|
||
| function loadPermissions() { |
There was a problem hiding this comment.
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 wheninternal === 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:
disabledis generic;isReadonlyorisPermissionMatrixDisabledconveys 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 (sodisabledupdates on permission changes). - Consider whether
permissionTableKeyremount is truly needed vs. a prop.
ใใ่ง่ฒใไผๅ-่ง่ฒๆ ใ่ง่ฒ็ฎก็-็ผ่พใๆ้ๆถ๏ผๆ้็ฉ้ตๅค้ๆกๅบไธๅฏ็นๅปๅพ้ใ
https://www.tapd.cn/tapd_fe/45245355/bug/detail/1145245355001079354