content.jsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import React from 'react'
  2. import { connect } from 'dva'
  3. import { Layout, Steps, Button, Tabs } from 'antd'
  4. import DataConnectConfig from './dataConnectConfig'
  5. import BaseConfig from './baseConfig'
  6. import ColumnConfig from './columnConfig'
  7. import AccessConfig from './accessConfig'
  8. import OtherConfig from './otherConfig'
  9. import './content.less'
  10. const { Content } = Layout
  11. const Step = Steps.Step
  12. const TabPane = Tabs.TabPane
  13. class DataSourceDetailContent extends React.Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. mode: props.params.code && props.params.code==='create'?'create':'modify',
  18. type: props.params.type,
  19. code: props.params.code,
  20. tab: props.params.tab,
  21. // current: ['base', 'column', 'access', 'other'].indexOf(props.match.params.tab)
  22. current: ['base', 'column', 'other'].indexOf(props.params.tab)
  23. }
  24. }
  25. next() {
  26. const { type, current } = this.state;
  27. this.setState({ current: current + 1 });
  28. // let step = ['base', 'column', 'access', 'other'][current + 1];
  29. let step = ['base', 'column', 'other'][current + 1];
  30. this.props.dispatch({ type: 'main/redirect', path: '/workshop/datasource/' + type + '/create/' + step })
  31. }
  32. prev() {
  33. const { type, current } = this.state;
  34. this.setState({ current: current - 1 });
  35. // let step = ['base', 'column', 'access', 'other'][current - 1];
  36. let step = ['base', 'column', 'other'][current - 1];
  37. this.props.dispatch({ type: 'main/redirect', path: '/workshop/datasource/' + type + '/create/' + step })
  38. }
  39. render() {
  40. const { dispatch, dataSourceDetail, dataConnect } = this.props;
  41. const { type, code, tab, mode, current } = this.state;
  42. const steps = [{
  43. tabName: 'base',
  44. title: type === 'database' ? '数据链接配置' : '文件选择',
  45. content: <DataConnectConfig mode={mode} />,
  46. }, {
  47. tabName: 'column',
  48. title: '数据列配置',
  49. content: <ColumnConfig mode={mode} />,
  50. }, {
  51. tabName: 'other',
  52. title: '完成',
  53. content: <OtherConfig mode={mode} />,
  54. }];
  55. const tabs = [{
  56. tabName: 'base',
  57. title: '属性配置',
  58. content: <BaseConfig mode={mode} />,
  59. }, {
  60. tabName: 'column',
  61. title: '数据列配置',
  62. content: <ColumnConfig mode={mode} />,
  63. }, {
  64. tabName: 'access',
  65. title: '数据开放策略',
  66. content: <AccessConfig mode={mode} />,
  67. }];
  68. return (
  69. <Layout className='layout-datasource-detail'>
  70. <Content className='content'>
  71. {mode === 'create' ? (<div className='datasource-steps-container'>
  72. <Steps className='steps-body' current={current}>
  73. {steps.map((item,index) => <Step key={'step-' + index} title={item.title} />)}
  74. </Steps>
  75. <div className="steps-content">
  76. {steps[current].content}
  77. </div>
  78. <div className="steps-action">
  79. {
  80. current > 0 && (
  81. <Button onClick={() => this.prev()}>
  82. 上一步
  83. </Button>)
  84. }
  85. {
  86. current < steps.length - 1
  87. && <Button disabled={
  88. // 第一步:没有选择数据连接或没有上传文件或上传文件有误
  89. ( current === 0 && ( ( type === 'database' && !dataSourceDetail.connectCode ) || ( type === 'file' && +1 === 2) ) ) ||
  90. // 第二步:数据列为空或者数据对象有变更
  91. (current === 1 && (!dataSourceDetail.columns || dataSourceDetail.columns.length === 0 || dataSourceDetail.targetDirty))
  92. } type="primary" onClick={() => this.next()}>下一步</Button>
  93. }
  94. {
  95. current === steps.length - 1
  96. && <Button disabled={
  97. !dataSourceDetail.name ||
  98. !dataConnect.selected ||
  99. (!dataSourceDetail.columns || dataSourceDetail.columns.length === 0)
  100. } type="primary" onClick={() => {
  101. dispatch({ type: 'dataSource/remoteAdd' })
  102. }}>完成</Button>
  103. }
  104. </div>
  105. </div>) : (
  106. <Tabs activeKey={tab} type="card"
  107. onChange={(key) => {
  108. dispatch({ type: 'main/redirect', path: '/workshop/datasource/' + type + '/' + code + '/' + key })
  109. this.setState({
  110. tab: key,
  111. })
  112. }}
  113. >
  114. {tabs.map((item, index) => {
  115. return <TabPane className='tab-datasource' key={item.tabName} tab={item.title}>
  116. {item.content}
  117. </TabPane>
  118. })}
  119. </Tabs>
  120. )}
  121. </Content>
  122. </Layout>
  123. )
  124. }
  125. }
  126. export default connect(({ present: { dataSourceDetail, dataConnect } }) => ({ dataSourceDetail, dataConnect }))(DataSourceDetailContent);