dataSourceDetail.jsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 DataConnectConfig from './dataConnectConfig'
  9. import BaseConfig from './baseConfig'
  10. import ColumnConfig from './columnConfig'
  11. import AccessConfig from './accessConfig'
  12. import OtherConfig from './otherConfig'
  13. import './dataSourceDetail.less'
  14. class DataSourceDetail extends React.Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. mode: props.match.params.code&&props.match.params.code=='create'?'create':'modify',
  19. type: props.match.params.type,
  20. code: props.match.params.code,
  21. tab: props.match.params.tab,
  22. current: ['base', 'column', 'access'].indexOf(props.match.params.tab)
  23. }
  24. }
  25. componentDidMount() {
  26. this.props.dispatch({ type: 'dataSource/setNewModelFields', fields: [
  27. { name: 'type', value: this.props.match.params.type },
  28. { name: 'code', value: this.props.match.params.code }
  29. ] });
  30. }
  31. next() {
  32. const { type, current } = this.state;
  33. this.setState({ current: current + 1 });
  34. let step = ['base', 'column', 'access'][current + 1];
  35. this.props.dispatch({ type: 'main/redirect', path: '/datasource/' + type + '/create/' + step })
  36. }
  37. prev() {
  38. const { type, current } = this.state;
  39. this.setState({ current: current - 1 });
  40. let step = ['base', 'column', 'access'][current - 1];
  41. this.props.dispatch({ type: 'main/redirect', path: '/datasource/' + type + '/create/' + step })
  42. }
  43. render() {
  44. const { dispatch } = this.props;
  45. const { type, mode, code, tab, current } = this.state;
  46. const steps = [{
  47. tabName: 'base',
  48. title: '数据连接配置',
  49. content: <DataConnectConfig mode={mode} />
  50. }, {
  51. tabName: 'column',
  52. title: '数据列配置',
  53. content: <ColumnConfig mode={mode} />
  54. }, {
  55. tabName: 'access',
  56. title: '权限配置',
  57. content: <AccessConfig mode={mode} />
  58. }, {
  59. tabName: 'other',
  60. title: '完成',
  61. content: <OtherConfig mode={mode} />
  62. }];
  63. const tabs = [{
  64. tabName: 'base',
  65. title: '属性配置',
  66. content: <BaseConfig mode={mode} />
  67. }, {
  68. tabName: 'column',
  69. title: '数据列配置',
  70. content: <ColumnConfig mode={mode} />
  71. }, {
  72. tabName: 'access',
  73. title: '权限配置',
  74. content: <AccessConfig mode={mode} />
  75. }];
  76. return (
  77. <Layout className='layout-datasource-detail'>
  78. <Content className='content'>
  79. {mode == 'create' ? (<div>
  80. <Steps className='steps-body' current={current}>
  81. {steps.map((item,index) => <Step key={'step-' + index} title={item.title} />)}
  82. </Steps>
  83. <div className="steps-content">
  84. {steps[current].content}
  85. </div>
  86. <div className="steps-action">
  87. {
  88. current > 0 && (
  89. <Button onClick={() => this.prev()}>
  90. 上一步
  91. </Button>)
  92. }
  93. {
  94. current < steps.length - 1
  95. && <Button type="primary" onClick={() => this.next()}>下一步</Button>
  96. }
  97. {
  98. current === steps.length - 1
  99. && <Button type="primary" onClick={() => {
  100. dispatch({ type: 'dataSource/remoteAdd' })
  101. dispatch({ type: 'main/redirect', path: { pathname: '/datasource' } });
  102. }}>完成</Button>
  103. }
  104. </div>
  105. </div>) : (
  106. <Tabs activeKey={tab} type="card"
  107. onChange={(key) => {
  108. dispatch({ type: 'main/redirect', path: '/datasource/' + type + '/' + code + '/' + key })
  109. this.setState({
  110. tab: key
  111. })
  112. }}
  113. tabBarExtraContent={<Button onClick={() => {
  114. dispatch({ type: 'dataSource/remoteModify', code: this.props.match.params.code });
  115. }}>保存修改</Button>}
  116. >
  117. {tabs.map((item, index) => {
  118. return <TabPane className='tab-datasource' key={item.tabName} tab={item.title}>
  119. {item.content}
  120. </TabPane>
  121. })}
  122. </Tabs>
  123. )}
  124. </Content>
  125. </Layout>
  126. )
  127. }
  128. }
  129. export default connect()(DataSourceDetail);