choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
194 lines (161 loc) • 5.36 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _get from "@babel/runtime/helpers/get";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import { __decorate } from "tslib";
import React from 'react';
import { observer } from 'mobx-react';
import { computed, isArrayLike } from 'mobx';
import isPlainObject from 'lodash/isPlainObject';
import isNil from 'lodash/isNil';
import omit from 'lodash/omit';
import { getConfig } from '../../../es/configure';
import { FormField } from '../field/FormField';
import autobind from '../_util/autobind';
import { BooleanValue, FieldType } from '../data-set/enum';
import ObserverCheckBox from '../check-box/CheckBox';
import { processFieldValue } from '../data-set/utils';
import isEmpty from '../_util/isEmpty';
var Output =
/*#__PURE__*/
function (_FormField) {
_inherits(Output, _FormField);
var _super = _createSuper(Output);
function Output() {
_classCallCheck(this, Output);
return _super.apply(this, arguments);
}
_createClass(Output, [{
key: "useFocusedClassName",
value: function useFocusedClassName() {
return false;
}
}, {
key: "handleChange",
value: function handleChange() {}
}, {
key: "getOtherProps",
value: function getOtherProps() {
return omit(_get(_getPrototypeOf(Output.prototype), "getOtherProps", this).call(this), ['name']);
}
}, {
key: "getValueKey",
value: function getValueKey(value) {
if (isArrayLike(value)) {
return value.map(this.getValueKey, this).join(',');
}
return this.processValue(value);
}
}, {
key: "processValue",
value: function processValue(value) {
if (!isNil(value)) {
var text = isPlainObject(value) ? value : _get(_getPrototypeOf(Output.prototype), "processValue", this).call(this, value);
var field = this.field,
lang = this.lang;
if (field) {
return processFieldValue(text, field, lang, true);
}
return text;
}
return '';
}
}, {
key: "defaultRenderer",
value: function defaultRenderer(_ref) {
var value = _ref.value,
text = _ref.text,
repeat = _ref.repeat,
maxTagTextLength = _ref.maxTagTextLength;
var field = this.field;
if (field && field.type === FieldType["boolean"]) {
return React.createElement(ObserverCheckBox, {
disabled: true,
checked: value === field.get(BooleanValue.trueValue)
});
}
var result = _get(_getPrototypeOf(Output.prototype), "defaultRenderer", this).call(this, {
text: text,
repeat: repeat,
maxTagTextLength: maxTagTextLength
});
return isEmpty(result) ? getConfig('renderEmpty')('Output') : result;
}
}, {
key: "getRenderedValue",
value: function getRenderedValue() {
var multiple = this.multiple,
range = this.range,
multiLine = this.multiLine,
currency = this.currency;
if (multiple) {
return this.renderMultipleValues(true);
}
if (range) {
return this.renderRangeValue(true);
}
/**
* 多行单元格渲染
*/
if (multiLine) {
return this.renderMultiLine(true);
}
/**
* 货币渲染
*/
if (currency) {
return this.renderCurrency(true);
}
return this.getTextNode() === '' ? getConfig('tableDefaultRenderer') : this.getTextNode();
}
}, {
key: "renderWrapper",
value: function renderWrapper() {
return React.createElement("span", _extends({}, this.getMergedProps()), this.getRenderedValue());
}
}, {
key: "editable",
get: function get() {
return false;
}
}]);
return Output;
}(FormField);
Output.displayName = 'Output';
Output.defaultProps = _objectSpread({}, FormField.defaultProps, {
suffixCls: 'output'
});
__decorate([computed], Output.prototype, "editable", null);
__decorate([autobind], Output.prototype, "handleChange", null);
__decorate([autobind], Output.prototype, "defaultRenderer", null);
Output = __decorate([observer], Output);
export default Output;
//# sourceMappingURL=Output.js.map