|
@@ -1,13 +1,15 @@
|
|
-import { Form } from 'antd';
|
|
|
|
|
|
+import { Button, Form } from 'antd';
|
|
import React, { useState, useMemo } from 'react';
|
|
import React, { useState, useMemo } from 'react';
|
|
import {
|
|
import {
|
|
ArrowUpOutlined,
|
|
ArrowUpOutlined,
|
|
ArrowDownOutlined,
|
|
ArrowDownOutlined,
|
|
DeleteOutlined,
|
|
DeleteOutlined,
|
|
|
|
+ PlusOutlined,
|
|
} from '@ant-design/icons';
|
|
} from '@ant-design/icons';
|
|
|
|
+import position from '../Flow/node/fields/position';
|
|
|
|
|
|
function FormContent(props) {
|
|
function FormContent(props) {
|
|
- const { list, onChange, onSelect } = props;
|
|
|
|
|
|
+ const { list, onChange, onSelect, onTableColumnChange } = props;
|
|
const [currentItem, setCurrentItem] = useState(null);
|
|
const [currentItem, setCurrentItem] = useState(null);
|
|
|
|
|
|
const linkedList = useMemo(() => {
|
|
const linkedList = useMemo(() => {
|
|
@@ -41,22 +43,24 @@ function FormContent(props) {
|
|
_list[index] = temp;
|
|
_list[index] = temp;
|
|
onChange(_list);
|
|
onChange(_list);
|
|
};
|
|
};
|
|
- const handleSelect = (index) => {
|
|
|
|
- setCurrentItem(index);
|
|
|
|
- onSelect(index);
|
|
|
|
|
|
+
|
|
|
|
+ const handleFormItemClick = (id) => {
|
|
|
|
+ setCurrentItem(id[0]);
|
|
|
|
+ onSelect(id);
|
|
};
|
|
};
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div style={{ width: 500, height: 636, overflow: 'auto' }}>
|
|
<div style={{ width: 500, height: 636, overflow: 'auto' }}>
|
|
{list.map((item, index) => {
|
|
{list.map((item, index) => {
|
|
const btns = (
|
|
const btns = (
|
|
<>
|
|
<>
|
|
- {index != 0 && (
|
|
|
|
|
|
+ {index !== 0 && (
|
|
<ArrowUpOutlined
|
|
<ArrowUpOutlined
|
|
style={{ marginLeft: 5, cursor: 'pointer' }}
|
|
style={{ marginLeft: 5, cursor: 'pointer' }}
|
|
onClick={() => handleUp(index)}
|
|
onClick={() => handleUp(index)}
|
|
/>
|
|
/>
|
|
)}
|
|
)}
|
|
- {index != list.length - 1 && (
|
|
|
|
|
|
+ {index !== list.length - 1 && (
|
|
<ArrowDownOutlined
|
|
<ArrowDownOutlined
|
|
style={{ marginLeft: 5, cursor: 'pointer' }}
|
|
style={{ marginLeft: 5, cursor: 'pointer' }}
|
|
onClick={() => handleDown(index)}
|
|
onClick={() => handleDown(index)}
|
|
@@ -68,14 +72,16 @@ function FormContent(props) {
|
|
/>
|
|
/>
|
|
</>
|
|
</>
|
|
);
|
|
);
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<FormItem
|
|
<FormItem
|
|
key={item.props?.id}
|
|
key={item.props?.id}
|
|
islinked={
|
|
islinked={
|
|
- linkedList?.findIndex((id) => id == item.props?.id) !== -1
|
|
|
|
|
|
+ linkedList?.findIndex((id) => id === item.props?.id) !== -1
|
|
} //不等于-1表示是被单选框关联的组件需要置灰
|
|
} //不等于-1表示是被单选框关联的组件需要置灰
|
|
- active={index == currentItem}
|
|
|
|
- onClick={() => handleSelect(index)}
|
|
|
|
|
|
+ active={item.props?.id === currentItem}
|
|
|
|
+ onClick={handleFormItemClick}
|
|
|
|
+ onTableColumnChange={onTableColumnChange}
|
|
item={item}
|
|
item={item}
|
|
btns={btns}
|
|
btns={btns}
|
|
/>
|
|
/>
|
|
@@ -86,8 +92,46 @@ function FormContent(props) {
|
|
}
|
|
}
|
|
|
|
|
|
function FormItem(props) {
|
|
function FormItem(props) {
|
|
- const { item, btns, active, onClick, islinked = false } = props;
|
|
|
|
|
|
+ const {
|
|
|
|
+ item,
|
|
|
|
+ btns,
|
|
|
|
+ active,
|
|
|
|
+ onClick,
|
|
|
|
+ onTableColumnChange,
|
|
|
|
+ islinked = false,
|
|
|
|
+ } = props;
|
|
const { label, placeholder, required } = item.props;
|
|
const { label, placeholder, required } = item.props;
|
|
|
|
+
|
|
|
|
+ // 子控件激活id
|
|
|
|
+ const [selectColumnID, setSelectColumnID] = useState('');
|
|
|
|
+
|
|
|
|
+ // 新增列时通过id定位
|
|
|
|
+ const addTableColumn = (event) => {
|
|
|
|
+ // 记录当前表格uuid
|
|
|
|
+ onTableColumnChange(item.props.id);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 修改表格内部的控件顺序
|
|
|
|
+ const changeIndex = (index, operate) => {
|
|
|
|
+ let newCol = [...item.columns];
|
|
|
|
+ const prev = newCol[index - 1];
|
|
|
|
+ const next = newCol[index + 1];
|
|
|
|
+ switch (operate) {
|
|
|
|
+ case 'up':
|
|
|
|
+ newCol[index - 1] = newCol[index];
|
|
|
|
+ newCol[index] = prev;
|
|
|
|
+ break;
|
|
|
|
+ case 'down':
|
|
|
|
+ newCol[index + 1] = newCol[index];
|
|
|
|
+ newCol[index] = next;
|
|
|
|
+ break;
|
|
|
|
+ case 'delete':
|
|
|
|
+ newCol.splice(index, 1);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ onTableColumnChange(item.props.id, newCol);
|
|
|
|
+ };
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div
|
|
<div
|
|
style={{
|
|
style={{
|
|
@@ -95,13 +139,24 @@ function FormItem(props) {
|
|
marginBottom: 20,
|
|
marginBottom: 20,
|
|
padding: '4px 12px',
|
|
padding: '4px 12px',
|
|
border: islinked ? '1px solid #bebcbc' : '1px solid #666',
|
|
border: islinked ? '1px solid #bebcbc' : '1px solid #666',
|
|
- borderLeft: active ? '10px solid #1890FF' : '1px solid #666',
|
|
|
|
|
|
+ borderLeft:
|
|
|
|
+ active && !item.isTable ? '10px solid #1890FF' : '1px solid #666',
|
|
|
|
+ }}
|
|
|
|
+ onClick={(e) => {
|
|
|
|
+ // 停止冒泡
|
|
|
|
+ e.stopPropagation();
|
|
|
|
+ if (item.isColumn === undefined) {
|
|
|
|
+ // 触发正常的事件
|
|
|
|
+ onClick([item.props.id]);
|
|
|
|
+ } else {
|
|
|
|
+ // 触发列中的click事件
|
|
|
|
+ onClick();
|
|
|
|
+ }
|
|
}}
|
|
}}
|
|
- onClick={onClick}
|
|
|
|
>
|
|
>
|
|
<div
|
|
<div
|
|
style={{
|
|
style={{
|
|
- fontSzie: 24,
|
|
|
|
|
|
+ fontSize: 16,
|
|
color: '#000',
|
|
color: '#000',
|
|
fontWeight: 'bold',
|
|
fontWeight: 'bold',
|
|
position: 'relative',
|
|
position: 'relative',
|
|
@@ -120,7 +175,61 @@ function FormItem(props) {
|
|
{btns}
|
|
{btns}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
- <div style={{ color: '#999', fontSize: 16 }}>{placeholder}</div>
|
|
|
|
|
|
+ {item.isTable ? (
|
|
|
|
+ <div style={{ padding: '10px 0 5px 0' }}>
|
|
|
|
+ {item.columns.map((column, index) => {
|
|
|
|
+ // column的按钮和外部的控件按钮不一样
|
|
|
|
+ const colBtns = (
|
|
|
|
+ <>
|
|
|
|
+ {index !== 0 && (
|
|
|
|
+ <ArrowUpOutlined
|
|
|
|
+ style={{ marginLeft: 5, cursor: 'pointer' }}
|
|
|
|
+ onClick={() => {
|
|
|
|
+ changeIndex(index, 'up');
|
|
|
|
+ }}
|
|
|
|
+ />
|
|
|
|
+ )}
|
|
|
|
+ {index !== item.columns.length - 1 && (
|
|
|
|
+ <ArrowDownOutlined
|
|
|
|
+ style={{ marginLeft: 5, cursor: 'pointer' }}
|
|
|
|
+ onClick={() => {
|
|
|
|
+ changeIndex(index, 'down');
|
|
|
|
+ }}
|
|
|
|
+ />
|
|
|
|
+ )}
|
|
|
|
+ <DeleteOutlined
|
|
|
|
+ style={{ marginLeft: 5, cursor: 'pointer' }}
|
|
|
|
+ onClick={() => {
|
|
|
|
+ changeIndex(index, 'delete');
|
|
|
|
+ }}
|
|
|
|
+ />
|
|
|
|
+ </>
|
|
|
|
+ );
|
|
|
|
+ return (
|
|
|
|
+ <FormItem
|
|
|
|
+ key={column.props?.id}
|
|
|
|
+ item={column}
|
|
|
|
+ active={active && column.props?.id === selectColumnID}
|
|
|
|
+ onClick={() => {
|
|
|
|
+ setSelectColumnID(column.props.id);
|
|
|
|
+ onClick([item.props.id, column.props.id]);
|
|
|
|
+ }}
|
|
|
|
+ btns={colBtns}
|
|
|
|
+ />
|
|
|
|
+ );
|
|
|
|
+ })}
|
|
|
|
+ <Button
|
|
|
|
+ type="dashed"
|
|
|
|
+ block
|
|
|
|
+ onClick={addTableColumn}
|
|
|
|
+ icon={<PlusOutlined />}
|
|
|
|
+ >
|
|
|
|
+ 点击添加列
|
|
|
|
+ </Button>
|
|
|
|
+ </div>
|
|
|
|
+ ) : (
|
|
|
|
+ <div style={{ color: '#999', fontSize: 16 }}>{placeholder}</div>
|
|
|
|
+ )}
|
|
</div>
|
|
</div>
|
|
);
|
|
);
|
|
}
|
|
}
|