fix(dnfs): 主题/样式继承改为仅查直接父节点,修复 getNode 查询目标错误

This commit is contained in:
qing committed 2026-08-12 15:36:53 +08:00
1 parent d7eb46b3a1
commit 1774d7d64b
1 file changed
+21 -24
+21 -24
View File
@@ -697,11 +697,9 @@ function formatBytes(n) {
return n.toFixed(1) + units[i]; return n.toFixed(1) + units[i];
} }
/* ===== 祖先主题/样式继承 ===== /* ===== 父节点主题/样式继承 =====
* 当前节点不存在 theme/style 子节点时,沿 stack 向根搜索最近祖先的对应节点, * 当前节点不存在 theme/style 子节点时,查找父节点的对应子节点并自动注入 CSS。
* 自动注入其 CSS。已存在的不重复搜索(hasTheme/hasStyle 分别控制)。 * 已存在的不重复搜索(hasTheme/hasStyle 分别控制)。 */
* 异步 getNode 可能跨导航——用 _inherit_gen 做取消,新导航的 clearAllEffects
* 会移除旧注入。 */
var _inherit_gen = 0; var _inherit_gen = 0;
function inheritThemeStyle() { function inheritThemeStyle() {
var hasTheme = false, hasStyle = false; var hasTheme = false, hasStyle = false;
@@ -713,29 +711,28 @@ function inheritThemeStyle() {
} }
if (hasTheme && hasStyle) return; if (hasTheme && hasStyle) return;
// 仅查询直接父节点
var parentPid = (stack.length === 0) ? 0 : (stack.length === 1 ? 0 : stack[stack.length - 2]);
var gen = ++_inherit_gen; var gen = ++_inherit_gen;
(async function() { (async function() {
for (var i = stack.length - 1; i >= 0; i--) { if (gen !== _inherit_gen) return;
if (hasTheme && hasStyle) break; try {
if (gen !== _inherit_gen) return; var children = await getNode(parentPid);
try { if (!Array.isArray(children)) return;
var children = await getNode(stack[i]); for (var j = 0; j < children.length; j++) {
if (!Array.isArray(children)) continue; var sp = parseSp(children[j].content);
for (var j = 0; j < children.length; j++) { if (!sp) continue;
var sp = parseSp(children[j].content); if (!hasTheme && sp._sp === 'theme') {
if (!sp) continue; injectSpCss(sp, 'inh-' + children[j].id);
if (!hasTheme && sp._sp === 'theme') { hasTheme = true;
injectSpCss(sp, 'inh-' + children[j].id); }
hasTheme = true; if (!hasStyle && sp._sp === 'style') {
} injectSpCss(sp, 'inh-' + children[j].id);
if (!hasStyle && sp._sp === 'style') { hasStyle = true;
injectSpCss(sp, 'inh-' + children[j].id);
hasStyle = true;
}
} }
} catch (e) {
console.error('继承主题/样式失败:', e);
} }
} catch (e) {
console.error('继承主题/样式失败:', e);
} }
})(); })();
} }