Commit 43523b78 authored by 杨子龙's avatar 杨子龙

优化控件

parent 0921bc5c
......@@ -4795,12 +4795,11 @@ const advancedWidgets = [
icon: <IconPack.AreaTask />,
schema: {
title: '数据表格',
type: 'array',
type: 'number',
widget: 'DataTable',
placeholder: '',
width: '100%',
labelWidth: 1,
default: []
},
setting: {
widget: {
......
import React, { Fragment, useEffect } from 'react';
import React, { Fragment, useEffect , useState } from 'react';
import {Button, Empty, Table, Space, Input} from 'antd';
import {CheckOutlined} from "@ant-design/icons";
import * as AntdIcon from '@ant-design/icons';
import FileView from '../../../Account/components/TablePack/components/FileView';
import TagPack from '../../../components/TagPack'
import eventEmitter from '../../../../utils/eventEmitter'
import styles from './index.less';
const DataTable = props => {
const { value, onChange, schema } = props;
const { value, onChange, schema , addons } = props;
const {
disabled,
fieldList,
......@@ -20,17 +21,20 @@ const DataTable = props => {
statusOption
} = schema;
const [dataSource , setDataSource] = useState([]);
const [visible , setVisible] = useState(true);
const hasHash = (url) => {
return url.includes('#');
}
const doAction = (_, row, index , actionItem) => {
const list = [...value];
const list = [...dataSource];
switch (actionItem.action) {
case "delete":
list.splice(index , 1);
onChange(list);
setDataSource(list);
break;
case "update":
list.forEach((item , i) => {
......@@ -43,7 +47,7 @@ const DataTable = props => {
}
}
});
onChange(list);
setDataSource(list);
break;
case "href":
if(!row.isEditable){
......@@ -78,7 +82,7 @@ const DataTable = props => {
}
const changeValue = (val, index, type) => {
const list = [...value];
const list = [...dataSource];
list.forEach((item , i) => {
if(i === index){
......@@ -86,7 +90,7 @@ const DataTable = props => {
}
})
onChange(list);
setDataSource(list);
}
// 操作栏渲染
......@@ -241,13 +245,31 @@ const DataTable = props => {
useEffect(() => {
getData();
return () => {
eventEmitter.removeListener(addons?.dataPath)
}
}, []);
useEffect(() => {
eventEmitter.on(addons?.dataPath , (res) => {
setVisible(false);
res.forEach((item , index) => {
item.key = index;
})
setDataSource(res);
setVisible(true);
onChange(res.length)
})
}, []);
return (
<Fragment>
<div className={styles.dataTable}>
<div className={styles.tableTitle}>{titleShow}</div>
{columns.length !== 0 ? (
{visible && columns.length !== 0 ? (
<Table
size="small"
rowKey={disabled ? 'gis-设备编号' : 'ID'}
......@@ -258,7 +280,7 @@ const DataTable = props => {
x: scrollX,
y: scrollY
}}
dataSource={value}
dataSource={dataSource}
/>
) : (
<Empty />
......
const events = require("events")
const eventEmitter = new events.EventEmitter();
export default 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