picker.js 改后的变化是什么,怎么使用

发布于 2022-09-07 23:58:44 字数 6583 浏览 13 评论 0

把antd 里面的picker组件改成了,请问怎么使用

改后
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _Popup = require('rmc-cascader/lib/Popup');

var _Popup2 = _interopRequireDefault(_Popup);

var _Cascader = require('rmc-cascader/lib/Cascader');

var _Cascader2 = _interopRequireDefault(_Cascader);

var _MultiPicker = require('rmc-picker/lib/MultiPicker');

var _MultiPicker2 = _interopRequireDefault(_MultiPicker);

var _arrayTreeFilter = require('array-tree-filter');

var _arrayTreeFilter2 = _interopRequireDefault(_arrayTreeFilter);

var _styles = require('./styles.web.js');

var _styles2 = _interopRequireDefault(_styles);

var _popupProps = require('./popupProps.web.js');

var _popupProps2 = _interopRequireDefault(_popupProps);

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {'default': obj};
}

function getDefaultProps() {
  var defaultFormat = function defaultFormat(values) {
    return values.join(',');
  };
  return {
    triggerType: 'onClick',
    prefixCls: 'am-picker',
    pickerPrefixCls: 'am-picker-col',
    popupPrefixCls: 'am-picker-popup',
    format: defaultFormat,
    cols: 3,
    cascade: true,
    extra: '请选择',
    okText: '确定',
    dismissText: '取消',
    title: '',
    styles: _styles2['default']
  };
}

var Picker = function (_React$Component) {
  (0, _inherits3['default'])(Picker, _React$Component);

  function Picker() {
    (0, _classCallCheck3['default'])(this, Picker);

    var _this = (0, _possibleConstructorReturn3['default'])(this, (Picker.__proto__ || Object.getPrototypeOf(Picker)).apply(this, arguments));

    _this.getSel = function () {
      var value = _this.props.value || [];
      var treeChildren = void 0;
      if (_this.props.cascade) {
        treeChildren = (0, _arrayTreeFilter2['default'])(_this.props.data, function (c, level) {
          return c.value === value[level];
        });
      } else {
        treeChildren = value.map(function (v, i) {
          return _this.props.data[i].filter(function (d) {
            return d.value === v;
          })[0];
        });
      }

      return _this.props.format && _this.props.format(treeChildren.map(function (v) {
        if (v)
          return v.label;
        }));
    };
    return _this;
  }

  (0, _createClass3['default'])(Picker, [{
    key: 'render',
    value: function render() {
      var props = this.props;
      var children = props.children,
        _props$value = props.value,
        value = _props$value === undefined ? [] : _props$value,
        extra = props.extra,
        okText = props.okText,
        itemStyle = props.itemStyle,
        dismissText = props.dismissText,
        popupPrefixCls = props.popupPrefixCls,
        cascade = props.cascade;

      var cascader = void 0;
      var popupMoreProps = {};
      if (cascade) {

        cascader = _react2['default'].createElement(_Cascader2['default'], {
          prefixCls: props.prefixCls,
          pickerPrefixCls: props.pickerPrefixCls,
          data: props.data,
          cols: props.cols,
          onChange: props.onPickerChange,
          pickerItemStyle: itemStyle
        });
      } else {
        cascader = _react2['default'].createElement(
          _MultiPicker2['default'],
          {prefixCls: props.prefixCls, pickerPrefixCls: props.pickerPrefixCls, pickerItemStyle: itemStyle},
          props.data.map(function (d) {
            return {props: {children: d}};
          })
        );
        popupMoreProps = {
          pickerValueProp: 'selectedValue',
          pickerValueChangeProp: 'onValueChange'
        };
      }
      return _react2['default'].createElement(
        _Popup2['default'],
        (0, _extends3['default'])({cascader: cascader}, _popupProps2['default'], props, {
          prefixCls: popupPrefixCls,
          value: value,
          dismissText: dismissText,
          okText: okText
        }, popupMoreProps),
        _react2['default'].cloneElement(children, {extra: this.getSel() || extra})
      );
    }
  }]);
  return Picker;
}(_react2['default'].Component);

require('./index.less');
Picker.defaultProps = getDefaultProps();
module.exports = Picker;
改前
'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _AbstractPicker2 = require('./AbstractPicker');

var _AbstractPicker3 = _interopRequireDefault(_AbstractPicker2);

var _style = require('./style');

var _style2 = _interopRequireDefault(_style);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var Picker = function (_AbstractPicker) {
    (0, _inherits3['default'])(Picker, _AbstractPicker);

    function Picker() {
        (0, _classCallCheck3['default'])(this, Picker);

        var _this = (0, _possibleConstructorReturn3['default'])(this, (Picker.__proto__ || Object.getPrototypeOf(Picker)).apply(this, arguments));

        _this.popupProps = {};
        return _this;
    }

    return Picker;
}(_AbstractPicker3['default']);

exports['default'] = Picker;

Picker.defaultProps = (0, _extends3['default'])({}, (0, _AbstractPicker2.getDefaultProps)(), { styles: _style2['default'] });
module.exports = exports['default'];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文