• 页面编写
  • 配置路由
  • 页面访问

在项目的react/src/app/demo/containers/organization(project, user, global)目录下新建一个新的功能文件夹table及其相关的JS文件。

  1. // table/index.js
  2. import React, { Component } from 'react';
  3. import { observer } from 'mobx-react';
  4. import { Button, Table } from 'choerodon-ui';
  5. import { Action, Content, Header, Page } from '@choerodon/boot';
  6. import Store from './stores';
  7. @observer
  8. class TableDemo extends Component {
  9. componentDidMount() {
  10. this.loadData();
  11. }
  12. loadData = () => {
  13. Store.loadData();
  14. }
  15. renderLevel(text) {
  16. const LEVEL_MAP = {
  17. organization: '组织',
  18. project: '项目',
  19. };
  20. return LEVEL_MAP[text] || '全局';
  21. }
  22. renderTable = () => {
  23. const { isLoading, pagination } = Store;
  24. const columns = [
  25. {
  26. title: '名字',
  27. dataIndex: 'name',
  28. key: 'name',
  29. width: '25%',
  30. },
  31. {
  32. title: '编码',
  33. dataIndex: 'code',
  34. key: 'code',
  35. width: '25%',
  36. },
  37. {
  38. title: '层级',
  39. dataIndex: 'level',
  40. },
  41. {
  42. title: '状态',
  43. key: 'enabled',
  44. },
  45. {
  46. title: '',
  47. key: 'action',
  48. align: 'right',
  49. render: (text, record) => {
  50. const actionDatas = [{
  51. icon: '',
  52. type: 'site',
  53. text: '修改',
  54. }];
  55. if (record.enabled) {
  56. actionDatas.push({
  57. icon: '',
  58. type: 'site',
  59. text: '停用',
  60. });
  61. } else {
  62. actionDatas.push({
  63. icon: '',
  64. type: 'site',
  65. text: '启用',
  66. });
  67. }
  68. return <Action data={actionDatas} getPopupContainer={() => document.getElementsByClassName('page-content')[0]} />;
  69. },
  70. },
  71. ];
  72. return (
  73. <Table
  74. columns={columns}
  75. dataSource={Store.data.slice()}
  76. pagination={pagination}
  77. rowKey={record => record.id}
  78. onChange={this.handlePageChange}
  79. loading={isLoading}
  80. filterBarPlaceholder="过滤表"
  81. />
  82. );
  83. }
  84. render() {
  85. return (
  86. <Page className="choerodon-role">
  87. <Button
  88. onClick={this.handleRefresh}
  89. >
  90. 刷新
  91. </Button>
  92. </Header>
  93. <Content
  94. title="标题"
  95. description="描述"
  96. link="#"
  97. >
  98. {this.renderTable()}
  99. </Content>
  100. </Page>
  101. );
  102. }
  103. }
  104. export default TableDemo;

2.编写store代码

  1. // stores/index.js
  2. import Store from './Store';
  3. export default Store;
  1. // DEMOIndex.js
  2. import React from 'react';
  3. import { Route, Switch } from 'react-router-dom';
  4. import { inject } from 'mobx-react';
  5. import { asyncRouter, nomatch } from '@choerodon/boot';
  6. const HelloIndex = asyncRouter(() => import('./organization/hello'));
  7. const TableIndex = asyncRouter(() => import('./organization/table'));
  8. @inject('AppState')
  9. class DEMOIndex extends React.Component {
  10. render() {
  11. const { match, AppState } = this.props;
  12. return (
  13. <Switch>
  14. <Route path={`${match.url}/hello`} component={HelloIndex} />
  15. <Route path={`${match.url}/table`} component={TableIndex} />
  16. <Route path="*" component={nomatch} />
  17. </Switch>
  18. );
  19. }
  20. }
  21. export default DEMOIndex;

本次demo的访问路径应该为: http://localhost:9090/#/demo/table