Commit d294f053 authored by 杨子龙's avatar 杨子龙

- 暴露事件方法

parent 8cc5fc64
import React, { Fragment, useEffect, useState } from 'react'; import React, { Fragment, useEffect, useState } from 'react';
import { Button, Empty, Input, Space, Table } from 'antd'; import { Button, Empty, Input, Space, Table, Tooltip } from 'antd';
import * as AntdIcon from '@ant-design/icons'; import * as AntdIcon from '@ant-design/icons';
import FileView from '../../../Account/components/TablePack/components/FileView'; import FileView from '../../../Account/components/TablePack/components/FileView';
import TagPack from '../../../components/TagPack'; import TagPack from '../../../components/TagPack';
...@@ -23,7 +23,7 @@ const DataTable = props => { ...@@ -23,7 +23,7 @@ const DataTable = props => {
areaTaskShine, areaTaskShine,
optionWidth, optionWidth,
optionFixed, optionFixed,
isOpenRowEvent isOpenRowEvent,
} = schema; } = schema;
const [dataSource, setDataSource] = useState([]); const [dataSource, setDataSource] = useState([]);
...@@ -35,8 +35,6 @@ const DataTable = props => { ...@@ -35,8 +35,6 @@ const DataTable = props => {
switch (actionItem.action) { switch (actionItem.action) {
case 'delete': case 'delete':
list.splice(index, 1);
setDataSource(list);
break; break;
case 'update': case 'update':
list.forEach((item, i) => { list.forEach((item, i) => {
...@@ -81,18 +79,27 @@ const DataTable = props => { ...@@ -81,18 +79,27 @@ const DataTable = props => {
if (type === 'icon') { if (type === 'icon') {
const Icon = AntdIcon[item.value]; const Icon = AntdIcon[item.value];
if(Icon){ if (Icon) {
otherProps = { otherProps = {
type: 'text', type: 'text',
shape: 'circle', shape: 'circle',
icon: <Icon />, icon: <Icon />,
}; };
} }
} }
Element = ( Element = (
<Button size={'small'} key={i} onClick={() => doAction(_, row, index, item)} type={type} {...otherProps}> <Button
size={'small'}
key={i}
onClick={e => {
e.stopPropagation();
doAction(_, row, index, item);
}}
type={type}
{...otherProps}
>
{type !== 'icon' && item.value} {type !== 'icon' && item.value}
</Button> </Button>
); );
...@@ -106,16 +113,15 @@ const DataTable = props => { ...@@ -106,16 +113,15 @@ const DataTable = props => {
let otherProps = {}; let otherProps = {};
if (type === 'icon') { if (type === 'icon') {
const Icon = AntdIcon[json[field]?.label]; const Icon = AntdIcon[json[field]?.label];
if(Icon){ if (Icon) {
otherProps = { otherProps = {
type: 'text', type: 'text',
shape: 'circle', shape: 'circle',
icon: <Icon style={{color:json[_[item.value]]?.color}} />, icon: <Icon style={{ color: json[_[item.value]]?.color }} />,
}; };
} }
} }
if (optionCode) { if (optionCode) {
if (field) { if (field) {
const codeStr = `return row[item.value] === "${field}"${optionCode}`; const codeStr = `return row[item.value] === "${field}"${optionCode}`;
...@@ -180,15 +186,22 @@ const DataTable = props => { ...@@ -180,15 +186,22 @@ const DataTable = props => {
// 字段栏显示模式渲染 // 字段栏显示模式渲染
const getFieldRender = (_, row, index, item) => { const getFieldRender = (_, row, index, item) => {
let ele; let ele;
switch (item.type) { switch (item.type) {
case '文本': case '文本':
if (!item.isMapped) { if (!item.isMapped) {
ele = <span style={{ color: item.color }}>{_}</span>; ele = (
<Tooltip placement="topLeft" title={_}>
<span style={{ color: item.color }}>{_}</span>
</Tooltip>
);
} else { } else {
if (item.parseStr) { if (item.parseStr) {
const json = JSON.parse(item.parseStr); const json = JSON.parse(item.parseStr);
ele = <span style={{ color: json[_]?.color }}>{json[_]?.label}</span>; ele = (
<Tooltip placement="topLeft" title={json[_]?.label}>
<span style={{ color: json[_]?.color }}>{json[_]?.label}</span>
</Tooltip>
);
} else { } else {
ele = <span>调试中...</span>; ele = <span>调试中...</span>;
} }
...@@ -207,19 +220,7 @@ const DataTable = props => { ...@@ -207,19 +220,7 @@ const DataTable = props => {
} }
break; break;
case 'FileUpload': case 'FileUpload':
ele = <FileView value={_} download={true} preview={true} />; ele = _ && <FileView value={_} download={true} preview={true} />;
break;
default:
if (!item.isMapped) {
ele = <span style={{ color: item.color }}>{_}</span>;
} else {
if (item.parseStr) {
const json = JSON.parse(item.parseStr);
ele = <span style={{ color: json[_]?.color }}>{json[_]?.label}</span>;
} else {
ele = <span>调试中...</span>;
}
}
break; break;
} }
...@@ -245,6 +246,9 @@ const DataTable = props => { ...@@ -245,6 +246,9 @@ const DataTable = props => {
dataIndex, dataIndex,
key: dataIndex, key: dataIndex,
width: item.width || 120, width: item.width || 120,
ellipsis: {
showTitle: false,
},
fixed: item.fixed || false, fixed: item.fixed || false,
render: (_, row, index) => { render: (_, row, index) => {
return ( return (
...@@ -266,7 +270,7 @@ const DataTable = props => { ...@@ -266,7 +270,7 @@ const DataTable = props => {
dataIndex: '', dataIndex: '',
key: '', key: '',
width: optionWidth || 120, width: optionWidth || 120,
fixed: optionFixed, fixed: optionFixed || false,
render: (_, row, index) => { render: (_, row, index) => {
return getOptionRender(_, row, index); return getOptionRender(_, row, index);
}, },
...@@ -327,16 +331,18 @@ const DataTable = props => { ...@@ -327,16 +331,18 @@ const DataTable = props => {
window.relationForm.data = data; window.relationForm.data = data;
}; };
const rowClickEvent = (record) => { const rowClickEvent = record => {
return { return {
onClick: () => { onClick: e => {
e.stopPropagation();
eventEmitter.emit(`${addons?.dataPath}_event`, { eventEmitter.emit(`${addons?.dataPath}_event`, {
...record, ...record,
action: "rowOnClick", action: 'rowOnClick',
}); });
} },
} };
} };
useEffect(() => { useEffect(() => {
eventEmitter.removeAllListeners(addons?.dataPath); eventEmitter.removeAllListeners(addons?.dataPath);
...@@ -368,7 +374,7 @@ const DataTable = props => { ...@@ -368,7 +374,7 @@ const DataTable = props => {
useEffect(() => { useEffect(() => {
getColumns(); getColumns();
}, [fieldList, dataSource , optionRender]); }, [fieldList, dataSource, optionRender]);
useEffect(() => { useEffect(() => {
initRelationForm(); initRelationForm();
...@@ -393,9 +399,7 @@ const DataTable = props => { ...@@ -393,9 +399,7 @@ const DataTable = props => {
y: scrollY, y: scrollY,
} }
} }
onRow={ onRow={record => isOpenRowEvent && rowClickEvent(record)}
record => isOpenRowEvent && rowClickEvent(record)
}
dataSource={dataSource} dataSource={dataSource}
/> />
) : ( ) : (
......
...@@ -3,6 +3,7 @@ import FormDesigner from './core/FormDesigner' ...@@ -3,6 +3,7 @@ import FormDesigner from './core/FormDesigner'
import Account from './core/Account' import Account from './core/Account'
import FileView from './core/Account/components/TablePack/components/FileView' import FileView from './core/Account/components/TablePack/components/FileView'
import { getFieldInfo } from './utils' import { getFieldInfo } from './utils'
import EventEmitter from "./utils/eventEmitter";
export { export {
FormRender, FormRender,
...@@ -10,4 +11,5 @@ export { ...@@ -10,4 +11,5 @@ export {
Account, Account,
FileView, FileView,
getFieldInfo, getFieldInfo,
EventEmitter
} }
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