ConfigLabel.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React from 'react';
  2. import { connectAlita } from 'redux-alita';
  3. import { withRouter } from 'react-router-dom';
  4. import { Button, Input, List, message, Modal, Spin, Pagination } from 'antd';
  5. import './styles/label.less';
  6. import AddLabelForm from './widget/AddLabelForm';
  7. class ConfigLabel extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. loading: false,
  12. removeModalTitle: '提示',
  13. removeLoading: false,
  14. removeModalVisible: false,
  15. currentLabel: null,
  16. };
  17. this.params = {
  18. page: 1,
  19. pageSize: 10,
  20. };
  21. }
  22. componentDidMount() {
  23. this._fetchLabels();
  24. }
  25. _fetchLabels() {
  26. this.setState({ currentLabel: null });
  27. let params = this.params;
  28. this.props.setAlitaState({ funcName: 'findPLabel', params });
  29. }
  30. _handleSearch(value) {
  31. this.params.keywords = value;
  32. this._fetchLabels();
  33. }
  34. removeLabel(item) {
  35. let { removeModalTitle } = this.state;
  36. let _this = this;
  37. Modal.confirm({
  38. title: removeModalTitle,
  39. content: `您确定要删除:${item.path} 标签吗?`,
  40. onOk() {
  41. _this.props.setAlitaState({ funcName: 'pLabelDelete', params: item.id })
  42. .then(() => {
  43. message.info('删除失败!');
  44. _this._fetchLabels();
  45. });
  46. },
  47. });
  48. }
  49. renderItem(item) {
  50. return (<List.Item className="prop-label-item">
  51. <div>
  52. <h3 className="label-label">{item.path}</h3>
  53. <span className={'label-title'}>{item.title}</span>
  54. </div>
  55. <div>{item.description}</div>
  56. <div className="tool-btns">
  57. <Button htmlType="button" icon="edit" type="primary" size="small"
  58. onClick={() => this.setState({ currentLabel: item })}/>
  59. <Button htmlType="button" icon="delete" type="danger" size="small"
  60. onClick={this.removeLabel.bind(this, item)}/>
  61. </div>
  62. </List.Item>);
  63. }
  64. render() {
  65. const { data: labelList = {}, isFetching } = this.props.findPLabel || {};
  66. let { records, current, total } = labelList || { total: 0, current: 1, records: [] };
  67. console.log('params: ', this.params);
  68. const { currentLabel } = this.state;
  69. return (<div className="page-label-container">
  70. <div className="prop-label-header">
  71. <Button htmlType="button" type="primary" icon="sync" loading={isFetching}
  72. onClick={() => {
  73. this.params.page = 1;
  74. this._fetchLabels();
  75. }}/>
  76. <Button htmlType="button" icon="plus"
  77. onClick={() => this.setState({ currentLabel: {} })}/>
  78. <Input.Search placeholder="输入关键词查询"
  79. onSearch={this._handleSearch.bind(this)}
  80. className="search-input"/>
  81. </div>
  82. <Spin className="spin" spinning={isFetching} size="large"/>
  83. <List
  84. dataSource={records}
  85. bordered
  86. size="small"
  87. renderItem={this.renderItem.bind(this)}
  88. />
  89. <Pagination defaultCurrent={current}
  90. style={{ marginTop: 10, padding: 10, background: 'white' }}
  91. onChange={(page, pageSize) => {
  92. this.params.page = page;
  93. this.params.pageSize = pageSize;
  94. this._fetchLabels();
  95. }}
  96. total={total}
  97. pageSize={this.params.pageSize}/>
  98. <AddLabelForm cancel={() => this.setState({ currentLabel: null })}
  99. refresh={this._fetchLabels.bind(this)}
  100. visible={!!currentLabel}
  101. label={currentLabel}
  102. />
  103. </div>);
  104. }
  105. }
  106. export default withRouter(connectAlita(['findPLabel'])(ConfigLabel));