yylib-quick-mobile
Version:
yylib-quick-mobile
254 lines (218 loc) • 11.2 kB
JavaScript
var _inputItem = require('antd-mobile/lib/input-item');
var _inputItem2 = _interopRequireDefault(_inputItem);
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/input-item/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');
var _YYScan = require('../plugin/YYScan');
var _YYScan2 = _interopRequireDefault(_YYScan);
var _YYVoice = require('../plugin/YYVoice');
var _YYVoice2 = _interopRequireDefault(_YYVoice);
require('./YYInput.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 YYInput = function (_React$Component) {
_inherits(YYInput, _React$Component);
function YYInput() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, YYInput);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = YYInput.__proto__ || Object.getPrototypeOf(YYInput)).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 (e) {
if ((0, _FunctionUtil.isFunction)(_this.props.onExtraClick)) _this.props.onExtraClick();
}, _this.scanClick = function (value) {
var data = { value: value };
if ((0, _FunctionUtil.isFunction)(_this.props.scanClick)) _this.props.scanClick(data);
var fields = {};
fields[_this.props.field] = {
dirty: true,
errors: undefined,
name: _this.props.field,
touched: true,
validating: true,
value: data.value
};
_this.props.form.setFields(fields);
}, _this.voiceClick = function (value) {
var data = { value: value };
if ((0, _FunctionUtil.isFunction)(_this.props.voiceClick)) _this.props.voiceClick(data);
var fields = {};
fields[_this.props.field] = {
dirty: true,
errors: undefined,
name: _this.props.field,
touched: true,
validating: true,
value: data.value
};
_this.props.form.setFields(fields);
}, _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(YYInput, [{
key: 'initExtra',
value: function initExtra() {
var extra = [];
var _props = this.props,
openScan = _props.openScan,
openVoice = _props.openVoice,
nid = _props.nid;
if (openScan) {
extra.push(_react2.default.createElement(_YYScan2.default, { key: nid, onClick: this.scanClick.bind(this) }));
}
if (openVoice) {
extra.push(_react2.default.createElement(_YYVoice2.default, { key: nid, onClick: this.voiceClick.bind(this) }));
}
return extra;
}
}, {
key: 'render',
value: function render() {
var getFieldProps = this.props.form.getFieldProps;
var _props2 = this.props,
field = _props2.field,
value = _props2.value,
required = _props2.required,
trigger = _props2.trigger,
type = _props2.type,
placeholder = _props2.placeholder,
editable = _props2.editable,
disabled = _props2.disabled,
clear = _props2.clear,
maxLength = _props2.maxLength,
hasError = _props2.hasError,
extra = _props2.extra,
labelNumber = _props2.labelNumber,
updatePlaceholder = _props2.updatePlaceholder,
label = _props2.label,
showIcon = _props2.showIcon,
icon = _props2.icon,
iconColor = _props2.iconColor,
visible = _props2.visible,
openScan = _props2.openScan,
openVoice = _props2.openVoice,
validateCallBack = _props2.validateCallBack,
findUI = _props2.findUI,
offline = _props2.offline,
parentType = _props2.parentType,
uiorigin = _props2.uiorigin,
RunInDesign = _props2.RunInDesign,
uititle = _props2.uititle,
uitype = _props2.uitype,
uikey = _props2.uikey,
nid = _props2.nid,
control_event = _props2.control_event,
restProps = _objectWithoutProperties(_props2, ['field', 'value', 'required', 'trigger', 'type', 'placeholder', 'editable', 'disabled', 'clear', 'maxLength', 'hasError', 'extra', 'labelNumber', 'updatePlaceholder', 'label', 'showIcon', 'icon', 'iconColor', 'visible', 'openScan', 'openVoice', 'validateCallBack', 'findUI', 'offline', 'parentType', 'uiorigin', 'RunInDesign', 'uititle', 'uitype', 'uikey', 'nid', 'control_event']);
var requiredMsg = '必填项' + label + '未填写';
var wrapClz = (0, _classnames2.default)('yy-input', !visible && 'hidden', this.props.className);
return _react2.default.createElement(
_inputItem2.default,
_extends({}, restProps, {
className: wrapClz
}, (0, _FunctionUtil.isFunction)(getFieldProps) ? getFieldProps(field, {
initialValue: value,
rules: [{ required: required, message: requiredMsg }, { validator: this.validateCallBack }],
trigger: trigger,
valuePropName: 'value'
}) : null, {
type: type,
placeholder: placeholder,
editable: editable,
disabled: disabled,
clear: clear,
maxLength: type != 'phone' && maxLength,
onChange: this.onChange,
onBlur: this.onBlur,
onFocus: this.onFocus,
error: hasError,
onErrorClick: this.onErrorClick,
extra: extra ? extra : this.initExtra(),
onExtraClick: extra ? this.onExtraClick : null,
labelNumber: showIcon ? labelNumber + 1 : labelNumber,
updatePlaceholder: updatePlaceholder,
name: field
}),
showIcon && _react2.default.createElement(_YYIcon2.default, { type: icon, color: iconColor, style: { float: 'left', paddingRight: '8px' }, size: 'xs' }),
required ? _react2.default.createElement(
'span',
{ className: 'yy-label-required' },
label
) : label
);
}
}]);
return YYInput;
}(_react2.default.Component);
YYInput.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,
openScan: false,
openVoice: false,
icon: "Home",
iconColor: "red",
validateCallBack: "",
visible: true,
findUI: '',
offline: false,
parentType: '',
uiorigin: '',
RunInDesign: false,
uititle: '',
uitype: '',
uikey: '',
nid: '',
control_event: {}
};
module.exports = YYInput;
;