intimate_view/src/Table.js

230 lines
4.9 KiB
JavaScript
Raw Normal View History

2020-08-18 11:22:29 +00:00
import React, { useState } from 'react';
2020-08-23 16:23:43 +00:00
import { Table, Input, Select, Tag, Row, Col } from 'antd';
import './Table.less';
import apihost from './Var';
const { Option } = Select;
2020-08-18 11:22:29 +00:00
2020-08-19 11:32:01 +00:00
const columns = [
2020-08-23 16:23:43 +00:00
{
title: '平台',
dataIndex: 'Platform',
editable: false,
key: 'Platform',
2020-08-19 11:32:01 +00:00
// width: "8%",
2020-08-23 16:23:43 +00:00
},
{
title: 'userid',
dataIndex: 'UserId',
editable: false,
key: 'UserId',
2020-08-19 11:32:01 +00:00
// width: "7%",
2020-08-23 16:23:43 +00:00
},
{
title: '名称',
dataIndex: 'UserName',
editable: false,
key: 'UserName',
// width: "7%",
},
{
title: '标签',
dataIndex: 'Tags',
editable: false,
render: tags => (
<>
{
tags != null ?
tags.map(tag => {
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>
);
}
) : null}
</>)
},
{
title: '粉丝数(关注)',
dataIndex: 'Followers',
key: 'Followers',
width: "8%",
},
{
title: '礼物数(币|钱)',
dataIndex: 'Gratuity',
key: 'Gratuity',
width: "8%",
sorter: (a, b) => a.Gratuity - b.Gratuity,
// sortOrder: sortedInfo.columnKey === 'Gratuity' && sortedInfo.order,
ellipsis: true,
2020-08-23 16:23:43 +00:00
},
{
title: '数据更新时间',
dataIndex: 'UpdateTime',
key: 'UpdateTime',
// width: "7%",
},
];
2020-08-19 11:32:01 +00:00
2020-08-23 16:23:43 +00:00
class DataTable extends React.Component {
2020-08-19 11:32:01 +00:00
2020-08-23 16:23:43 +00:00
state = {
data: [],
platform: "openrec",
pagination: {
current: 1,
pageSize: 20,
position: ["topLeft"],
},
loading: false,
};
2020-08-20 11:29:22 +00:00
2020-08-23 16:23:43 +00:00
expandedRow = (record) => {
const ecolumns = [
{
title: 'uid',
dataIndex: 'Uid',
key: 'Uid',
},
{
title: '直播地址',
dataIndex: 'LiveUrl',
key: 'LiveUrl',
},
{
title: '直播标题',
dataIndex: 'LiveTitle',
key: 'LiveTitle',
},
{
title: '近直播开始时间',
dataIndex: 'LiveStartTime',
key: 'LiveStartTime',
},
{
title: '近直播结束时间',
dataIndex: 'LiveEndTime',
key: 'LiveEndTime',
},
];
var data = [record];
return <Table rowClassName="subtable" size="small" bordered={true} columns={ecolumns} dataSource={data} pagination={false} />;
};
2020-08-20 11:29:22 +00:00
2020-08-23 16:23:43 +00:00
updatePlatform(p) {
const { pagination } = this.state;
pagination.current = 1;
this.setState({ platform: p }, () => {
this.fetchapi({
2020-08-23 16:23:43 +00:00
pagination
});
});
}
componentDidMount() {
const { platform } = this.state;
this.updatePlatform(platform);
}
handleTableChange = (pagination, filters, sorter) => {
console.log(filters, sorter);
this.fetchapi({
2020-08-23 16:23:43 +00:00
sortField: sorter.field,
sortOrder: sorter.order,
pagination,
...filters,
});
};
2020-08-19 11:32:01 +00:00
fetchapi = (params = {}) => {
2020-08-23 16:23:43 +00:00
this.setState({ loading: true });
const { platform, pagination } = this.state;
2020-08-19 11:32:01 +00:00
2020-08-23 16:23:43 +00:00
fetch(`${apihost}/${platform}/query?page=${pagination.current}&psize=${pagination.pageSize}`, { mode: "cors" }).then((response) => {
// console.log(response);
2020-08-23 16:23:43 +00:00
response.json().then(
(data) => {
2020-08-19 11:32:01 +00:00
var result = JSON.parse(data)
this.setState({
loading: false,
2020-08-23 16:23:43 +00:00
data: result.Data ? result.Data : [],
2020-08-19 11:32:01 +00:00
pagination: {
...params.pagination,
total: 100000,
},
});
2020-08-23 16:23:43 +00:00
}
)
})
};
2020-08-18 11:22:29 +00:00
2020-08-23 16:23:43 +00:00
render() {
const { data, pagination, loading } = this.state;
return (
<div>
{/* <Row justify="start">
2020-08-23 16:23:43 +00:00
<Col span={6}>
<Input.Group compact size="small">
<Select size="small" defaultValue="operator">
<Option value="operator">operator</Option>
<Option value="uid">uid</Option>
</Select>
<Input size="small" style={{ width: '50%' }} defaultValue="123" />
</Input.Group>
</Col>
<Col span={6}>
<Input.Group compact size="small">
<Select size="small" defaultValue="Zhejiang">
<Option value="Zhejiang">Zhejiang</Option>
<Option value="Jiangsu">Jiangsu</Option>
</Select>
<Input size="small" style={{ width: '50%' }} defaultValue="Xihu District, Hangzhou" />
</Input.Group>
</Col>
</Row> */}
2020-08-23 16:23:43 +00:00
<Table
bordered={true}
size={"middle"}
columns={columns}
dataSource={data}
pagination={pagination}
loading={loading}
onChange={this.handleTableChange}
expandable={{
expandedRowRender: this.expandedRow
}} />
</div>
);
}
};
2020-08-18 11:22:29 +00:00
export default DataTable;
//