page.js 2.7 KB

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