From 8939e610941a0048316fb2d9ed3e23df2da017f9 Mon Sep 17 00:00:00 2001 From: qitangbo Date: Thu, 8 Oct 2026 21:08:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20recents=5Flimit=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=8C=E7=BB=A7=E6=89=BF=20patch=20OmuxNav?= =?UTF-8?q?Bar=20=E5=B0=86=E5=AF=BC=E8=88=AA=E6=A0=8F=E3=80=8C=E6=9C=80?= =?UTF-8?q?=E8=BF=91=E3=80=8D=E4=B8=8A=E9=99=90=E4=BB=8E50=E6=94=B9?= =?UTF-8?q?=E4=B8=BA20=EF=BC=88=E4=B8=8D=E6=94=B9=E5=8A=A8=E7=BA=BF?= =?UTF-8?q?=E4=B8=8A=E6=BA=90=E7=A0=81/yuthon=5Fbase=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- recents_limit/__init__.py | 2 ++ recents_limit/__manifest__.py | 26 ++++++++++++++++++ recents_limit/static/src/js/recents_limit.js | 29 ++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 recents_limit/__init__.py create mode 100644 recents_limit/__manifest__.py create mode 100644 recents_limit/static/src/js/recents_limit.js diff --git a/recents_limit/__init__.py b/recents_limit/__init__.py new file mode 100644 index 0000000..086d4a7 --- /dev/null +++ b/recents_limit/__init__.py @@ -0,0 +1,2 @@ +# recents_limit —— 纯前端补丁模块,无 Python 模型 +# 仅通过 JS patch 把导航栏「最近」分组上限从 50 改为 20。 diff --git a/recents_limit/__manifest__.py b/recents_limit/__manifest__.py new file mode 100644 index 0000000..ce4aefe --- /dev/null +++ b/recents_limit/__manifest__.py @@ -0,0 +1,26 @@ +{ + 'name': 'Recents Limit (20)', + 'version': '18.0.1.0.0', + 'summary': '把导航栏「最近」分组上限从 50 改为 20(继承 udoo_om_ux,不改动线上源码)', + 'description': """ + 通过前端 patch 继承 udoo_om_ux 的 OmuxNavBar,把「最近访问」的分组上限 + 从默认的 50 截到 20。 + + 实现方式(不改动 udoo_om_ux 与 yuthon_base 的任何源码): + 1. setup 时把历史 localStorage 中可能 >20 的 recents 截断到 20; + 2. 监听 UDOO:FRC 事件,在每次新增「最近」后把上限压回 20。 + 由于整个会话期间 this.uo.recents 恒 <= 20,beforeunload 持久化到 + localStorage 时自然也 <= 20,无需再 patch beforeunload 逻辑。 + """, + 'category': 'Tools', + 'depends': ['udoo_om_ux', 'web'], + 'assets': { + 'web.assets_backend': [ + 'recents_limit/static/src/js/recents_limit.js', + ], + }, + 'installable': True, + 'application': False, + 'license': 'LGPL-3', + 'author': 'Yuthon', +} diff --git a/recents_limit/static/src/js/recents_limit.js b/recents_limit/static/src/js/recents_limit.js new file mode 100644 index 0000000..b8b67c5 --- /dev/null +++ b/recents_limit/static/src/js/recents_limit.js @@ -0,0 +1,29 @@ +/** @odoo-module **/ +import { patch } from "@web/core/utils/patch"; +import { OmuxNavBar } from "@udoo_om_ux/webclient/navbar/navbar"; +import { useBus } from "@web/core/utils/hooks"; + +// 「最近访问」分组的目标上限(线上 udoo_om_ux 默认为 50) +const MAX_RECENTS = 20; + +patch(OmuxNavBar.prototype, { + setup() { + super.setup(); + + // 1) 处理从历史 localStorage 加载进来的 >20 条「最近」 + if (this.uo?.recents?.length > MAX_RECENTS) { + this.uo.recents.length = MAX_RECENTS; + } + + // 2) 实时:每次新增「最近」访问后,把上限压回 20。 + // 原 OmuxNavBar 在 UDOO:FRC 事件里会把上限维持在 50, + // 这里在其之后(先注册者先触发)再截到 20, + // 于是整个会话期间 this.uo.recents 恒 <= 20, + // 连带 beforeunload 持久化到 localStorage 也自然 <= 20。 + useBus(this.env.bus, "UDOO:FRC", () => { + if (this.uo?.recents?.length > MAX_RECENTS) { + this.uo.recents.length = MAX_RECENTS; + } + }); + }, +});