page.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import { Button } from 'antd';
  4. import './index.less';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. import FilterLayout from '@src/layouts/FilterLayout';
  8. import ActionLayout from '@src/layouts/ActionLayout';
  9. import TableLayout from '@src/layouts/TableLayout';
  10. import { formatDate, getMap } from '@src/services/Tools';
  11. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  12. // import { ArticleChannel } from '../../../../Constant';
  13. import { Ready } from '../../../stores/ready';
  14. // const ArticleChannelMap = getMap(ArticleChannel, 'value', 'label');
  15. export default class extends Page {
  16. init() {
  17. this.categoryMap = {};
  18. this.categoryList = [];
  19. this.filterForm = [{
  20. key: 'parentCategoryId',
  21. type: 'select',
  22. allowClear: true,
  23. name: '一级标题',
  24. placeholder: '请选择',
  25. select: [],
  26. number: true,
  27. onChange: (value) => {
  28. this.changeSearch(this.filterForm, this, value);
  29. },
  30. }, {
  31. key: 'categoryId',
  32. type: 'select',
  33. allowClear: true,
  34. name: '二级标题',
  35. select: [],
  36. number: true,
  37. placeholder: '请选择',
  38. }];
  39. this.actionList = [{
  40. key: 'add',
  41. type: 'primary',
  42. name: '创建',
  43. render: (item) => {
  44. return <Link to='/ready/article/detail'><Button>{item.name}</Button></Link>;
  45. },
  46. }];
  47. this.columns = [{
  48. title: '一级标题',
  49. dataIndex: 'parentCategoryId',
  50. render: (text) => {
  51. return this.categoryMap[text];
  52. },
  53. }, {
  54. title: '二级标题',
  55. dataIndex: 'categoryId',
  56. render: (text) => {
  57. return this.categoryMap[text];
  58. },
  59. }, {
  60. title: '文章标题',
  61. dataIndex: 'title',
  62. }, {
  63. title: '更新时间',
  64. dataIndex: 'updateTime',
  65. render: (text) => {
  66. return formatDate(text);
  67. },
  68. }, {
  69. title: '操作',
  70. dataIndex: 'handler',
  71. render: (text, record) => {
  72. return <div className="table-button">
  73. {<Link to={`/ready/article/detail/${record.id}`}>编辑</Link>}
  74. {<a onClick={() => {
  75. this.deleteAction(record);
  76. }}>删除</a>}
  77. </div>;
  78. },
  79. }];
  80. Ready.allCategory().then(result => {
  81. this.categoryList = result.map(row => {
  82. row.value = row.id;
  83. return row;
  84. });
  85. this.categoryMap = getMap(result, 'id', 'title');
  86. this.filterForm[0].select = this.categoryList.filter(row => row.parentId === 0);
  87. this.onChangeSearch(this.filterForm, this, this.state.search.parentCategoryId);
  88. this.initData();
  89. });
  90. }
  91. changeSearch(list, component, value) {
  92. if (value) {
  93. list[1].disabled = false;
  94. list[1].select = this.categoryList.filter(row => row.parentId === value);
  95. } else {
  96. list[1].disabled = true;
  97. list[1].select = [];
  98. }
  99. component.setState({ load: false });
  100. }
  101. initData() {
  102. Ready.listArticle(this.state.search).then(result => {
  103. this.setTableData(result.list, result.total);
  104. });
  105. }
  106. deleteAction(row) {
  107. asyncDelConfirm('删除确认', '是否删除选中?', () => {
  108. const handler = Ready.delArticle({ id: row.id });
  109. return handler.then(() => {
  110. asyncSMessage('删除成功!');
  111. this.refresh();
  112. });
  113. });
  114. }
  115. renderView() {
  116. return <Block flex>
  117. <FilterLayout
  118. show
  119. itemList={this.filterForm}
  120. data={this.state.search}
  121. onChange={data => {
  122. this.search(data);
  123. }} />
  124. <ActionLayout
  125. itemList={this.actionList}
  126. selectedKeys={this.state.selectedKeys}
  127. onAction={key => this.onAction(key)}
  128. />
  129. <TableLayout
  130. columns={this.tableSort(this.columns)}
  131. list={this.state.list}
  132. pagination={this.state.page}
  133. loading={this.props.core.loading}
  134. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  135. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  136. selectedKeys={this.state.selectedKeys}
  137. />
  138. </Block>;
  139. }
  140. }