TODO: fetch mehtod for sort and filter.

This commit is contained in:
eson 2020-08-24 01:14:36 +08:00
parent 3a987464e6
commit e91995fc65
2 changed files with 21 additions and 19 deletions

View File

@ -112,13 +112,13 @@ func Query(cxt *gin.Context, platform string) {
ot := &ObjectQuery{} ot := &ObjectQuery{}
var view, gratuity sql.NullInt64 var view, gratuity sql.NullInt64
var lstm, letm, utm sql.NullTime var lstm, letm, utm sql.NullTime
var tags, livetitle sql.NullString var username, tags, livetitle, liveurl sql.NullString
err = rows.Scan( err = rows.Scan(
&ot.Uid, &ot.Uid,
&ot.Platform, &ot.Platform,
&ot.UserId, &ot.UserId,
&ot.UserName, &username,
&ot.LiveUrl, &liveurl,
&tags, &tags,
&ot.Followers, &ot.Followers,
&view, &view,
@ -160,6 +160,14 @@ func Query(cxt *gin.Context, platform string) {
ot.Gratuity = gratuity.Int64 ot.Gratuity = gratuity.Int64
} }
if username.Valid {
ot.UserName = username.String
}
if liveurl.Valid {
ot.LiveUrl = liveurl.String
}
if err = json.Unmarshal([]byte(tags.String), &ot.Tags); err != nil { if err = json.Unmarshal([]byte(tags.String), &ot.Tags); err != nil {
// log.Println(tags) // log.Println(tags)
} }

View File

@ -66,6 +66,9 @@ const columns = [
dataIndex: 'Gratuity', dataIndex: 'Gratuity',
key: 'Gratuity', key: 'Gratuity',
width: "8%", width: "8%",
sorter: (a, b) => a.Gratuity - b.Gratuity,
// sortOrder: sortedInfo.columnKey === 'Gratuity' && sortedInfo.order,
ellipsis: true,
}, },
{ {
title: '数据更新时间', title: '数据更新时间',
@ -78,15 +81,6 @@ const columns = [
const getRandomuserParams = params => {
return {
psize: params.pagination.pageSize,
page: params.pagination.current,
// ...params,
};
};
class DataTable extends React.Component { class DataTable extends React.Component {
@ -143,7 +137,7 @@ class DataTable extends React.Component {
const { pagination } = this.state; const { pagination } = this.state;
pagination.current = 1; pagination.current = 1;
this.setState({ platform: p }, () => { this.setState({ platform: p }, () => {
this.fetch({ this.fetchapi({
pagination pagination
}); });
}); });
@ -156,8 +150,8 @@ class DataTable extends React.Component {
} }
handleTableChange = (pagination, filters, sorter) => { handleTableChange = (pagination, filters, sorter) => {
// console.log(filters, sorter); console.log(filters, sorter);
this.fetch({ this.fetchapi({
sortField: sorter.field, sortField: sorter.field,
sortOrder: sorter.order, sortOrder: sorter.order,
pagination, pagination,
@ -165,12 +159,12 @@ class DataTable extends React.Component {
}); });
}; };
fetch = (params = {}) => { fetchapi = (params = {}) => {
this.setState({ loading: true }); this.setState({ loading: true });
const { platform, pagination } = this.state; const { platform, pagination } = this.state;
fetch(`${apihost}/${platform}/query?page=${pagination.current}&psize=${pagination.pageSize}`, { mode: "cors" }).then((response) => { fetch(`${apihost}/${platform}/query?page=${pagination.current}&psize=${pagination.pageSize}`, { mode: "cors" }).then((response) => {
console.log(response); // console.log(response);
response.json().then( response.json().then(
(data) => { (data) => {
var result = JSON.parse(data) var result = JSON.parse(data)
@ -193,7 +187,7 @@ class DataTable extends React.Component {
return ( return (
<div> <div>
<Row justify="start"> {/* <Row justify="start">
<Col span={6}> <Col span={6}>
<Input.Group compact size="small"> <Input.Group compact size="small">
<Select size="small" defaultValue="operator"> <Select size="small" defaultValue="operator">
@ -212,7 +206,7 @@ class DataTable extends React.Component {
<Input size="small" style={{ width: '50%' }} defaultValue="Xihu District, Hangzhou" /> <Input size="small" style={{ width: '50%' }} defaultValue="Xihu District, Hangzhou" />
</Input.Group> </Input.Group>
</Col> </Col>
</Row> </Row> */}
<Table <Table
bordered={true} bordered={true}