fx-form-widget
Version:
73 lines • 3.12 kB
JavaScript
import _Space from "antd/es/space";
import _Button from "antd/es/button";
import _Input from "antd/es/input";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["schema", "onChange", "onCheck", "value"];
import React from 'react';
import { isNotNullValue } from './tools';
import './index.less';
var InputWidget = function InputWidget(props) {
var _props$schema = props.schema,
schema = _props$schema === void 0 ? {} : _props$schema,
_props$onChange = props.onChange,
onChange = _props$onChange === void 0 ? function () {} : _props$onChange,
_props$onCheck = props.onCheck,
onCheck = _props$onCheck === void 0 ? function () {} : _props$onCheck,
_props$value = props.value,
value = _props$value === void 0 ? isNotNullValue(schema.data) ? schema.data : '' : _props$value,
restProps = _objectWithoutPropertiesLoose(props, _excluded);
var _schema$readonly = schema.readonly,
readonly = _schema$readonly === void 0 ? false : _schema$readonly,
_schema$hasCheck = schema.hasCheck,
hasCheck = _schema$hasCheck === void 0 ? false : _schema$hasCheck,
_schema$placeholder = schema.placeholder,
placeholder = _schema$placeholder === void 0 ? '请输入' : _schema$placeholder,
_schema$minLength = schema.minLength,
minLength = _schema$minLength === void 0 ? undefined : _schema$minLength,
_schema$maxLength = schema.maxLength,
maxLength = _schema$maxLength === void 0 ? undefined : _schema$maxLength,
_schema$allowClear = schema.allowClear,
allowClear = _schema$allowClear === void 0 ? false : _schema$allowClear,
_schema$addonBefore = schema.addonBefore,
addonBefore = _schema$addonBefore === void 0 ? undefined : _schema$addonBefore,
_schema$addonAfter = schema.addonAfter,
addonAfter = _schema$addonAfter === void 0 ? undefined : _schema$addonAfter;
var defaultOptions = {};
if (schema['ui_options']) {
Object.keys(schema['ui_options']).forEach(function (key) {
defaultOptions[key] = schema['ui_options'][key];
});
}
var handleChange = function handleChange(e) {
return onChange(e.target.value);
};
var options = _extends({
placeholder: placeholder,
maxLength: maxLength,
allowClear: allowClear,
addonBefore: addonBefore,
addonAfter: addonAfter,
minLength: minLength,
disabled: readonly,
suffix: maxLength ? value ? (value === null || value === void 0 ? void 0 : value.length) + "/" + maxLength : "0/" + maxLength : undefined
}, defaultOptions);
return /*#__PURE__*/React.createElement(_Space.Compact, {
style: {
width: '100%'
}
}, /*#__PURE__*/React.createElement(_Input, _extends({
type: "text",
onChange: handleChange
}, restProps, options, {
value: value
})), hasCheck && !readonly && /*#__PURE__*/React.createElement(_Button, {
onClick: function onClick() {
return onCheck({
value: value,
fieldName: schema.fieldName
});
}
}, "\u6821\u9A8C"));
};
export default InputWidget;