import React from 'react';
import styles from './CellDesigner.css';
import { Guid } from 'guid-typescript';
import {
DragDropContext,
Draggable,
Droppable,
DroppableProvided,
DraggableLocation,
DropResult,
DroppableStateSnapshot,
DraggableProvided,
DraggableStateSnapshot,
DragStart,
HookProvided,
} from 'react-beautiful-dnd';
import { Row, Col } from 'antd';
import { Cell, CellType, DataType } from '@/components/GridCell';
class XCell {
id: Guid = Guid.create();
cell: Cell = new Cell();
child: XCell[] = [];
}
const getTextXCell = (): XCell => {
return {
id: Guid.create(),
cell: {
text: '未定义',
type: CellType.Text,
span: 4,
},
child: [],
};
};
const getInnerXCell = (): XCell => {
return {
id: Guid.create(),
cell: {
text: '子表设计',
type: CellType.InnerCell,
span: 4,
iCell: new Cell(),
},
child: [],
};
};
const getGroupXCell = (): XCell => {
return {
id: Guid.create(),
cell: {
text: '未定义集合',
type: CellType.Group,
dataType: DataType.Default, //横向布局为Default,纵向布局为List
span: 8, //根据需要调整
},
child: [
{
id: Guid.create(),
cell: {
text: 'some',
type: CellType.Text,
dataType: DataType.Default, //横向布局为Default,纵向布局为List
span: 4, //根据需要调整
},
child: [],
},
],
};
};
const getCustomXCell = (): XCell => {
return {
id: Guid.create(),
cell: {
text: '自定义纵向排列表格',
type: CellType.Custom,
dataType: DataType.List, //横向布局为Default,纵向布局为List
span: 4,
render: () => {
/**自定义html */
//todo
},
},
child: [],
};
};
const getItemStyle = (draggableStyle: any, isDragging: boolean): {} => ({
userSelect: 'none',
padding: 0,
margin: 0,
background: isDragging ? 'lightgreen' : 'grey',
...draggableStyle,
});
const getListStyle = (isDraggingOver: boolean): {} => ({
background: isDraggingOver ? 'lightblue' : 'lightgrey',
padding: 0,
minHeight: 400,
margin: '0.5px',
position: 'relative',
height: 'auto',
zoom: 1,
display: 'block',
});
export default class CellDesigner extends React.Component {
state = {
cell: new XCell(),
templateCells: [getTextXCell(), getInnerXCell(), getGroupXCell(), getCustomXCell()],
};
constructor(props: any) {
super(props);
let rootCell = getGroupXCell();
rootCell.cell.text = '某某表格';
rootCell.cell.type = CellType.Group;
rootCell.cell.span = 24;
rootCell.child = [];
this.state.cell = rootCell;
// this.onDragEnd = this.onDragEnd.bind(this);
// this.getList = this.getList.bind(this);
}
public onDragEnd = (result: DropResult, provided: HookProvided): void => {
const { source, destination } = result;
console.log(result);
if (!destination) {
return;
}
if (source.droppableId === destination.droppableId) {
if (destination.droppableId === 'workspace') {
} else {
}
} else {
if (destination.droppableId === 'workspace') {
let cur = this.state.templateCells.find(p => p.id.toString() === result.draggableId);
if (cur !== undefined) {
// this.state.cell.
}
} else if (destination.droppableId === 'droppableTemplate') {
} else {
if (destination.droppableId === this.state.cell.id.toString()) {
let cur = this.state.templateCells.find(p => p.id.toString() === result.draggableId);
let nodes = this.state.cell.child;
if (cur !== undefined) {
nodes.push(this.createXCell(cur));
}
this.setState({
...this.state,
cell: {
...this.state.cell,
child: nodes,
},
});
}
}
}
//调整
};
createXCell = (cell: XCell): XCell => {
let cur = JSON.parse(JSON.stringify(cell));
cur.id = Guid.create();
return cur;
};
onDragStart = (initial: DragStart, provided: HookProvided): void => {};
buildCell = (cell: XCell, index: number): JSX.Element => {
if (cell.cell.type === CellType.Text || cell.cell.type === undefined) {
return (