From b8cdbe3fbd57bbd513509a7d76c529096b1a7153 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 15 七月 2020 14:39:10 +0800 Subject: [PATCH] 2020-07-15 --- src/mob/datasource/index.jsx | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/mob/datasource/index.jsx b/src/mob/datasource/index.jsx index f40dd17..8a03a45 100644 --- a/src/mob/datasource/index.jsx +++ b/src/mob/datasource/index.jsx @@ -9,6 +9,8 @@ import VerifyCard from './verifycard' import './index.scss' +const { confirm } = Modal + class DataSource extends Component { static propTpyes = { config: PropTypes.any, @@ -20,7 +22,14 @@ sourcelist: [], searches: [], visible: false, + loading: false, source: null + } + + UNSAFE_componentWillMount () { + const { config } = this.props + + this.setState({sourcelist: config.sourcelist || []}) } UNSAFE_componentWillReceiveProps(nextProps) { @@ -50,19 +59,62 @@ }) } - 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)} /> @@ -87,6 +139,7 @@ okText={dict['mob.submit']} cancelText={dict['mob.cancel']} onOk={this.verifySubmit} + confirmLoading={loading} onCancel={() => { this.setState({ visible: false }) }} destroyOnClose > -- Gitblit v1.8.0