text: var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  
  /**
   * 文件上传组件
   * @author Sun Wenfei
   * @version 0.0.2.1
   */
  define(function (require) {
  
      var React = require('react');
      var ReactDOM = require('react-dom');
  
      var Button = require('../Button.jsx');
      var Upload = require('../components/uploader/UploaderCore.jsx');
      var InputWidget = require('../mixins/InputWidget');
      var cTools = require('../core/componentTools');
  
      return React.createClass({
          /**
           * @properties
           *
           * @param {Import|Properties} src\core\componentTools.js className style disabled skin
           * @param {ReactComponent} renderer value的渲染组件
           * @param {Object} formData 随文件一同传回服务器的数据对象
           * @param {Object} uploadConfig 文件上传配置
           * @param {String} uploaderConfig.action 服务器上传脚本路径，等同于form的action属性，默认/upload.do
           * @param {String} uploaderConfig.method 上传方式，等同于form的method属性，默认post
           * @param {String} uploaderConfig.encType 上传类型，等同于form的encType属性，默认multipart/form-data
           * @param {String} uploaderConfig.accept 可选择文件类型，等同于input的accept属性，默认''
           * @param {Import|Properties} src\mixins\InputWidget.js
           *      value onChange name validations valueTemplate
           */
          /**
           * @fire Import src\mixins\InputWidget.js XXX onChange
           */
          mixins: [InputWidget],
  
          getDefaultProps: function getDefaultProps() {
              return {
                  skin: '',
                  className: '',
                  style: {},
                  disabled: false,
                  valueTemplate: '',
                  renderer: defaultUploaderRenderer,
                  formData: {},
                  uploadConfig: {}
              };
          },
  
          getInitialState: function getInitialState() {
              return {};
          },
  
          componentDidMount: function componentDidMount() {
              this.uploadElement = null;
              this.uploadContainer = null;
          },
  
          onUploaderClick: function onUploaderClick(e) {
              if (this.props.disabled) return;
              var me = this;
              if (!me.uploadElement || !me.uploadContainer) {
                  var element = React.createElement(Upload, {
                      formData: this.props.formData,
                      onUploaded: this.onUploaded,
                      uploadConfig: this.props.uploadConfig || {}
                  });
                  me.uploadContainer = document.createElement('div');
                  document.body.appendChild(me.uploadContainer);
                  me.uploadElement = ReactDOM.render(element, me.uploadContainer, function () {
                      if (this) me.uploadElement = this;
                      setTimeout(function () {
                          me.uploadElement.refs.uploadInput.click();
                      }, 0);
                  });
              } else {
                  this.uploadElement.refs.uploadInput.click();
              }
          },
  
          onUploaded: function onUploaded(result) {
              if (!result) {
                  return;
              }
              this.refs.container.value = result;
              this.___dispatchChange___({ target: this.refs.container });
              ReactDOM.unmountComponentAtNode(this.uploadContainer);
              document.body.removeChild(this.uploadContainer);
              this.uploadElement = null;
              this.uploadContainer = null;
          },
  
          render: function render() {
              var uploaderContainerProps = cTools.containerBaseProps('uploader', this, {
                  merge: {
                      onClick: this.onUploaderClick
                  }
              });
              var Renderer = typeof this.props.renderer === 'function' ? this.props.renderer : defaultUploaderRenderer;
              return React.createElement(
                  'div',
                  uploaderContainerProps,
                  React.createElement(Renderer, _extends({ value: this.___getValue___() }, this.props))
              );
          }
      });
  
      function defaultUploaderRenderer(props) {
          var url = '';
          try {
              value = JSON.parse(props.value);
              url = value.data.url;
          } catch (e) {
              // DO NOTHING
          }
          var buttonProps = {
              icon: 'jpui-icon jpui-icon-upload',
              label: '    文件上传'
          };
          return React.createElement(
              'div',
              null,
              url ? url : React.createElement(Button, buttonProps)
          );
      }
  });