UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

163 lines (132 loc) 7.6 kB
'use strict'; var _list = require('antd-mobile/lib/list'); var _list2 = _interopRequireDefault(_list); 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; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); require('antd-mobile/lib/list/style/css'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _YYIcon = require('../icon/YYIcon'); var _YYIcon2 = _interopRequireDefault(_YYIcon); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _FunctionUtil = require('../../utils/FunctionUtil'); require('./YYScan.less'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var YYScan = function (_React$Component) { _inherits(YYScan, _React$Component); function YYScan() { var _ref; var _temp, _this, _ret; _classCallCheck(this, YYScan); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = YYScan.__proto__ || Object.getPrototypeOf(YYScan)).call.apply(_ref, [this].concat(args))), _this), _this.state = { value: _this.props.value }, _this.onChange = function (value) { var fields = {}; fields[_this.props.field] = { dirty: true, errors: undefined, name: _this.props.field, touched: true, validating: true, value: value }; _this.props.form.setFields(fields); if ((0, _FunctionUtil.isFunction)(_this.props.onChange)) _this.props.onChange(value); }, _this.onBlur = function (value) { if ((0, _FunctionUtil.isFunction)(_this.props.onBlur)) _this.props.onBlur(value); }, _this.onExtraClick = function () { if ((0, _FunctionUtil.isFunction)(_this.props.onExtraClick)) _this.props.onExtraClick(); }, _this.onFocus = function (value) { if ((0, _FunctionUtil.isFunction)(_this.props.onFocus)) _this.props.onFocus(value); }, _this.onErrorClick = function () { if ((0, _FunctionUtil.isFunction)(_this.props.onErrorClick)) _this.props.onErrorClick(); }, _this.validateCallBack = function (rule, value, callback) { if ((0, _FunctionUtil.isFunction)(_this.props.validateCallBack)) { _this.props.validateCallBack(rule, value, callback); callback(); } else { callback(); } }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(YYScan, [{ key: 'render', value: function render() { var getFieldProps = this.props.form.getFieldProps; var wrapClz = (0, _classnames2.default)('yy-scan', this.props.className); var _props = this.props, scanIconColor = _props.scanIconColor, scanIcon = _props.scanIcon, scanValue = _props.scanValue, field = _props.field, value = _props.value, required = _props.required, trigger = _props.trigger, type = _props.type, placeholder = _props.placeholder, editable = _props.editable, disabled = _props.disabled, clear = _props.clear, maxLength = _props.maxLength, hasError = _props.hasError, extra = _props.extra, updatePlaceholder = _props.updatePlaceholder, label = _props.label, showIcon = _props.showIcon, icon = _props.icon, iconColor = _props.iconColor, restProps = _objectWithoutProperties(_props, ['scanIconColor', 'scanIcon', 'scanValue', 'field', 'value', 'required', 'trigger', 'type', 'placeholder', 'editable', 'disabled', 'clear', 'maxLength', 'hasError', 'extra', 'updatePlaceholder', 'label', 'showIcon', 'icon', 'iconColor']); var requiredMsg = '必填项' + label + '未填写'; return _react2.default.createElement( _list2.default.Item, _extends({}, restProps, { className: wrapClz, extra: _react2.default.createElement( 'div', null, scanValue, _react2.default.createElement(_YYIcon2.default, _extends({}, (0, _FunctionUtil.isFunction)(getFieldProps) ? getFieldProps(field, { initialValue: scanValue, valuePropName: 'scanValue' }) : null, { disabled: disabled, type: scanIcon, color: scanIconColor, onClick: this.onClick })) ) }), showIcon && _react2.default.createElement(_YYIcon2.default, { type: icon, color: iconColor, style: { float: 'left', paddingRight: '8px' }, size: 'xs' }), label ); } }]); return YYScan; }(_react2.default.Component); YYScan.defaultProps = { field: "default", value: null, required: false, trigger: "onChange", type: "text", placeholder: "", editable: true, disabled: false, clear: true, maxLength: null, hasError: false, extra: "", labelNumber: 7, updatePlaceholder: false, label: '输入框', showIcon: false, icon: "wage", iconColor: "red" }; module.exports = YYScan;