Appearance
整体布局调整
一、结构骨架调整
1.1 src/components/Header/index.tsx
tsx
import { Button } from "antd";
function Header() {
return (
<div className="header-content">
<h1 className="header-title">3D画廊编辑器</h1>
<Button type="primary">预览</Button>
</div>
);
}
export default Header;1.2 新增菜单
src/components/Menu/sidebar.tsx
tsx
import { Menu } from 'antd'
const menuItems = [
{ key: 'gallery', label: '画廊编辑' },
{ key: 'character', label: '人物编辑' },
]
function AppSider() {
return (
<Menu
mode="inline"
defaultSelectedKeys={['gallery']}
items={menuItems}
style={{ height: '100%', borderRight: 0 }}
/>
)
}
export default AppSider1.3 引入菜单
src/components/Menu/index.tsx
tsx
import React from "react";
import AppSider from "./sidebar";
function Menu() {
const [left, setLeft] = React.useState(0);
return (
<div className="Menu" style={{ left }}>
<AppSider />
<div className="drawer-bar" onClick={() => setLeft(left === 0 ? -200 : 0)}></div>
</div>
);
}
export default Menu;1.4 Segmented分段控制器替换Button
diff
import React from "react";
import { init3D } from "./init-3d";
import { init2D } from "./init-2d";
+import { Segmented } from "antd";
function Main() {
React.useEffect(() => {
const dom = document.getElementById('threejs-3d-container')
const { scene } = init3D(dom!);
return () => {
if (dom) {
dom.innerHTML = ''
}
}
}, [])
React.useEffect(() => {
const dom = document.getElementById('threejs-2d-container')
const { scene } = init2D(dom!);
return () => {
if (dom) {
dom.innerHTML = ''
}
}
}, [])
const [curMode, setCurMode] = React.useState<'2d' | '3d'>('2d')
return (
<div className="Main">
<div id="threejs-3d-container" style={{ display: curMode === '3d' ? 'block' : 'none' }}></div>
<div id="threejs-2d-container" style={{ display: curMode === '2d' ? 'block' : 'none' }}></div>
+ <div className="mode-change-btns">
+ <Segmented
+ options={[
+ { label: '2D', value: '2d' },
+ { label: '3D', value: '3d' }
+ ]}
+ value={curMode}
+ onChange={(value) => setCurMode(value as '2d' | '3d')}
+ />
+ </div>
</div>
);
}
export default Main;二、布局调整
2.1 src/App.tsx
tsx
import { Layout } from 'antd'
import './App.scss'
import AppHeader from './components/Header'
import AppSider from './components/Menu'
import Main from './components/Main'
const { Header, Sider, Content } = Layout
function App() {
return (
<Layout className="gallery-editor-layout">
<Header className="app-header">
<AppHeader />
</Header>
<Layout>
<Sider width={200} className="app-sider">
<AppSider />
</Sider>
<Content className="app-content">
<Main />
</Content>
</Layout>
</Layout>
)
}
export default App2.2 src/App.scss
scss
body {
margin: 0;
}
.gallery-editor-layout {
min-height: 100vh;
.app-header {
display: flex;
align-items: center;
padding: 0 24px;
background: #fff;
border-bottom: 1px solid #000;
.header-content {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
}
.header-title {
margin: 0;
font-size: 18px;
font-weight: 500;
}
}
.app-sider {
background: #fff;
border-right: 1px solid #000;
.ant-menu {
margin-top: 16px;
}
}
.app-content {
position: relative;
min-height: calc(100vh - 64px);
background: #fff;
}
.main-content {
position: relative;
height: 100%;
min-height: calc(100vh - 64px);
#threejs-3d-container,
#threejs-2d-container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
.mode-change-btns {
position: absolute;
z-index: 10;
bottom: 20px;
left: 20px;
}
}
}