dataSourceDetail.jsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. tab: props.match.params.tab,
  21. current: ['base', 'column', 'access'].indexOf(props.match.params.tab)
  22. }
  23. }
  24. componentDidMount() {
  25. this.props.dispatch({ type: 'dataSource/setNewModelFields', fields: [
  26. { name: 'type', value: this.props.match.params.type },
  27. { name: 'code', value: this.props.match.params.code }
  28. ] });
  29. }
  30. next() {
  31. const { type, current } = this.state;
  32. this.setState({ current: current + 1 });
  33. let step = ['base', 'column', 'access'][current + 1];
  34. this.props.dispatch({ type: 'main/redirect', path: '/datasource/' + type + '/create/' + step })
  35. }
  36. prev() {
  37. const { type, current } = this.state;
  38. this.setState({ current: current - 1 });
  39. let step = ['base', 'column', 'access'][current - 1];
  40. this.props.dispatch({ type: 'main/redirect', path: '/datasource/' + type + '/create/' + step })
  41. }
  42. render() {
  43. const { dispatch } = this.props;
  44. const { type, mode, code, tab, current } = this.state;
  45. const steps = [{
  46. tabName: 'base',
  47. title: '属性配置',
  48. content: <BaseConfig/>
  49. }, {
  50. tabName: 'column',
  51. title: '数据列配置',
  52. content: <ColumnConfig />
  53. }, {
  54. tabName: 'access',
  55. title: '权限配置',
  56. content: <AccessConfig />
  57. }];
  58. return (
  59. <Layout className='layout-datasource-detail'>
  60. <Content className='content'>
  61. {mode == 'create' ? (<div>
  62. <Steps className='steps-body' current={current}>
  63. {steps.map((item,index) => <Step key={'step-' + index} title={item.title} />)}
  64. </Steps>
  65. <div className="steps-content">
  66. {steps[current].content}
  67. </div>
  68. <div className="steps-action">
  69. {
  70. current > 0 && (
  71. <Button onClick={() => this.prev()}>
  72. 上一步
  73. </Button>)
  74. }
  75. {
  76. current < steps.length - 1
  77. && <Button type="primary" onClick={() => this.next()}>下一步</Button>
  78. }
  79. {
  80. current === steps.length - 1
  81. && <Button type="primary" onClick={() => {
  82. dispatch({ type: 'dataSource/remoteAdd' })
  83. dispatch({ type: 'main/redirect', path: { pathname: '/datasource' } });
  84. }}>完成</Button>
  85. }
  86. </div>
  87. </div>) : (
  88. <Tabs activeKey={tab} type="card"
  89. onChange={(key) => {
  90. dispatch({ type: 'main/redirect', path: '/datasource/' + type + '/' + code + '/' + key })
  91. this.setState({
  92. tab: key
  93. })
  94. }}
  95. tabBarExtraContent={<Button onClick={() => {
  96. dispatch({ type: 'dataSource/remoteModify', code: this.props.match.params.code });
  97. }}>保存修改</Button>}
  98. >
  99. {steps.map((item, index) => {
  100. return <TabPane className='tab-datasource' key={item.tabName} tab={item.title}>
  101. {item.content}
  102. </TabPane>
  103. })}
  104. </Tabs>
  105. )}
  106. </Content>
  107. </Layout>
  108. )
  109. }
  110. }
  111. export default connect()(DataSourceDetail);