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

- 暴露事件方法

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