page.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. key: 'edit',
  16. name: '编辑',
  17. selectNum: 1,
  18. },
  19. {
  20. key: 'del',
  21. name: '删除',
  22. needSelect: 1,
  23. },
  24. ];
  25. const itemList = [
  26. {
  27. key: 'id',
  28. type: 'hidden',
  29. },
  30. {
  31. key: 'username',
  32. name: '用户名',
  33. type: 'input',
  34. placeholder: '请输入用户名',
  35. require: true,
  36. },
  37. ];
  38. export default class extends Page {
  39. init() {
  40. this.columns = [
  41. {
  42. title: '用户名',
  43. dataIndex: 'username',
  44. },
  45. ];
  46. }
  47. initData() {
  48. System.listManager(this.state.search).then(result => {
  49. this.setTableData(result.list, result.total);
  50. });
  51. }
  52. addAction() {
  53. asyncForm('新增', itemList, {}, data => {
  54. return System.addManager(data).then(() => {
  55. asyncSMessage('新增成功!');
  56. this.refresh();
  57. });
  58. });
  59. }
  60. editAction() {
  61. const { selectedRows } = this.state;
  62. asyncForm('编辑', itemList, selectedRows[0], data => {
  63. return System.putManager(data).then(() => {
  64. asyncSMessage('编辑成功!');
  65. this.refresh();
  66. });
  67. });
  68. }
  69. delAction() {
  70. const { selectedKeys } = this.state;
  71. asyncDelConfirm('删除确认', '是否删除选中账号?', () => {
  72. Promise.all(selectedKeys.map(row => System.delManager({ id: row }))).then(() => {
  73. asyncSMessage('删除成功!');
  74. this.refresh();
  75. });
  76. });
  77. }
  78. renderView() {
  79. return (
  80. <Block flex>
  81. <ActionLayout
  82. itemList={actionList}
  83. selectedKeys={this.state.selectedKeys}
  84. onAction={key => this.onAction(key)}
  85. />
  86. <TableLayout
  87. select
  88. columns={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. }
  99. }