Repository navigation
fix: system role member list display - #8287
Conversation
| :span-method="objectSpanMethod" | ||
| @current-change="loadMembers()" | ||
| @size-change="loadMembers()" | ||
| :max-table-height="290" |
There was a problem hiding this comment.
Review of the diff
Correctness / potential issues
-
column.type === 'selection'assumption is fragile. Withspan-method, Element Plus still renders one selection checkbox per row, but merged rows get[0, 0], so hidden checkboxes disappear. The header "select all" and the internal selection state then no longer map 1:1 to visible checkboxes. Verify thatselection-group-key="user_id"+ span merging yields the intended UX (e.g., selecting a merged row selects only the first visually rendered row). Relying oncolumn.type === 'selection'instead ofcolumn.propertyis correct for the checkbox column, but confirm it stays stable across Element Plus versions. -
Merge requires contiguous, sorted records.
objectSpanMethodmerges only consecutive rows with the sameuser_id. If the backend returns users interleaved (e.g., by role), you'll get multiple fragments per user and unstable spans. Ensure data ordering guarantees grouping, or sort client-side before rendering (but beware sorting interacts with server pagination). -
Pagination breaks the merge. Merging is computed from
members.valueonly, so a user spanning a page boundary will render as separate groups on each page. Acceptable, but worth documenting. -
Whole-table scan is O(n²) in the worst case. For every non-merged row the
whileloop re-scans forward. On large lists, this is repeated work. A single precomputed pass is cheaper:const spanMap = computed(() => { const m = new Map<number, [number, number]>() const rows = members.value for (let i = 0; i < rows.length; ) { let j = i + 1 while (j < rows.length && rows[j].user_id === rows[i].user_id) j++ m.set(i, [j - i, 1]) for (let k = i + 1; k < j; k++) m.set(k, [0, 0]) i = j } return m })
Then lookup by
rowIndexinobjectSpanMethod. Note: if you memoize, key it offmembersreactively (the computed does that) rather than calling inside the render function each time. -
Reactivity inside
span-method. Readingmembers.valueinside a render-time callback is fine since it's reactive, but the method is invoked frequently during table layout. The precomputed map above avoids repeated array access. -
row.user_idmay be undefined/null. Ifuser_idis missing,undefined === undefinedmerges all such rows together incorrectly. Add a guard:if (userId == null) return
-
Signature duplication. The inline parameter type duplicates
TableColumnCtx<RoleMember>details; consider using the exported helper type forspan-methodparams (orTableSpanMethod) to avoid drift.
Style / minor
- Lines exceed typical line length (the
shouldMergeexpression). Consider wrapping. - Comment is in Chinese while the request asked for English review — just noting consistency, not a bug.
while (...) rowspan += 1could use braces for readability.
Summary
Logic is basically sound for contiguous, non-paginated groups. Main risks: interleaved/unordered data, pagination splits, null user_id, and the check-all semantics of merged selection columns. Recommend replacing the per-row forward scan with a precomputed span map and adding guards.
【【角色管理】角色成员列表中,同一个成员的不同记录没有合并显示】
https://www.tapd.cn/tapd_fe/45245355/bug/detail/1145245355001081034