feat: 模组全维度独立,消除全局 DOM/Portal/存储污染
- jieya-ibp/welltrust-qap ThemeContext 改为作用域容器承载 CSS 变量与背景色,不再写 document - 删除 order-cost CostCockpit 对 documentElement 的死变量写入 - bomx Drawer createPortal 挂载点内移到 .bomx-app,移除 document.body 兜底 - knowledge-graph 拖拽 cursor 改为根容器 ref - 新增 check-module-independence 门禁并接入 build - SOP 与融合技能文档补充「模组完全独立互不影响」章节 Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6 noreply@anthropic.com>
parent
9c45aedbe8
commit
8699798ea5
@@ -2,8 +2,13 @@ import { useEffect } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { IconX } from './Icons';
|
||||
|
||||
// 使用 Portal 渲染到 body,避免被父级层叠上下文/导航条遮挡
|
||||
export default function Drawer({ open, title, onClose, children, width = 540 }: any) {
|
||||
// Portal 渲染到模块根容器内的挂载点(必传 portalMount),
|
||||
// 保持 DOM 节点位于模块作用域内,禁止挂到 document.body
|
||||
export default function Drawer({ open, title, onClose, children, width = 540, portalMount }: {
|
||||
open: boolean; title?: React.ReactNode; onClose: () => void;
|
||||
children?: React.ReactNode; width?: number;
|
||||
portalMount: HTMLDivElement;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
|
||||
@@ -32,6 +37,6 @@ export default function Drawer({ open, title, onClose, children, width = 540 }:
|
||||
<div className="drawer-content">{children}</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body
|
||||
portalMount
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState, useCallback } from 'react';
|
||||
import { useEffect, useState, useCallback, useRef } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { initStore } from '../core/store';
|
||||
import BomBrowser from '../components/BomBrowser';
|
||||
@@ -47,6 +47,9 @@ export default function BomxReuseHome() {
|
||||
const [loadError, setLoadError] = useState<any>(null);
|
||||
const [fadingOut, setFadingOut] = useState(false);
|
||||
|
||||
// Drawer Portal 挂载点:位于 .bomx-app 根容器内部,使 Drawer DOM 节点留在模块作用域内
|
||||
const portalMountRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const loadData = useCallback(async (sourceKey: string) => {
|
||||
setLoading(true);
|
||||
setFadingOut(false);
|
||||
@@ -164,6 +167,9 @@ export default function BomxReuseHome() {
|
||||
</div>
|
||||
<ToastContainer />
|
||||
|
||||
{/* Drawer Portal 挂载点:Drawer 通过 createPortal 将内容渲染到此节点内 */}
|
||||
<div ref={portalMountRef} />
|
||||
|
||||
{data && (
|
||||
<div className="data-source-switch">
|
||||
<select
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { createContext, useContext, useState, useCallback } from 'react';
|
||||
import type { ReactNode, CSSProperties } from 'react';
|
||||
|
||||
export type Theme = 'dark' | 'light';
|
||||
|
||||
@@ -185,19 +185,20 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty('--body-bg', tokens.bodyBg);
|
||||
root.style.setProperty('--scroll-thumb', tokens.scrollThumb);
|
||||
root.style.setProperty('--glow-color', tokens.accentGlow);
|
||||
root.style.setProperty('--hover-bg', tokens.tableRowHover);
|
||||
document.body.style.background = tokens.bodyBgImage;
|
||||
document.body.style.color = tokens.text;
|
||||
}, [tokens]);
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={{ theme, tokens, toggleTheme }}>
|
||||
{children}
|
||||
<div style={{
|
||||
'--body-bg': tokens.bodyBg,
|
||||
'--scroll-thumb': tokens.scrollThumb,
|
||||
'--glow-color': tokens.accentGlow,
|
||||
'--hover-bg': tokens.tableRowHover,
|
||||
background: tokens.bodyBgImage,
|
||||
color: tokens.text,
|
||||
width: '100%',
|
||||
minHeight: '100vh',
|
||||
} as CSSProperties}>
|
||||
{children}
|
||||
</div>
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ export default function KnowledgeGraphHome() {
|
||||
const [sideTab, setSideTab] = useState<SideTab>('stats');
|
||||
const [sidebarWidth, setSidebarWidth] = useState(320);
|
||||
const isDragging = useRef(false);
|
||||
const rootRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const handleNodeSelect = (node: SelectedNode | null) => setSelectedNode(node);
|
||||
const handleMaterialSelect = (mat: Material | null) => {
|
||||
@@ -46,8 +47,8 @@ export default function KnowledgeGraphHome() {
|
||||
isDragging.current = true;
|
||||
const startX = e.clientX;
|
||||
const startWidth = sidebarWidth;
|
||||
document.body.style.cursor = 'col-resize';
|
||||
document.body.style.userSelect = 'none';
|
||||
rootRef.current?.style.setProperty('cursor', 'col-resize');
|
||||
rootRef.current?.style.setProperty('userSelect', 'none');
|
||||
|
||||
const onMouseMove = (ev: MouseEvent) => {
|
||||
if (!isDragging.current) return;
|
||||
@@ -57,8 +58,8 @@ export default function KnowledgeGraphHome() {
|
||||
};
|
||||
const onMouseUp = () => {
|
||||
isDragging.current = false;
|
||||
document.body.style.cursor = '';
|
||||
document.body.style.userSelect = '';
|
||||
rootRef.current?.style.setProperty('cursor', '');
|
||||
rootRef.current?.style.setProperty('userSelect', '');
|
||||
document.removeEventListener('mousemove', onMouseMove);
|
||||
document.removeEventListener('mouseup', onMouseUp);
|
||||
};
|
||||
@@ -69,7 +70,7 @@ export default function KnowledgeGraphHome() {
|
||||
const viewLabels: Record<ViewMode, string> = { category: '按分类', project: '按项目', aging: '按账龄' };
|
||||
|
||||
return (
|
||||
<div className="flex h-screen w-screen overflow-hidden" style={{ backgroundColor:'#f5f5f7' }}>
|
||||
<div ref={rootRef} className="flex h-screen w-screen overflow-hidden" style={{ backgroundColor:'#f5f5f7' }}>
|
||||
{/* Sidebar */}
|
||||
<aside className="flex-shrink-0 flex flex-col sidebar-bg" style={{ width:sidebarWidth, borderRight:'none' }}>
|
||||
{/* Logo header */}
|
||||
|
||||
@@ -24,11 +24,6 @@ export default function CostCockpit() {
|
||||
const { theme, tokens, toggleTheme } = useTheme();
|
||||
const { orders } = useOrders();
|
||||
|
||||
// 同步 body 背景色(CSS 变量)
|
||||
useEffect(() => {
|
||||
document.documentElement.style.setProperty('--body-bg', tokens.bodyBg);
|
||||
}, [tokens.bodyBg]);
|
||||
|
||||
const [selectedOrder, setSelectedOrder] = useState<Order | null>(null);
|
||||
const [leftExpanded, setLeftExpanded] = useState(false);
|
||||
const [rightExpanded, setRightExpanded] = useState(false);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { createContext, useContext, useState, useCallback } from 'react';
|
||||
import type { ReactNode, CSSProperties } from 'react';
|
||||
|
||||
export type Theme = 'dark' | 'light';
|
||||
|
||||
@@ -193,19 +193,20 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty('--body-bg', tokens.bodyBg);
|
||||
root.style.setProperty('--scroll-thumb', tokens.scrollThumb);
|
||||
root.style.setProperty('--glow-color', tokens.accentGlow);
|
||||
root.style.setProperty('--hover-bg', tokens.tableRowHover);
|
||||
document.body.style.background = tokens.bodyBgImage;
|
||||
document.body.style.color = tokens.text;
|
||||
}, [tokens]);
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={{ theme, tokens, toggleTheme }}>
|
||||
{children}
|
||||
<div style={{
|
||||
'--body-bg': tokens.bodyBg,
|
||||
'--scroll-thumb': tokens.scrollThumb,
|
||||
'--glow-color': tokens.accentGlow,
|
||||
'--hover-bg': tokens.tableRowHover,
|
||||
background: tokens.bodyBgImage,
|
||||
color: tokens.text,
|
||||
width: '100%',
|
||||
minHeight: '100vh',
|
||||
} as CSSProperties}>
|
||||
{children}
|
||||
</div>
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user