page.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. }
  44. initData() {
  45. System.listManager(this.state.search).then(result => {
  46. this.setTableData(result.list, result.total);
  47. });
  48. }
  49. addAction() {
  50. asyncForm('新增', itemList, {}, data => {
  51. return System.addManager(data).then(() => {
  52. asyncSMessage('新增成功!');
  53. this.refresh();
  54. });
  55. });
  56. }
  57. editAction() {
  58. const { selectedRows } = this.state;
  59. asyncForm('编辑', itemList, selectedRows[0], data => {
  60. return System.putManager(data).then(() => {
  61. asyncSMessage('编辑成功!');
  62. this.refresh();
  63. });
  64. });
  65. }
  66. delAction() {
  67. const { selectedKeys } = this.state;
  68. asyncDelConfirm('删除确认', '是否删除选中账号?', () => {
  69. Promise.all(selectedKeys.map(row => System.delManager({ id: row }))).then(() => {
  70. asyncSMessage('删除成功!');
  71. this.refresh();
  72. });
  73. });
  74. }
  75. renderView() {
  76. return (
  77. <Block flex>
  78. <ActionLayout
  79. itemList={actionList}
  80. selectedKeys={this.state.selectedKeys}
  81. onAction={key => this.onAction(key)}
  82. />
  83. <TableLayout
  84. select
  85. columns={this.columns}
  86. list={this.state.list}
  87. pagination={this.state.page}
  88. loading={this.props.core.loading}
  89. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  90. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  91. selectedKeys={this.state.selectedKeys}
  92. />
  93. </Block>
  94. );
  95. }
  96. }