| | |
| | | import VerifyCard from './verifycard' |
| | | import './index.scss' |
| | | |
| | | const { confirm } = Modal |
| | | |
| | | class DataSource extends Component { |
| | | static propTpyes = { |
| | | config: PropTypes.any, |
| | |
| | | sourcelist: [], |
| | | searches: [], |
| | | visible: false, |
| | | loading: false, |
| | | source: null |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { config } = this.props |
| | | |
| | | this.setState({sourcelist: config.sourcelist || []}) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | |
| | | }) |
| | | } |
| | | |
| | | closeDataSource = () => { |
| | | closeDataSource = (item) => { |
| | | const { config } = this.props |
| | | let sourcelist = fromJS(this.state.sourcelist).toJS() |
| | | const _this = this |
| | | |
| | | sourcelist = sourcelist.filter(cell => cell.uuid !== item.uuid) |
| | | |
| | | confirm({ |
| | | title: '确定删除数据源吗?', |
| | | content: '', |
| | | okText: _this.state.dict['mob.confirm'], |
| | | cancelText: _this.state.dict['mob.cancel'], |
| | | onOk() { |
| | | _this.setState({sourcelist}) |
| | | _this.props.updateConfig({...config, sourcelist: fromJS(sourcelist).toJS()}) |
| | | }, |
| | | onCancel() {} |
| | | }) |
| | | } |
| | | |
| | | verifySubmit = () => { |
| | | const { config } = this.props |
| | | let sourcelist = fromJS(this.state.sourcelist).toJS() |
| | | |
| | | this.setState({loading: true}) |
| | | this.verifyRef.submitDataSource().then((res) => { |
| | | let isadd = true |
| | | sourcelist = sourcelist.map(item => { |
| | | if (item.uuid === res.uuid) { |
| | | isadd = false |
| | | return res |
| | | } else { |
| | | return item |
| | | } |
| | | }) |
| | | |
| | | if (isadd) { |
| | | sourcelist.push(res) |
| | | } |
| | | |
| | | this.setState({loading: false, visible: false, sourcelist}) |
| | | this.props.updateConfig({...config, sourcelist: fromJS(sourcelist).toJS()}) |
| | | }, () => { |
| | | this.setState({loading: false}) |
| | | }) |
| | | } |
| | | |
| | | render () { |
| | | const { sourcelist, visible, source, dict, searches } = this.state |
| | | const { sourcelist, visible, source, dict, searches, loading } = this.state |
| | | |
| | | return ( |
| | | <div className="mob-datasource"> |
| | | {sourcelist.map(item => ( |
| | | <span className="mob-input-group-wrapper" key={item.uuid}> |
| | | <span className="mob-input-wrapper"> |
| | | <span className="mob-input-value">{item.label}</span> |
| | | <span className="mob-input-value">{item.setting.name}</span> |
| | | <span className="mob-input-group-addon"> |
| | | <Icon type="setting" onClick={() => this.editDataSource(item)} /> |
| | | <Icon type="close" onClick={() => this.closeDataSource(item)} /> |
| | |
| | | okText={dict['mob.submit']} |
| | | cancelText={dict['mob.cancel']} |
| | | onOk={this.verifySubmit} |
| | | confirmLoading={loading} |
| | | onCancel={() => { this.setState({ visible: false }) }} |
| | | destroyOnClose |
| | | > |