page.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import TableLayout from '@src/layouts/TableLayout';
  5. import ActionLayout from '@src/layouts/ActionLayout';
  6. import Block from '@src/components/Block';
  7. import { asyncDelConfirm, asyncForm, asyncSMessage } from '@src/services/AsyncTools';
  8. import { System } from '../../../../stores/system';
  9. const actionList = [
  10. {
  11. key: 'add',
  12. name: '新增',
  13. },
  14. ];
  15. const itemList = [
  16. {
  17. key: 'id',
  18. type: 'hidden',
  19. },
  20. {
  21. key: 'username',
  22. name: '用户名',
  23. type: 'input',
  24. placeholder: '请输入用户名',
  25. require: true,
  26. },
  27. {
  28. key: 'password',
  29. name: '密码',
  30. type: 'password',
  31. placeholder: '请输入密码',
  32. require: true,
  33. },
  34. ];
  35. export default class extends Page {
  36. init() {
  37. this.columns = [
  38. {
  39. title: '用户名',
  40. dataIndex: 'username',
  41. },
  42. {
  43. title: '操作',
  44. dataIndex: 'handler',
  45. render: (text, record) => {
  46. return <div className="table-button">
  47. {(
  48. <a onClick={() => {
  49. this.editAction(record);
  50. }} >编辑</a>
  51. )}
  52. </div>;
  53. },
  54. },
  55. ];
  56. }
  57. initData() {
  58. System.listManager(this.state.search).then(result => {
  59. this.setTableData(result.list, result.total);
  60. });
  61. }
  62. addAction() {
  63. asyncForm('新增', itemList, {}, data => {
  64. return System.addManager(data).then(() => {
  65. asyncSMessage('新增成功!');
  66. this.refresh();
  67. });
  68. });
  69. }
  70. editAction(row) {
  71. asyncForm('编辑', itemList, row, data => {
  72. return System.putManager(data).then(() => {
  73. asyncSMessage('编辑成功!');
  74. this.refresh();
  75. });
  76. });
  77. }
  78. delAction() {
  79. const { selectedKeys } = this.state;
  80. asyncDelConfirm('删除确认', '是否删除选中账号?', () => {
  81. return Promise.all(selectedKeys.map(row => System.delManager({ id: row }))).then(() => {
  82. asyncSMessage('删除成功!');
  83. this.refresh();
  84. });
  85. });
  86. }
  87. renderView() {
  88. return (
  89. <Block flex>
  90. <ActionLayout
  91. itemList={actionList}
  92. selectedKeys={this.state.selectedKeys}
  93. onAction={key => this.onAction(key)}
  94. />
  95. <TableLayout
  96. // select
  97. columns={this.tableSort(this.columns)}
  98. list={this.state.list}
  99. pagination={this.state.page}
  100. loading={this.props.core.loading}
  101. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  102. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  103. selectedKeys={this.state.selectedKeys}
  104. />
  105. </Block>
  106. );
  107. }
  108. }