2020-11-13 22:01:14 +08:00
|
|
|
import React, { useEffect, useRef } from 'react';
|
2020-11-11 15:23:39 +08:00
|
|
|
import { Table as AntdTable, Card } from 'antd';
|
|
|
|
import { redirectTo } from '@/components/pages/CollectionLoader/utils';
|
|
|
|
import { Actions } from '@/components/actions';
|
|
|
|
import ViewFactory from '@/components/views';
|
2020-11-13 22:01:14 +08:00
|
|
|
import { request, useRequest } from 'umi';
|
|
|
|
import api from '@/api-client';
|
2020-11-11 15:23:39 +08:00
|
|
|
|
|
|
|
const dataSource = [];
|
|
|
|
for (let i = 0; i < 46; i++) {
|
|
|
|
dataSource.push({
|
|
|
|
id: i,
|
|
|
|
name: `Edward King ${i}`,
|
|
|
|
age: 32,
|
|
|
|
address: `London, Park Lane no. ${i}`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: '姓名',
|
|
|
|
dataIndex: 'name',
|
|
|
|
key: 'name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '年龄',
|
|
|
|
dataIndex: 'age',
|
|
|
|
key: 'age',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '住址',
|
|
|
|
dataIndex: 'address',
|
|
|
|
key: 'address',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-11-13 22:01:14 +08:00
|
|
|
export interface SimpleTableProps {
|
|
|
|
schema?: any;
|
|
|
|
activeTab?: any;
|
|
|
|
resourceName: string;
|
|
|
|
associatedName?: string;
|
|
|
|
associatedKey?: string;
|
|
|
|
[key: string]: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function SimpleTable(props: SimpleTableProps) {
|
2020-11-11 15:23:39 +08:00
|
|
|
console.log(props);
|
2020-11-13 22:01:14 +08:00
|
|
|
const {
|
|
|
|
activeTab = {},
|
|
|
|
pageInfo = {},
|
|
|
|
schema,
|
|
|
|
resourceName,
|
|
|
|
associatedName,
|
|
|
|
associatedKey,
|
|
|
|
} = props;
|
|
|
|
const { fields, viewCollectionName, rowViewName, actions = [] } = schema;
|
|
|
|
const { sourceKey = 'id' } = activeTab.field||{};
|
2020-11-11 15:23:39 +08:00
|
|
|
const drawerRef = useRef<any>();
|
2020-11-13 22:01:14 +08:00
|
|
|
const name = associatedName ? `${associatedName}.${resourceName}` : resourceName;
|
|
|
|
const { data } = useRequest(() => api.resource(name).list({
|
|
|
|
associatedKey,
|
|
|
|
}));
|
|
|
|
console.log(activeTab);
|
2020-11-11 15:23:39 +08:00
|
|
|
return (
|
|
|
|
<Card bordered={false}>
|
|
|
|
<Actions {...props} style={{ marginBottom: 14 }} actions={actions}/>
|
|
|
|
<ViewFactory reference={drawerRef} viewCollectionName={viewCollectionName} viewName={rowViewName}/>
|
2020-11-13 22:01:14 +08:00
|
|
|
<AntdTable dataSource={data} onRow={(data) => ({
|
2020-11-11 15:23:39 +08:00
|
|
|
onClick: () => {
|
|
|
|
drawerRef.current.setVisible(true);
|
|
|
|
},
|
2020-11-13 22:01:14 +08:00
|
|
|
})} columns={fields} />
|
2020-11-11 15:23:39 +08:00
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|