refactor(usePagination): 简化分页逻辑,移除冗余导航配置
移除当前页导航配置的中间变量 current_nav,直接在遇到分页符时应用其属性 最后一页若无分页符则使用默认导航配置
Showing
1 changed file
with
5 additions
and
9 deletions
| ... | @@ -67,24 +67,20 @@ export function usePagination(formDataRef, options = {}) { | ... | @@ -67,24 +67,20 @@ export function usePagination(formDataRef, options = {}) { |
| 67 | const pages = [] | 67 | const pages = [] |
| 68 | const navs = [] | 68 | const navs = [] |
| 69 | let cur = [] | 69 | let cur = [] |
| 70 | - // 当前页导航配置,默认值;当遇到 paginator 时更新为“下一页”的导航 | ||
| 71 | - let current_nav = normalizePaginatorProps() | ||
| 72 | // 连续的 paginator 需要忽略,避免出现空分页 | 70 | // 连续的 paginator 需要忽略,避免出现空分页 |
| 73 | let last_was_paginator = false | 71 | let last_was_paginator = false |
| 74 | formDataRef.value.forEach(item => { | 72 | formDataRef.value.forEach(item => { |
| 75 | const tag = item.component_props?.tag | 73 | const tag = item.component_props?.tag |
| 76 | - // 分隔符 paginator 作为分页分组边界,同时决定后续一页的导航配置 | 74 | + // 分隔符 paginator 作为分页分组边界;其属性应用于“当前页”(它所在页的页尾) |
| 77 | if (tag === 'paginator') { | 75 | if (tag === 'paginator') { |
| 78 | // 连续分页符:忽略后者,保留先前设置,避免空页与属性覆盖 | 76 | // 连续分页符:忽略后者,保留先前设置,避免空页与属性覆盖 |
| 79 | if (last_was_paginator) return | 77 | if (last_was_paginator) return |
| 80 | - // 如果当前已有内容,先把“这一页”收束,并使用当前导航配置 | 78 | + // 若当前页有内容,则用此分页符的属性收束为一页 |
| 81 | if (cur.length) { | 79 | if (cur.length) { |
| 82 | pages.push(cur) | 80 | pages.push(cur) |
| 83 | - navs.push(current_nav) | 81 | + navs.push(normalizePaginatorProps(item.component_props)) |
| 84 | cur = [] | 82 | cur = [] |
| 85 | } | 83 | } |
| 86 | - // 更新“下一页”的导航配置为本分页符设置 | ||
| 87 | - current_nav = normalizePaginatorProps(item.component_props) | ||
| 88 | last_was_paginator = true | 84 | last_was_paginator = true |
| 89 | return | 85 | return |
| 90 | } | 86 | } |
| ... | @@ -93,10 +89,10 @@ export function usePagination(formDataRef, options = {}) { | ... | @@ -93,10 +89,10 @@ export function usePagination(formDataRef, options = {}) { |
| 93 | last_was_paginator = false | 89 | last_was_paginator = false |
| 94 | }) | 90 | }) |
| 95 | 91 | ||
| 96 | - // 收尾:最后一页 | 92 | + // 收尾:最后一页(没有尾随 paginator 时使用默认导航) |
| 97 | if (cur.length) { | 93 | if (cur.length) { |
| 98 | pages.push(cur) | 94 | pages.push(cur) |
| 99 | - navs.push(current_nav) | 95 | + navs.push(normalizePaginatorProps()) |
| 100 | } | 96 | } |
| 101 | 97 | ||
| 102 | // 若未显式分页,仅按固定大小分片,并为每一页设置默认导航 | 98 | // 若未显式分页,仅按固定大小分片,并为每一页设置默认导航 | ... | ... |
-
Please register or login to post a comment