dataSourceDetail.jsx 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react'
  2. import { connect } from 'dva'
  3. import { Layout, Steps, Button, message, Tabs } from 'antd'
  4. const { Header, Content } = Layout
  5. const Step = Steps.Step
  6. const TabPane = Tabs.TabPane
  7. import { Link } from 'react-router-dom'
  8. import BaseConfig from './baseConfig'
  9. import ConnectConfig from './connectConfig'
  10. import ColumnConfig from './columnConfig'
  11. import AccessConfig from './accessConfig'
  12. import './dataSourceDetail.less'
  13. class DataSourceDetail extends React.Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. mode: props.match.params.code&&props.match.params.code=='create'?'create':'modify',
  18. type: props.match.params.type,
  19. code: props.match.params.code,
  20. current: 0
  21. }
  22. }
  23. componentDidMount() {
  24. this.props.dispatch({ type: 'dataSource/setNewModelField', name: 'type', value: this.props.match.params.type });
  25. this.props.dispatch({ type: 'dataSource/setNewModelField', name: 'code', value: this.props.match.params.code });
  26. }
  27. next() {
  28. const current = this.state.current + 1;
  29. this.setState({ current });
  30. }
  31. prev() {
  32. const current = this.state.current - 1;
  33. this.setState({ current });
  34. }
  35. render() {
  36. const { dispatch } = this.props;
  37. const { mode, current } = this.state;
  38. const steps = [{
  39. title: '属性配置',
  40. content: <BaseConfig/>
  41. }, {
  42. title: '数据列配置',
  43. content: <ColumnConfig />
  44. }, {
  45. title: '权限配置',
  46. content: <AccessConfig />
  47. }];
  48. return (
  49. <Layout className='layout-datasource-detail'>
  50. <Content className='content'>
  51. {mode == 'create' ? (<div>
  52. <Steps className='steps-body' current={current}>
  53. {steps.map((item,index) => <Step key={'step-' + index} title={item.title} />)}
  54. </Steps>
  55. <div className="steps-content">
  56. {steps[current].content}
  57. </div>
  58. <div className="steps-action">
  59. {
  60. current > 0 && (
  61. <Button onClick={() => this.prev()}>
  62. 上一步
  63. </Button>)
  64. }
  65. {
  66. current < steps.length - 1
  67. && <Button type="primary" onClick={() => this.next()}>下一步</Button>
  68. }
  69. {
  70. current === steps.length - 1
  71. && <Button type="primary" onClick={() => {
  72. dispatch({ type: 'dataSource/add' })
  73. dispatch({ type: 'main/redirect', path: { pathname: '/dataSource' } });
  74. }}>完成</Button>
  75. }
  76. </div>
  77. </div>) : (
  78. <Tabs defaultActiveKey="tab-0" type="card">
  79. {steps.map((item, index) => {
  80. return <TabPane className='tab-datasource' key={'tab-' + index} tab={item.title}>
  81. {item.content}
  82. </TabPane>
  83. })}
  84. </Tabs>
  85. )}
  86. </Content>
  87. </Layout>
  88. )
  89. }
  90. }
  91. export default connect()(DataSourceDetail);