commit
59f2bb003b
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index-520b59d8379e5c351e38.js","sources":["webpack:///index-520b59d8379e5c351e38.js"],"mappings":"AAAA;;;;;;;AAuhZA","sourceRoot":""}
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
{"version":3,"file":"index-5c8cbf958683e20086f5.js","sources":["webpack:///index-5c8cbf958683e20086f5.js"],"mappings":"AAAA;;;;;;;AAmsYA","sourceRoot":""}
|
@ -1 +1 @@
|
||||
<!doctype html><html><head><meta charset="UTF-8"><title>Nightingale</title><link rel="shortcut icon" href="/favicon.ico"><link href="/index-5c8cbf958683e20086f5.css" rel="stylesheet"></head><body><div id="react-content"></div><script src="/lib-033bee8514de110e36ef.dll.js"></script><script src="/index-5c8cbf958683e20086f5.js"></script></body></html>
|
||||
<!doctype html><html><head><meta charset="UTF-8"><title>Nightingale</title><link rel="shortcut icon" href="/favicon.ico"><link href="/index-520b59d8379e5c351e38.css" rel="stylesheet"></head><body><div id="react-content"></div><script src="/lib-033bee8514de110e36ef.dll.js"></script><script src="/index-520b59d8379e5c351e38.js"></script></body></html>
|
@ -1,123 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import { Table } from 'antd';
|
||||
import _ from 'lodash';
|
||||
import queryString from 'query-string';
|
||||
import api from '@common/api';
|
||||
import * as config from '@common/config';
|
||||
import request from '@common/request';
|
||||
import './style.less';
|
||||
|
||||
export default class BaseComponent extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.api = api;
|
||||
this.config = config;
|
||||
this.prefixCls = config.appname;
|
||||
this.request = request;
|
||||
this.otherParamsKey = [];
|
||||
this.state = {
|
||||
loading: false,
|
||||
pagination: {
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
showSizeChanger: true,
|
||||
},
|
||||
data: [],
|
||||
searchValue: '',
|
||||
};
|
||||
}
|
||||
|
||||
handleSearchChange = (value) => {
|
||||
this.setState({ searchValue: value }, () => {
|
||||
this.reload({
|
||||
query: value,
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
handleTableChange = (pagination) => {
|
||||
const { pagination: paginationState } = this.state;
|
||||
const pager = {
|
||||
...paginationState,
|
||||
current: pagination.current,
|
||||
pageSize: pagination.pageSize,
|
||||
};
|
||||
this.setState({ pagination: pager }, () => {
|
||||
this.reload({
|
||||
limit: pagination.pageSize,
|
||||
page: pagination.current,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
reload(params) {
|
||||
this.fetchData(params);
|
||||
}
|
||||
|
||||
fetchData(newParams = {}, backFirstPage = false) {
|
||||
const url = this.getFetchDataUrl();
|
||||
|
||||
if (!url) return;
|
||||
const othenParams = _.pick(this.state, this.otherParamsKey);
|
||||
const { pagination, searchValue } = this.state;
|
||||
const params = {
|
||||
limit: pagination.pageSize,
|
||||
p: backFirstPage ? 1 : pagination.current,
|
||||
query: searchValue,
|
||||
...othenParams,
|
||||
...newParams,
|
||||
};
|
||||
|
||||
this.setState({ loading: true });
|
||||
// TODO: Method 'fetchData' expected no return value.
|
||||
// eslint-disable-next-line consistent-return
|
||||
return this.request(`${url}?${queryString(params)}`).then((res) => {
|
||||
const newPagination = {
|
||||
...pagination,
|
||||
current: backFirstPage ? 1 : pagination.current,
|
||||
total: res.total,
|
||||
};
|
||||
let data = [];
|
||||
if (_.isArray(res.list)) {
|
||||
data = res.list;
|
||||
} else if (_.isArray(res)) {
|
||||
data = res;
|
||||
}
|
||||
this.setState({
|
||||
data,
|
||||
pagination: newPagination,
|
||||
});
|
||||
return data;
|
||||
}).finally(() => {
|
||||
this.setState({ loading: false });
|
||||
});
|
||||
}
|
||||
|
||||
renderTable(params) {
|
||||
const { loading, pagination, data } = this.state;
|
||||
return (
|
||||
<Table
|
||||
rowKey="id"
|
||||
size="small"
|
||||
loading={loading}
|
||||
pagination={{
|
||||
...pagination,
|
||||
showTotal: total => `共 ${total} 条数据`,
|
||||
pageSizeOptions: config.defaultPageSizeOptions,
|
||||
onChange: () => {
|
||||
if (this.handlePaginationChange) this.handlePaginationChange();
|
||||
},
|
||||
}}
|
||||
rowClassName={(record, index) => {
|
||||
if (index % 2 === 1) {
|
||||
return 'table-row-bg';
|
||||
}
|
||||
return '';
|
||||
}}
|
||||
dataSource={data}
|
||||
onChange={this.handleTableChange}
|
||||
{...params}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
.table-row-bg {
|
||||
background: #f9f9f9;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue