page.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 { ArticleChannel } from '../../../../Constant';
  12. import { System } from '../../../stores/system';
  13. const ArticleChannelMap = getMap(ArticleChannel, 'value', 'label');
  14. export default class extends Page {
  15. init() {
  16. this.filterForm = [{
  17. key: 'channel',
  18. type: 'select',
  19. allowClear: true,
  20. name: '频道',
  21. select: ArticleChannel,
  22. placeholder: '请选择',
  23. }, {
  24. key: 'position',
  25. type: 'select',
  26. allowClear: true,
  27. name: '位置',
  28. select: [],
  29. placeholder: '请选择',
  30. }];
  31. this.actionList = [{
  32. key: 'add',
  33. type: 'primary',
  34. name: '创建',
  35. render: (item) => {
  36. return <Link to='/show/article/detail'><Button>{item.name}</Button></Link>;
  37. },
  38. }];
  39. this.columns = [{
  40. title: '频道',
  41. dataIndex: 'channel',
  42. render: (text) => {
  43. return ArticleChannelMap[text] || '';
  44. },
  45. }, {
  46. title: '位置',
  47. dataIndex: 'position',
  48. }, {
  49. title: '文章标题',
  50. dataIndex: 'title',
  51. }, {
  52. title: '更新时间',
  53. dataIndex: 'updateTime',
  54. render: (text) => {
  55. return formatDate(text);
  56. },
  57. }, {
  58. title: '操作',
  59. dataIndex: 'handler',
  60. render: (text, record) => {
  61. return <div className="table-button">
  62. {<Link to={`/show/article/detail/${record.id}`}>编辑</Link>}
  63. </div>;
  64. },
  65. }];
  66. }
  67. initData() {
  68. System.listArticle(this.state.search).then(result => {
  69. this.setTableData(result.list, result.total);
  70. });
  71. }
  72. renderView() {
  73. return <Block flex>
  74. <FilterLayout
  75. show
  76. itemList={this.filterForm}
  77. data={this.state.search}
  78. onChange={data => {
  79. this.search(data);
  80. }} />
  81. <ActionLayout
  82. itemList={this.actionList}
  83. selectedKeys={this.state.selectedKeys}
  84. onAction={key => this.onAction(key)}
  85. />
  86. <TableLayout
  87. select
  88. columns={this.tableSort(this.columns)}
  89. list={this.state.list}
  90. pagination={this.state.page}
  91. loading={this.props.core.loading}
  92. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  93. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  94. selectedKeys={this.state.selectedKeys}
  95. />
  96. </Block>;
  97. }
  98. }