Commit 51728178 authored by wenmo's avatar wenmo

三级拖拽实现

parent 5e8f3caf
import React, { useRef, useState } from 'react'; import React, {useRef, useState} from 'react';
import useDraggable from '../../hooks/useDraggable'; import useDraggable from '../../hooks/useDraggable';
import styles from './DraggleLayout.less'; import styles from './DraggleLayout.less';
import {connect} from "umi"; import {connect} from "umi";
import {StateType} from "@/pages/FlinkSqlStudio/model"; import {StateType} from "@/pages/FlinkSqlStudio/model";
function DraggleLayout({ function DraggleLayout({
children, // 两列布局 children, // 两列布局
min = 400, // 左侧最小宽度 min = 400, // 左侧最小宽度
max = Infinity, // 左侧最大宽度 max = Infinity, // 左侧最大宽度
containerWidth = 0, // 容器宽度 containerWidth = 0, // 容器宽度
containerHeight = 0, // 容器高度 containerHeight = 0, // 容器高度
initLeftWidth = 0, // 初始左侧容器宽度 initLeftWidth = 0, // 初始左侧容器宽度
handler = null, // 拖拽器 handler = null, // 拖拽器
onWidthChange = width => width, // 左侧容器高度变化 isLeft = true, // 拖拽器
toolWidth, onWidthChange = width => width, // 左侧容器高度变化
dispatch dispatch,
}) { }) {
const ref = useRef(null); const ref = useRef(null);
const [position, setPosition] = useState({ x: initLeftWidth, y: 0 }); const [position, setPosition] = useState({x: initLeftWidth, y: 0});
const [props] = useDraggable( const [props] = useDraggable(
ref, ref,
{ {
onMouseMove: ({ x, y }) => { onMouseMove: ({x, y}) => {
let _x = x; let _x = x;
if (_x < min) _x = min; if (_x < min) _x = min;
if (_x > max) _x = max; if (_x > max) _x = max;
if (onWidthChange) onWidthChange(_x); if (onWidthChange) onWidthChange(_x);
setPosition({ x: _x, y }); setPosition({x: _x, y});
dispatch&&dispatch({ if (isLeft) {
type: "Studio/saveToolWidth", dispatch && dispatch({
payload: _x, type: "Studio/saveToolLeftWidth",
}); payload: _x,
});
} else {
dispatch && dispatch({
type: "Studio/saveToolRightWidth",
payload: (containerWidth - _x),
});
}
}, },
}, },
{ overbound: false }, {overbound: false},
); );
const _handler = handler ? ( const _handler = handler ? (
React.cloneElement(handler, { React.cloneElement(handler, {
...@@ -46,16 +53,16 @@ function DraggleLayout({ ...@@ -46,16 +53,16 @@ function DraggleLayout({
}, },
}) })
) : ( ) : (
<span style={{ fontSize: 18, pointerEvents: 'none' }}></span> <span style={{fontSize: 18, pointerEvents: 'none'}}></span>
); );
return ( return (
<div <div
ref={ref} ref={ref}
className={styles.root} className={styles.root}
style={{ width: containerWidth, height: containerHeight }} style={{width: containerWidth, height: containerHeight}}
> >
<div className={styles.left} style={{ width: position.x }}> <div className={styles.left} style={{width: position.x}}>
{children[0]} {children[0]}
<div className={styles.handler} {...props}> <div className={styles.handler} {...props}>
...@@ -64,7 +71,7 @@ function DraggleLayout({ ...@@ -64,7 +71,7 @@ function DraggleLayout({
</div> </div>
<div <div
className={styles.right} className={styles.right}
style={{ width: containerWidth - position.x }} style={{width: containerWidth - position.x}}
> >
{children[1]} {children[1]}
</div> </div>
...@@ -73,5 +80,4 @@ function DraggleLayout({ ...@@ -73,5 +80,4 @@ function DraggleLayout({
} }
export default connect(({Studio}: { Studio: StateType }) => ({ export default connect(({Studio}: { Studio: StateType }) => ({
toolWidth: Studio.toolWidth,
}))(DraggleLayout); }))(DraggleLayout);
...@@ -205,15 +205,13 @@ const StudioCluster = (props: any) => { ...@@ -205,15 +205,13 @@ const StudioCluster = (props: any) => {
onClick={onCreateCluster} onClick={onCreateCluster}
/> />
</Tooltip> </Tooltip>
<div style={{float: "right"}}> <Tooltip title="刷新 Flink 集群">
<Tooltip title="刷新 Flink 集群"> <Button
<Button type="text"
type="text" icon={<ReloadOutlined/>}
icon={<ReloadOutlined/>} onClick={onRefreshCluster}
onClick={onRefreshCluster} />
/> </Tooltip>
</Tooltip>
</div>
<Scrollbars style={{height: (toolHeight - 32)}}> <Scrollbars style={{height: (toolHeight - 32)}}>
{cluster.length > 0 ? ( {cluster.length > 0 ? (
<Table dataSource={cluster} columns={getColumns()} size="small"/>) : ( <Table dataSource={cluster} columns={getColumns()} size="small"/>) : (
......
...@@ -261,7 +261,6 @@ const StudioConnector = (props: any) => { ...@@ -261,7 +261,6 @@ const StudioConnector = (props: any) => {
onClick={createSessions} onClick={createSessions}
/> />
</Tooltip> </Tooltip>
<div style={{float: "right"}}>
{session.length > 0 ? ( {session.length > 0 ? (
<Tooltip title="切换会话"> <Tooltip title="切换会话">
<Button <Button
...@@ -295,7 +294,6 @@ const StudioConnector = (props: any) => { ...@@ -295,7 +294,6 @@ const StudioConnector = (props: any) => {
/> />
</Tooltip> </Tooltip>
</>)} </>)}
</div>
<Scrollbars style={{height: (toolHeight - 32)}}> <Scrollbars style={{height: (toolHeight - 32)}}>
{currentSession.connectors && currentSession.connectors.length > 0 ? ( {currentSession.connectors && currentSession.connectors.length > 0 ? (
<Table dataSource={currentSession.connectors} columns={getColumns()} size="small"/>) : ( <Table dataSource={currentSession.connectors} columns={getColumns()} size="small"/>) : (
......
...@@ -68,15 +68,13 @@ const StudioDataBase = (props: any) => { ...@@ -68,15 +68,13 @@ const StudioDataBase = (props: any) => {
onClick={onCreateDataBase} onClick={onCreateDataBase}
/> />
</Tooltip> </Tooltip>
<div style={{float: "right"}}> <Tooltip title="刷新数据源">
<Tooltip title="刷新数据源"> <Button
<Button type="text"
type="text" icon={<ReloadOutlined/>}
icon={<ReloadOutlined/>} onClick={onRefreshDataBase}
onClick={onRefreshDataBase} />
/> </Tooltip>
</Tooltip>
</div>
<Scrollbars style={{height: (toolHeight - 32)}}> <Scrollbars style={{height: (toolHeight - 32)}}>
{database.length > 0 ? ( {database.length > 0 ? (
<Table dataSource={database} columns={getColumns()} size="small"/>) : ( <Table dataSource={database} columns={getColumns()} size="small"/>) : (
......
...@@ -68,15 +68,13 @@ const StudioMetaData = (props: any) => { ...@@ -68,15 +68,13 @@ const StudioMetaData = (props: any) => {
> >
{getDataBaseOptions()} {getDataBaseOptions()}
</Select> </Select>
<div style={{float: "right"}}> <Tooltip title="刷新元数据表">
<Tooltip title="刷新元数据表"> <Button
<Button type="text"
type="text" icon={<ReloadOutlined/>}
icon={<ReloadOutlined/>} onClick={onRefreshTreeData}
onClick={onRefreshTreeData} />
/> </Tooltip>
</Tooltip>
</div>
<Scrollbars style={{height: (toolHeight - 32)}}> <Scrollbars style={{height: (toolHeight - 32)}}>
<DirectoryTree <DirectoryTree
multiple multiple
......
...@@ -345,7 +345,6 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => { ...@@ -345,7 +345,6 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
<div className={style.tree_div} > <div className={style.tree_div} >
<Row> <Row>
<Col span={24}> <Col span={24}>
<div style={{float: "right"}}>
<Tooltip title="创建根目录"> <Tooltip title="创建根目录">
<Button <Button
type="text" type="text"
...@@ -360,7 +359,6 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => { ...@@ -360,7 +359,6 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
onClick={offExpandAll} onClick={offExpandAll}
/> />
</Tooltip> </Tooltip>
</div>
</Col> </Col>
</Row> </Row>
<Scrollbars style={{height:(toolHeight-32)}}> <Scrollbars style={{height:(toolHeight-32)}}>
......
...@@ -24,14 +24,16 @@ type StudioProps = { ...@@ -24,14 +24,16 @@ type StudioProps = {
const Studio: React.FC<StudioProps> = (props) => { const Studio: React.FC<StudioProps> = (props) => {
const {rightClickMenu, toolHeight, toolWidth, dispatch} = props; const {rightClickMenu, toolHeight, toolLeftWidth,toolRightWidth, dispatch} = props;
const [form] = Form.useForm(); const [form] = Form.useForm();
const VIEW = { const VIEW = {
rightToolWidth: 300,
leftToolWidth: 300, leftToolWidth: 300,
marginTop: 116, marginTop: 116,
topHeight: 35.6, topHeight: 35.6,
bottomHeight: 153.6, bottomHeight: 153.6,
rightMargin: 32,
leftMargin: 36,
midMargin: 46,
}; };
const [size, setSize] = useState({ const [size, setSize] = useState({
width: document.documentElement.clientWidth - 1, width: document.documentElement.clientWidth - 1,
...@@ -92,11 +94,12 @@ const Studio: React.FC<StudioProps> = (props) => { ...@@ -92,11 +94,12 @@ const Studio: React.FC<StudioProps> = (props) => {
> >
<Row> <Row>
<DraggleLayout <DraggleLayout
containerWidth={size.width - VIEW.rightToolWidth} containerWidth={size.width}
containerHeight={toolHeight} containerHeight={toolHeight}
min={VIEW.leftToolWidth} min={VIEW.leftMargin+VIEW.midMargin}
max={size.width * (1 / 2)} max={size.width - VIEW.rightMargin}
initLeftWidth={VIEW.leftToolWidth} initLeftWidth={size.width - toolRightWidth}
isLeft={false}
handler={ handler={
<div <div
style={{ style={{
...@@ -107,20 +110,38 @@ const Studio: React.FC<StudioProps> = (props) => { ...@@ -107,20 +110,38 @@ const Studio: React.FC<StudioProps> = (props) => {
/> />
} }
> >
<Col className={styles["vertical-tabs"]}> <DraggleLayout
<StudioLeftTool style={{ containerWidth={size.width - toolRightWidth}
display: 'flex', containerHeight={toolHeight}
alignItems: 'center', min={VIEW.leftMargin}
justifyContent: 'center', max={size.width - VIEW.rightMargin - VIEW.midMargin}
}}/> initLeftWidth={toolLeftWidth}
</Col> isLeft={true}
<Col> handler={
<StudioTabs width={size.width - VIEW.rightToolWidth - toolWidth}/> <div
style={{
width: 4,
height: '100%',
background: 'rgb(240, 240, 240)',
}}
/>
}
>
<Col className={styles["vertical-tabs"]}>
<StudioLeftTool style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}/>
</Col>
<Col>
<StudioTabs width={size.width - toolRightWidth - toolLeftWidth}/>
</Col>
</DraggleLayout>
<Col id='StudioRightTool' className={styles["vertical-tabs"]}>
<StudioRightTool form={form}/>
</Col> </Col>
</DraggleLayout> </DraggleLayout>
<Col id='StudioRightTool' style={{width: VIEW.rightToolWidth}} className={styles["vertical-tabs"]}>
<StudioRightTool form={form}/>
</Col>
</Row> </Row>
<Row> <Row>
<Col span={24}> <Col span={24}>
...@@ -137,5 +158,6 @@ const Studio: React.FC<StudioProps> = (props) => { ...@@ -137,5 +158,6 @@ const Studio: React.FC<StudioProps> = (props) => {
export default connect(({Studio}: { Studio: StateType }) => ({ export default connect(({Studio}: { Studio: StateType }) => ({
rightClickMenu: Studio.rightClickMenu, rightClickMenu: Studio.rightClickMenu,
toolHeight: Studio.toolHeight, toolHeight: Studio.toolHeight,
toolWidth: Studio.toolWidth, toolLeftWidth: Studio.toolLeftWidth,
toolRightWidth: Studio.toolRightWidth,
}))(Studio); }))(Studio);
...@@ -123,7 +123,8 @@ export type SessionType = { ...@@ -123,7 +123,8 @@ export type SessionType = {
export type StateType = { export type StateType = {
toolHeight?: number; toolHeight?: number;
toolWidth?: number; toolRightWidth?: number;
toolLeftWidth?: number;
cluster?: ClusterType[]; cluster?: ClusterType[];
sessionCluster?: ClusterType[]; sessionCluster?: ClusterType[];
clusterConfiguration?: ClusterConfigurationType[]; clusterConfiguration?: ClusterConfigurationType[];
...@@ -150,7 +151,8 @@ export type ModelType = { ...@@ -150,7 +151,8 @@ export type ModelType = {
}; };
reducers: { reducers: {
saveToolHeight: Reducer<StateType>; saveToolHeight: Reducer<StateType>;
saveToolWidth: Reducer<StateType>; saveToolRightWidth: Reducer<StateType>;
saveToolLeftWidth: Reducer<StateType>;
saveSql: Reducer<StateType>; saveSql: Reducer<StateType>;
saveCurrentPath: Reducer<StateType>; saveCurrentPath: Reducer<StateType>;
saveMonaco: Reducer<StateType>; saveMonaco: Reducer<StateType>;
...@@ -174,7 +176,8 @@ const Model: ModelType = { ...@@ -174,7 +176,8 @@ const Model: ModelType = {
namespace: 'Studio', namespace: 'Studio',
state: { state: {
toolHeight: 400, toolHeight: 400,
toolWidth: 300, toolRightWidth: 300,
toolLeftWidth: 300,
cluster: [], cluster: [],
sessionCluster: [], sessionCluster: [],
clusterConfiguration: [], clusterConfiguration: [],
...@@ -282,10 +285,15 @@ const Model: ModelType = { ...@@ -282,10 +285,15 @@ const Model: ModelType = {
...state, ...state,
toolHeight: payload, toolHeight: payload,
}; };
},saveToolWidth(state, {payload}) { },saveToolRightWidth(state, {payload}) {
return { return {
...state, ...state,
toolWidth: payload, toolRightWidth: payload,
};
},saveToolLeftWidth(state, {payload}) {
return {
...state,
toolLeftWidth: payload,
}; };
}, },
saveSql(state, {payload}) { saveSql(state, {payload}) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment