intimate_view/src/Table.js

212 lines
4.8 KiB
JavaScript
Raw Normal View History

2020-08-18 19:22:29 +08:00
import React, { useState } from 'react';
2020-08-19 19:32:01 +08:00
import { Table, Input, InputNumber, Popconfirm, Form, Tag } from 'antd';
2020-08-18 19:22:29 +08:00
import reqwest from 'reqwest';
2020-08-20 19:29:22 +08:00
import './Table.less';
2020-08-19 19:32:01 +08:00
import { useForm } from 'antd/lib/form/Form';
2020-08-18 19:22:29 +08:00
2020-08-19 19:32:01 +08:00
const columns = [
2020-08-18 19:22:29 +08:00
{
title: '平台',
2020-08-19 19:32:01 +08:00
dataIndex: 'Platform',
2020-08-18 19:22:29 +08:00
editable: false,
2020-08-20 19:29:22 +08:00
key: 'Platform',
2020-08-19 19:32:01 +08:00
// width: "8%",
2020-08-18 19:22:29 +08:00
},
{
2020-08-19 19:32:01 +08:00
title: 'userid',
dataIndex: 'UserId',
2020-08-18 19:22:29 +08:00
editable: false,
2020-08-20 19:29:22 +08:00
key: 'UserId',
2020-08-19 19:32:01 +08:00
// width: "7%",
2020-08-18 19:22:29 +08:00
},
{
2020-08-19 19:32:01 +08:00
title: '名称',
dataIndex: 'UserName',
2020-08-18 19:22:29 +08:00
editable: false,
2020-08-20 19:29:22 +08:00
key: 'UserName',
2020-08-19 19:32:01 +08:00
// width: "7%",
2020-08-18 19:22:29 +08:00
},
{
title: '标签',
2020-08-19 19:32:01 +08:00
dataIndex: 'Tags',
2020-08-18 19:22:29 +08:00
editable: false,
2020-08-19 19:32:01 +08:00
render: tags => (
<>
2020-08-20 19:29:22 +08:00
{
tags != null ?
tags.map( tag => {
2020-08-19 19:32:01 +08:00
let color = "purple";
if (tag.length < 3) {
color = 'green';
} else if (tag.length < 6) {
color = 'geekblue';
} else if (tag.length < 9) {
color = 'volcano';
}
return (
<Tag color={color} key={tag}>
{tag}
</Tag>
);
2020-08-20 19:29:22 +08:00
}
) : null}
2020-08-19 19:32:01 +08:00
</> )
2020-08-18 19:22:29 +08:00
},
{
title: '粉丝数(关注)',
2020-08-19 19:32:01 +08:00
dataIndex: 'Followers',
2020-08-20 19:29:22 +08:00
key: 'Followers',
2020-08-19 19:32:01 +08:00
width: "8%",
2020-08-18 19:22:29 +08:00
},
{
title: '礼物数(币|钱)',
2020-08-19 19:32:01 +08:00
dataIndex: 'Gratuity',
2020-08-20 19:29:22 +08:00
key: 'Gratuity',
2020-08-19 19:32:01 +08:00
width: "8%",
2020-08-18 19:22:29 +08:00
},
{
title: '数据更新时间',
2020-08-19 19:32:01 +08:00
dataIndex: 'UpdateTime',
2020-08-20 19:29:22 +08:00
key: 'UpdateTime',
2020-08-19 19:32:01 +08:00
// width: "7%",
2020-08-18 19:22:29 +08:00
},
];
2020-08-19 19:32:01 +08:00
const getRandomuserParams = params => {
2020-08-18 19:22:29 +08:00
return {
2020-08-19 19:32:01 +08:00
psize: params.pagination.pageSize,
page: params.pagination.current,
// ...params,
2020-08-18 19:22:29 +08:00
};
2020-08-19 19:32:01 +08:00
};
class DataTable extends React.Component {
2020-08-20 19:29:22 +08:00
2020-08-19 19:32:01 +08:00
state = {
data: [],
2020-08-20 19:29:22 +08:00
platform: "openrec",
2020-08-19 19:32:01 +08:00
pagination: {
current: 1,
pageSize: 20,
position: ["topLeft"],
},
loading: false,
};
expandedRow = (record) => {
const ecolumns = [
{
title: 'uid',
dataIndex: 'Uid',
2020-08-20 19:29:22 +08:00
key: 'Uid',
2020-08-19 19:32:01 +08:00
},
2020-08-20 19:29:22 +08:00
{
title: '直播地址',
dataIndex: 'LiveUrl',
key: 'LiveUrl',
},
2020-08-19 19:32:01 +08:00
{
title: '直播标题',
dataIndex: 'LiveTitle',
2020-08-20 19:29:22 +08:00
key: 'LiveTitle',
2020-08-19 19:32:01 +08:00
},
{
title: '近直播开始时间',
dataIndex: 'LiveStartTime',
2020-08-20 19:29:22 +08:00
key: 'LiveStartTime',
2020-08-19 19:32:01 +08:00
},
{
title: '近直播结束时间',
dataIndex: 'LiveEndTime',
2020-08-20 19:29:22 +08:00
key: 'LiveEndTime',
2020-08-19 19:32:01 +08:00
},
];
var data = [record];
2020-08-20 19:29:22 +08:00
return <Table rowClassName="subtable" size="small" bordered={true} columns={ecolumns} dataSource={data} pagination={false} />;
2020-08-19 19:32:01 +08:00
};
2020-08-20 19:29:22 +08:00
updatePlatform(p) {
2020-08-19 19:32:01 +08:00
const { pagination } = this.state;
2020-08-20 19:29:22 +08:00
pagination.current = 1;
this.setState({platform:p}, ()=>{
this.fetch({
pagination
2020-08-19 19:32:01 +08:00
});
2020-08-20 19:29:22 +08:00
});
}
componentDidMount() {
const {platform} = this.state;
this.updatePlatform(platform);
2020-08-19 19:32:01 +08:00
}
handleTableChange = (pagination, filters, sorter) => {
2020-08-20 19:29:22 +08:00
// console.log(filters, sorter);
2020-08-19 19:32:01 +08:00
this.fetch({
sortField: sorter.field,
sortOrder: sorter.order,
pagination,
...filters,
});
};
fetch = (params = {}) => {
this.setState({ loading: true });
2020-08-20 19:29:22 +08:00
const {platform} = this.state;
console.log(platform);
2020-08-19 19:32:01 +08:00
reqwest({
2020-08-20 19:29:22 +08:00
url: 'http://localhost:5500/' + platform + '/query',
2020-08-19 19:32:01 +08:00
method: 'get',
type: 'json',
data: getRandomuserParams(params),
}).then(data => {
var result = JSON.parse(data)
this.setState({
loading: false,
data: result.Data?result.Data:[],
pagination: {
...params.pagination,
total: 100000,
},
});
});
};
render() {
2020-08-20 19:29:22 +08:00
2020-08-19 19:32:01 +08:00
const { data, pagination, loading } = this.state;
2020-08-20 19:29:22 +08:00
return (
2020-08-19 19:32:01 +08:00
<Table
bordered={true}
2020-08-20 19:29:22 +08:00
size={"middle"}
2020-08-19 19:32:01 +08:00
// scroll={{ x: "150vh", y:"800" }}
columns={columns}
dataSource={data}
pagination={pagination}
loading={loading}
onChange={this.handleTableChange}
expandable={{
expandedRowRender: this.expandedRow
}}
/>
);
}
2020-08-18 19:22:29 +08:00
};
export default DataTable;
//