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 styles from './DraggleLayout.less';
import {connect} from "umi";
......@@ -12,30 +12,37 @@ function DraggleLayout({
containerHeight = 0, // 容器高度
initLeftWidth = 0, // 初始左侧容器宽度
handler = null, // 拖拽器
isLeft = true, // 拖拽器
onWidthChange = width => width, // 左侧容器高度变化
toolWidth,
dispatch
dispatch,
}) {
const ref = useRef(null);
const [position, setPosition] = useState({ x: initLeftWidth, y: 0 });
const [position, setPosition] = useState({x: initLeftWidth, y: 0});
const [props] = useDraggable(
ref,
{
onMouseMove: ({ x, y }) => {
onMouseMove: ({x, y}) => {
let _x = x;
if (_x < min) _x = min;
if (_x > max) _x = max;
if (onWidthChange) onWidthChange(_x);
setPosition({ x: _x, y });
dispatch&&dispatch({
type: "Studio/saveToolWidth",
setPosition({x: _x, y});
if (isLeft) {
dispatch && dispatch({
type: "Studio/saveToolLeftWidth",
payload: _x,
});
} else {
dispatch && dispatch({
type: "Studio/saveToolRightWidth",
payload: (containerWidth - _x),
});
}
},
},
{ overbound: false },
{overbound: false},
);
const _handler = handler ? (
React.cloneElement(handler, {
......@@ -46,16 +53,16 @@ function DraggleLayout({
},
})
) : (
<span style={{ fontSize: 18, pointerEvents: 'none' }}></span>
<span style={{fontSize: 18, pointerEvents: 'none'}}></span>
);
return (
<div
ref={ref}
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]}
<div className={styles.handler} {...props}>
......@@ -64,7 +71,7 @@ function DraggleLayout({
</div>
<div
className={styles.right}
style={{ width: containerWidth - position.x }}
style={{width: containerWidth - position.x}}
>
{children[1]}
</div>
......@@ -73,5 +80,4 @@ function DraggleLayout({
}
export default connect(({Studio}: { Studio: StateType }) => ({
toolWidth: Studio.toolWidth,
}))(DraggleLayout);
......@@ -205,7 +205,6 @@ const StudioCluster = (props: any) => {
onClick={onCreateCluster}
/>
</Tooltip>
<div style={{float: "right"}}>
<Tooltip title="刷新 Flink 集群">
<Button
type="text"
......@@ -213,7 +212,6 @@ const StudioCluster = (props: any) => {
onClick={onRefreshCluster}
/>
</Tooltip>
</div>
<Scrollbars style={{height: (toolHeight - 32)}}>
{cluster.length > 0 ? (
<Table dataSource={cluster} columns={getColumns()} size="small"/>) : (
......
......@@ -261,7 +261,6 @@ const StudioConnector = (props: any) => {
onClick={createSessions}
/>
</Tooltip>
<div style={{float: "right"}}>
{session.length > 0 ? (
<Tooltip title="切换会话">
<Button
......@@ -295,7 +294,6 @@ const StudioConnector = (props: any) => {
/>
</Tooltip>
</>)}
</div>
<Scrollbars style={{height: (toolHeight - 32)}}>
{currentSession.connectors && currentSession.connectors.length > 0 ? (
<Table dataSource={currentSession.connectors} columns={getColumns()} size="small"/>) : (
......
......@@ -68,7 +68,6 @@ const StudioDataBase = (props: any) => {
onClick={onCreateDataBase}
/>
</Tooltip>
<div style={{float: "right"}}>
<Tooltip title="刷新数据源">
<Button
type="text"
......@@ -76,7 +75,6 @@ const StudioDataBase = (props: any) => {
onClick={onRefreshDataBase}
/>
</Tooltip>
</div>
<Scrollbars style={{height: (toolHeight - 32)}}>
{database.length > 0 ? (
<Table dataSource={database} columns={getColumns()} size="small"/>) : (
......
......@@ -68,7 +68,6 @@ const StudioMetaData = (props: any) => {
>
{getDataBaseOptions()}
</Select>
<div style={{float: "right"}}>
<Tooltip title="刷新元数据表">
<Button
type="text"
......@@ -76,7 +75,6 @@ const StudioMetaData = (props: any) => {
onClick={onRefreshTreeData}
/>
</Tooltip>
</div>
<Scrollbars style={{height: (toolHeight - 32)}}>
<DirectoryTree
multiple
......
......@@ -345,7 +345,6 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
<div className={style.tree_div} >
<Row>
<Col span={24}>
<div style={{float: "right"}}>
<Tooltip title="创建根目录">
<Button
type="text"
......@@ -360,7 +359,6 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
onClick={offExpandAll}
/>
</Tooltip>
</div>
</Col>
</Row>
<Scrollbars style={{height:(toolHeight-32)}}>
......
......@@ -24,14 +24,16 @@ type StudioProps = {
const Studio: React.FC<StudioProps> = (props) => {
const {rightClickMenu, toolHeight, toolWidth, dispatch} = props;
const {rightClickMenu, toolHeight, toolLeftWidth,toolRightWidth, dispatch} = props;
const [form] = Form.useForm();
const VIEW = {
rightToolWidth: 300,
leftToolWidth: 300,
marginTop: 116,
topHeight: 35.6,
bottomHeight: 153.6,
rightMargin: 32,
leftMargin: 36,
midMargin: 46,
};
const [size, setSize] = useState({
width: document.documentElement.clientWidth - 1,
......@@ -92,11 +94,29 @@ const Studio: React.FC<StudioProps> = (props) => {
>
<Row>
<DraggleLayout
containerWidth={size.width - VIEW.rightToolWidth}
containerWidth={size.width}
containerHeight={toolHeight}
min={VIEW.leftMargin+VIEW.midMargin}
max={size.width - VIEW.rightMargin}
initLeftWidth={size.width - toolRightWidth}
isLeft={false}
handler={
<div
style={{
width: 4,
height: '100%',
background: 'rgb(240, 240, 240)',
}}
/>
}
>
<DraggleLayout
containerWidth={size.width - toolRightWidth}
containerHeight={toolHeight}
min={VIEW.leftToolWidth}
max={size.width * (1 / 2)}
initLeftWidth={VIEW.leftToolWidth}
min={VIEW.leftMargin}
max={size.width - VIEW.rightMargin - VIEW.midMargin}
initLeftWidth={toolLeftWidth}
isLeft={true}
handler={
<div
style={{
......@@ -115,12 +135,13 @@ const Studio: React.FC<StudioProps> = (props) => {
}}/>
</Col>
<Col>
<StudioTabs width={size.width - VIEW.rightToolWidth - toolWidth}/>
<StudioTabs width={size.width - toolRightWidth - toolLeftWidth}/>
</Col>
</DraggleLayout>
<Col id='StudioRightTool' style={{width: VIEW.rightToolWidth}} className={styles["vertical-tabs"]}>
<Col id='StudioRightTool' className={styles["vertical-tabs"]}>
<StudioRightTool form={form}/>
</Col>
</DraggleLayout>
</Row>
<Row>
<Col span={24}>
......@@ -137,5 +158,6 @@ const Studio: React.FC<StudioProps> = (props) => {
export default connect(({Studio}: { Studio: StateType }) => ({
rightClickMenu: Studio.rightClickMenu,
toolHeight: Studio.toolHeight,
toolWidth: Studio.toolWidth,
toolLeftWidth: Studio.toolLeftWidth,
toolRightWidth: Studio.toolRightWidth,
}))(Studio);
......@@ -123,7 +123,8 @@ export type SessionType = {
export type StateType = {
toolHeight?: number;
toolWidth?: number;
toolRightWidth?: number;
toolLeftWidth?: number;
cluster?: ClusterType[];
sessionCluster?: ClusterType[];
clusterConfiguration?: ClusterConfigurationType[];
......@@ -150,7 +151,8 @@ export type ModelType = {
};
reducers: {
saveToolHeight: Reducer<StateType>;
saveToolWidth: Reducer<StateType>;
saveToolRightWidth: Reducer<StateType>;
saveToolLeftWidth: Reducer<StateType>;
saveSql: Reducer<StateType>;
saveCurrentPath: Reducer<StateType>;
saveMonaco: Reducer<StateType>;
......@@ -174,7 +176,8 @@ const Model: ModelType = {
namespace: 'Studio',
state: {
toolHeight: 400,
toolWidth: 300,
toolRightWidth: 300,
toolLeftWidth: 300,
cluster: [],
sessionCluster: [],
clusterConfiguration: [],
......@@ -282,10 +285,15 @@ const Model: ModelType = {
...state,
toolHeight: payload,
};
},saveToolWidth(state, {payload}) {
},saveToolRightWidth(state, {payload}) {
return {
...state,
toolWidth: payload,
toolRightWidth: payload,
};
},saveToolLeftWidth(state, {payload}) {
return {
...state,
toolLeftWidth: 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