UNPKG

ming-demo3

Version:
328 lines (288 loc) 10.7 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _react = _interopRequireDefault(require("react")); var _reactDom = require("react-dom"); var _antd = require("antd"); var _SvgIcon = _interopRequireDefault(require("@mdf/metaui-web/lib/components/common/SvgIcon")); var _label = _interopRequireDefault(require("./label")); var _text = _interopRequireDefault(require("./text")); var _util = require("@mdf/cube/lib/helpers/util"); var _AcInputLocal = _interopRequireDefault(require("../AcInputLocal")); var _util2 = require("util"); var InputMultiLang = function (_React$Component) { (0, _inherits2["default"])(InputMultiLang, _React$Component); function InputMultiLang(props) { var _this; (0, _classCallCheck2["default"])(this, InputMultiLang); _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(InputMultiLang).call(this, props)); var cStyle = props.cStyle, cFormatData = props.cFormatData; var config = null, format = null; if (cStyle) { try { config = JSON.parse(cStyle); } catch (e) { config = {}; } } if (cFormatData) { try { format = JSON.parse(cFormatData); } catch (e) {} } _this.state = Object.assign({ bIsNull: props.bIsNull, value: props.defaultValue, type: props.type || 'text', size: props.size || 'default', disabled: props.disabled || false, visible: !props.bHidden, addonBefore: props.addonBefore || '', readOnly: props.readOnly, addonAfter: props.addonAfter || '', placeholder: props.placeholder || '', autosize: props.autosize || false, err: props.err || '', msg: props.msg || '', focused: props.focus ? true : false, format: format }, config); _this.onPressEnter = _this.onPressEnter.bind((0, _assertThisInitialized2["default"])(_this)); return _this; } (0, _createClass2["default"])(InputMultiLang, [{ key: "componentDidMount", value: function componentDidMount() { if (this.props.model) this.props.model.addListener(this); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { if (this.props.model) this.props.model.removeListener(this); } }, { key: "componentWillUpdate", value: function componentWillUpdate(nextProps, nextState) {} }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps, prevState) { if (this.props.model) { this.props.model.addListener(this); if (this.state.err && prevState.value != this.state.value) { if (!this.autoTrigger) { this.props.model.validate(); } else { delete this.autoTrigger; } } } } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { if (this.props.model) return; var _newStateValue = {}; if (nextProps.defaultValue != this.state.value) _newStateValue.value = nextProps.defaultValue; if (nextProps.err != this.state.err) _newStateValue.err = nextProps.err; if (nextProps.focus && this.state.focused == false) _newStateValue.focused = true; if (Object.keys(_newStateValue).length > 0) this.setState(_newStateValue); } }, { key: "syncViewModel", value: function syncViewModel(localeList) { if (this.props.model) { this.props.model.setValue(localeList, true); } } }, { key: "handleOnChange", value: function handleOnChange(localeValue, localeList) { var value = cb.utils.isEmpty(localeList) ? null : localeList; if (this.props.model) { if (this.state.err) this.props.model.validate(); this.syncViewModel(localeList); if (!this.props.model.execute('valueChange', localeList)) { return; } ; } if (this.props.onChange) { this.props.onChange(localeList); } this.autoTrigger = true; this.setState({ localeList: localeList }); } }, { key: "handleOnBlur", value: function handleOnBlur(localeValue, localeList) { var value = cb.utils.isEmpty(localeList) ? null : localeList; if (this.props.model) { this.props.model.execute('blur'); } else {} if (this.props.onBlur) { this.props.onBlur(value); } this.setState({ focused: false }); } }, { key: "handleInputFocus", value: function handleInputFocus(e) { this.setState({ focused: true }); } }, { key: "onPressEnter", value: function onPressEnter(e) { if (this.props.model) { var value = e && e.target ? e.target.value : e; value = value === '' ? null : value; this.props.model.setValue(value, true); this.props.model.execute('enter', value); } } }, { key: "validate", value: function validate(val) { this.setState({ err: val.type && 'has-' + val.type, msg: val.message }); } }, { key: "baseControl", value: function baseControl() { var _this2 = this; var _this$state = this.state, readOnly = _this$state.readOnly, value = _this$state.value, bIsNull = _this$state.bIsNull, type = _this$state.type, placeholder = _this$state.placeholder, size = _this$state.size, disabled = _this$state.disabled, addonBefore = _this$state.addonBefore, addonAfter = _this$state.addonAfter, format = _this$state.format, iMaxLength = _this$state.iMaxLength, icon = _this$state.icon, before = _this$state.before, after = _this$state.after, bottom = _this$state.bottom, focused = _this$state.focused; var showValue = value, prefix = null, suffix = null, currentLanguage = 'zh_CN'; if (format) { var formatValue = (0, _util.getFormatValue)(value, format); showValue = formatValue.showValue; prefix = formatValue.prefix; suffix = formatValue.suffix; } if (readOnly) return before ? _react["default"].createElement("div", { className: "input-hasBA" }, _react["default"].createElement("span", { className: "input-before" }, before), (0, _text["default"])(showValue)) : (0, _text["default"])(showValue); if (icon) suffix = _react["default"].createElement(_SvgIcon["default"], { type: icon }); var selfProps = { autoComplete: 'new-password', ref: '_acInputLocal', type: type, placeholder: placeholder, size: size, disabled: disabled, addonBefore: addonBefore, addonAfter: addonAfter, onPressEnter: this.onPressEnter, value: cb.utils.isEmpty(value) ? '' : value, prefix: prefix, suffix: suffix, currentLanguage: currentLanguage, localeList: Object.prototype.toString.call(value).toLowerCase() == "[object object]" ? value : (0, _defineProperty2["default"])({}, currentLanguage, value || ""), required: bIsNull == false ? true : false, inputId: String(this.props.id), isPopConfirm: false, sysLocale: 'zh_TW', locale: currentLanguage, status: 'editor', onChange: function onChange(localeValue, localeList) { return _this2.handleOnChange(localeValue, localeList); }, onBlur: function onBlur(localeValue, localeList) { return _this2.handleOnBlur(localeValue, localeList); }, onFocus: function onFocus(e) { return _this2.handleInputFocus(e); } }; if (iMaxLength) selfProps.maxLength = iMaxLength; if (focused || this.props.focus) { selfProps.className = "input_focused"; selfProps.focus = true; } return _react["default"].createElement(_AcInputLocal["default"], selfProps); } }, { key: "relatedControl", value: function relatedControl() { var control = this.baseControl(); var relatedControl = this.props.relatedControl; if (!relatedControl) return control;else return _react["default"].createElement("div", { className: "has-related" }, _react["default"].createElement("div", { className: "viewCell" }, control), relatedControl); } }, { key: "getControl", value: function getControl() { var cShowCaption = this.props.cShowCaption; var title = !this.state.readOnly && this.state.bIsNull === false && cShowCaption ? _react["default"].createElement("label", null, _react["default"].createElement(_antd.Icon, { type: "star" }), cShowCaption) : _react["default"].createElement("label", null, cShowCaption); var control = cShowCaption ? _react["default"].createElement(_label["default"], { control: this.relatedControl(), title: title }) : this.relatedControl(); return control; } }, { key: "render", value: function render() { var control = this.getControl(); var style = this.state.visible ? {} : { display: "none" }; var errClass = "basic-input-".concat(this.state.type, " has-feedback ").concat(this.state.classname || '', " ") + this.state.err; return _react["default"].createElement("div", { style: style, className: errClass }, control, _react["default"].createElement("div", { className: "ant-form-explain" }, this.state.msg)); } }]); return InputMultiLang; }(_react["default"].Component); exports["default"] = InputMultiLang; //# sourceMappingURL=InputMultiLang.js.map