| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Popover, Button, Icon } from 'antd' |
| | | import { Radio, Modal } from 'antd' |
| | | import { PaperClipOutlined, DeleteOutlined } from '@ant-design/icons' |
| | | |
| | | import PopSource from './popsource' |
| | | import InputForm from './inputform' |
| | | import './index.scss' |
| | | |
| | | class CopyComponent extends Component { |
| | | class SourceComponent extends Component { |
| | | static propTpyes = { |
| | | type: PropTypes.string, |
| | | placement: PropTypes.any, |
| | |
| | | } |
| | | |
| | | state = { |
| | | url: this.props.value |
| | | url: '', |
| | | visible: '' |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { value } = this.props |
| | | let val = '' |
| | | |
| | | if (value) { |
| | | val = value |
| | | } else if (this.props['data-__meta']) { |
| | | val = this.props['data-__meta'].initialValue || '' |
| | | } |
| | | |
| | | this.setState({ |
| | | url: val, |
| | | }) |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | this.props.onChange('') |
| | | } |
| | | |
| | | changePopover = (visible) => { |
| | | if (!visible && this.SourceWrap.state.url) { |
| | | this.setState({url: this.SourceWrap.state.url}) |
| | | this.props.onChange(this.SourceWrap.state.url) |
| | | } else if (visible && this.SourceWrap) { |
| | | this.SourceWrap.init() |
| | | handleChange = (key) => { |
| | | this.setState({visible: key}) |
| | | } |
| | | |
| | | popSubmit = () => { |
| | | let url = '' |
| | | if (this.inputWrap && this.inputWrap.state.url) { |
| | | url = this.inputWrap.state.url |
| | | } |
| | | |
| | | this.setState({visible: '', url}) |
| | | this.props.onChange(url) |
| | | } |
| | | |
| | | render () { |
| | | const { url } = this.state |
| | | const { type, placement } = this.props |
| | | const { url, visible } = this.state |
| | | const { type } = this.props |
| | | let name = url ? url.slice(url.lastIndexOf('/') + 1) : '' |
| | | // url !== '@icon@' |
| | | |
| | | return ( |
| | | <div className="mk-source-wrap"> |
| | | {!url ? <Popover overlayClassName="mk-source-manage" placement={placement || 'top'} content={<PopSource type={type} ref={dom => { this.SourceWrap = dom }} />} trigger="click" onVisibleChange={this.changePopover}> |
| | | <Button icon="upload">点击添加</Button> |
| | | </Popover> : null} |
| | | {url ? <div className="mk-source-item-info"> |
| | | <Icon type="paper-clip" /> |
| | | {!url ? <Radio.Group> |
| | | <Radio.Button value="input" size="small" onClick={() => this.handleChange('input')}>输入</Radio.Button> |
| | | <Radio.Button value="upload" size="small" onClick={() => this.handleChange('upload')}>上传</Radio.Button> |
| | | <Radio.Button value="system" size="small" onClick={() => this.handleChange('system')}>系统</Radio.Button> |
| | | </Radio.Group> : null} |
| | | {url && type === 'video' ? <div className="mk-source-item-info"> |
| | | <PaperClipOutlined /> |
| | | <a target="_blank" rel="noopener noreferrer" href={url}>{name}</a> |
| | | <Icon title="删除文件" type="delete" onClick={this.deleteUrl}/> |
| | | <DeleteOutlined title="删除文件" onClick={this.deleteUrl}/> |
| | | </div> : null} |
| | | {url && type !== 'video' && url !== '@icon@' ? <div className="mk-source-item-info picture"> |
| | | <img src={url} alt="" /> |
| | | <a target="_blank" rel="noopener noreferrer" href={url}>{name}</a> |
| | | <DeleteOutlined title="删除文件" onClick={this.deleteUrl}/> |
| | | </div> : null} |
| | | {url && type !== 'video' && url === '@icon@' ? <div className="mk-source-item-info avatar"> |
| | | <span className="mk-avatar">{name}</span> |
| | | <DeleteOutlined title="删除文件" onClick={this.deleteUrl}/> |
| | | </div> : null} |
| | | <Modal |
| | | visible={!!visible} |
| | | width={visible !== 'system' ? 600 : 1000} |
| | | closable={false} |
| | | maskClosable={false} |
| | | okText="确定" |
| | | cancelText="取消" |
| | | onOk={this.popSubmit} |
| | | onCancel={() => {this.setState({visible: ''})}} |
| | | destroyOnClose |
| | | > |
| | | <InputForm type={type === 'picture' ? 'image' : type} keyword={visible} ref={dom => { this.inputWrap = dom }} /> |
| | | </Modal> |
| | | </div> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | export default CopyComponent |
| | | export default SourceComponent |