fix(ui): 待办分页按实际行高装箱,不再裁掉最底行

徽标卡更高时,按固定卡高估出来的页容量会多塞一行,
最底一张被视口裁掉(入库 3行4列 最明显)。改为按每页
实际行高装箱:矮卡页多放、高卡页少放,每页都完整。
This commit is contained in:
雨天
2026-11-25 18:30:59 +08:00
parent e313739453
commit 86d57974b0
3 changed files with 119 additions and 10 deletions
+36
View File
@@ -15,6 +15,7 @@ import sys
import io
import os
import json
import time
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -544,6 +545,41 @@ check('确认行高亮不改边框粗细',
== {A.CARD_HL},
str({c.cget('highlightthickness') for c in app.todo_cards.values()}))
print('=== 20. 分页不裁最底行(徽标只在后面几页) ===')
rows2 = []
_names = ['尖白菜', '仔姜', '四季豆', '莲花白', '大白菜', '大葱']
for _i in range(24):
rows2.append({
'id': 'p%02d' % _i,
'item_name': _names[_i % len(_names)],
'unit': '斤',
'remaining_qty': 5 + _i,
'customer_name': '富顺分公司',
# 第一页没有徽标(卡矮),后面几页有(卡高)——现场就是这个组合
'independent_inbound': (_i >= 12),
})
app.engine.rows = [dict(r) for r in rows2]
app._fill_todo(rows2)
root.update()
time.sleep(0.25)
root.update()
cv = app.todo_canvas
worst = []
for _pg in range(max(1, getattr(app, '_page_count', 1))):
inside = [c for c in app.todo_cards.values()
if c.winfo_manager() == 'grid']
for c in inside:
over = (c.winfo_y() + c.winfo_height()) - cv.winfo_height()
if over > 0:
worst.append((_pg + 1, c.winfo_y(), c.winfo_height(), over))
app._page_turn(1)
root.update()
check('每一页卡片都在视口内(不被裁)', not worst,
'超出:%r' % worst[:4])
check('多页时页码正常', getattr(app, '_page_count', 1) > 1,
getattr(app, '_page_count', 1))
root.destroy()
print('\n结果:%d 项通过,%d 项失败' % (ok, fail))
sys.exit(1 if fail else 0)
+77 -10
View File
@@ -98,6 +98,64 @@ def save_config(cfg, path='config.json'):
atomic.write_json(path, cfg)
def _paginate_by_height(items, ncols, budget, height_of):
"""按实际行高分页:每页累计高度不超过 budget。
与固定「一页几行」相比:一页里有高卡(带黄底徽标)时少吃一行,
都是矮卡时能多放一行,而且永远不会把最底行排出视口。
height_of(kind, obj) 返回这一项单独占的高度(含上下 gap);
卡片行的实际高度取本行最高那张。
"""
pages, cur = [], []
used = 0.0
col = 0 # 本行已经摆了几张卡
row_h = 0.0 # 本行最高卡
def close_row():
nonlocal used, col, row_h
if col:
used += row_h
col, row_h = 0, 0.0
def new_page():
nonlocal cur, used, col, row_h
close_row()
if cur:
pages.append(cur)
cur, used, col, row_h = [], 0.0, 0, 0.0
seq = list(items)
for idx, (kind, obj) in enumerate(seq):
h = float(height_of(kind, obj))
if kind == 'hdr':
close_row()
# 页尾孤标题:连后面那张卡都放不下时,标题也挪到下一页
nxt = 0.0
if idx + 1 < len(seq) and seq[idx + 1][0] == 'card':
nxt = float(height_of(*seq[idx + 1]))
if cur and (used + h > budget
or (nxt and used + h + nxt > budget)):
new_page()
cur.append((kind, obj))
used += h
continue
if col == 0:
if cur and used + h > budget:
new_page()
row_h = h
else:
row_h = max(row_h, h)
cur.append((kind, obj))
col += 1
if col >= ncols:
used += row_h
col, row_h = 0, 0.0
close_row()
if cur:
pages.append(cur)
return pages or [[]]
def _paginate_items(items, ncols, cap_rows):
"""把 (kind, obj) 序列切成若干页:每页占用的网格行数 ≤ cap_rows。
@@ -3725,13 +3783,10 @@ class App:
# (第一次用估值,摆完 _calibrate_row_h 量真实的再校正),名字
# 换 1 行还是 2 行差 20px,写死会最底行被切一半或下半页空着。
view_h = max(1, self.todo_canvas.winfo_height())
row_h = getattr(self, '_row_h_est', 0) or int(118 * self.S)
cap = max(1, (view_h - gap) // (row_h + gap))
# v1.0.56:列宽/列数/卡片集合都没变就别重排。确认条一弹出右列高度
# 就变,canvas 跟着发 Configure → 又跑一遍 _layout_cards。
# v1.0.58:view_h/页容量/页码也进 key —— 翻页、确认条弹出挤压
# 视口高度都会触发重排,其余 Configure 直接跳过。
key = (cw, view_h, ncols, cap, self._thumb_on(), self._page,
# 分页改成「按每行实际高度装箱」(_paginate_by_height):带黄底徽标/
# 长名字的行更高,这类页少吃一行;全是矮卡时多放一行;
# 不再用固定行高估一个页容量,避免最底行被视口裁掉。
key = (cw, view_h, ncols, self._thumb_on(), self._page,
len(items),
tuple(str(x) for x in (getattr(self, '_shown_ids', None) or ())))
if getattr(self, '_layout_key', None) == key:
@@ -3782,7 +3837,17 @@ class App:
badge.configure(
wraplength=max(int(80 * self.S),
card_w - int(16 * self.S)))
pages = _paginate_items(items, ncols, cap)
def _item_height(kind, obj):
"""这一项单独占的高度(卡片行取本行最高,见 _paginate_by_height)"""
try:
h = int(obj.winfo_reqheight())
except Exception:
h = 0
if h <= 10: # 还没量出来:用保守估值
h = int(118 * self.S)
return h + (2 * gap if kind == 'card' else gap)
pages = _paginate_by_height(items, ncols, view_h, _item_height)
self._page_count = len(pages)
self._page = max(0, min(self._page, len(pages) - 1))
page = pages[self._page]
@@ -3929,8 +3994,10 @@ class App:
def _calibrate_row_h_idle(self):
self._cal_sched = False
try:
hs = [c.winfo_reqheight() for c in self.todo_cards.values()
if c.winfo_manager() == 'grid']
# 量**全部**卡(不只是当前页):徽标/长名字会让某些卡更高,
# 只量当前页会把行高估值偏小,翻到有徽标的那页就多塞一行、
# 最底一张被裁(现场入库第 2 页开始出现的遮挡)。
hs = [c.winfo_reqheight() for c in self.todo_cards.values()]
hs = [h for h in hs if h > 10]
if not hs:
return
+6
View File
@@ -62,6 +62,12 @@
· 要调宽松可在 config 的 flow 段设置:confirm_zero_ms(默认 3000)、
confirm_linger_s(默认 10)。分拣工位不受影响,仍必须人工确认。
◆ 待办卡分页不再裁掉最底一行
· 以前按一个固定的卡高估“一页几行”:带「独立入库」黄底的卡更高,
翻到那页就多塞一行,最底那张被视口裁掉(入库 3 行 4 列时最明显)。
· 现在按每页实际行高装箱:都是矮卡时多放一行,有高卡时少放一行,
每一页的卡都完整显示(不会半张卡藏在翻页条下面)。
◆ 点待办卡不再抖、也不会两张同时亮
· 所有卡片外框固定 4px,选中(琥珀)/ 确认(绿)只换颜色、不改粗细。
以前确认行比别的卡粗 2px,一点卡整排卡片就被撑大、界面跟着跳。