UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

92 lines (91 loc) 3.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LionCalcTplRenderer = exports.LionCalcTpl = void 0; var tslib_1 = require("tslib"); // 更新模板计算数值到数据域 var react_1 = (0, tslib_1.__importDefault)(require("react")); var factory_1 = require("../../../../factory"); var tpl_1 = require("../../../../utils/tpl"); var helper_1 = require("../../../../utils/helper"); var tpl_builtin_1 = require("../../../../utils/tpl-builtin"); var Badge_1 = require("../../../../components/Badge"); var LionCalcTpl = /** @class */ (function (_super) { (0, tslib_1.__extends)(LionCalcTpl, _super); function LionCalcTpl(props) { var _this = _super.call(this, props) || this; _this.state = { content: "" }; return _this; } LionCalcTpl.prototype.getContent = function () { var _a = this.props, tpl = _a.tpl, html = _a.html, text = _a.text, raw = _a.raw, data = _a.data, placeholder = _a.placeholder; var value = (0, helper_1.getPropValue)(this.props); if (raw) { return raw; } else if (html) { return (0, tpl_1.filter)(html, data); } else if (tpl) { return (0, tpl_1.filter)(tpl, data); } else if (text) { return (0, tpl_builtin_1.escapeHtml)((0, tpl_1.filter)(text, data)); } else { return value == null || value === '' ? "<span class=\"text-muted\">" + placeholder + "</span>" : typeof value === 'string' ? value : JSON.stringify(value); } }; LionCalcTpl.prototype.componentWillMount = function () { this.updateValue(); }; LionCalcTpl.prototype.componentDidUpdate = function () { this.updateValue(); }; LionCalcTpl.prototype.updateValue = function () { var _a = this.props, name = _a.name, onQuickChange = _a.onQuickChange; var value = this.getContent(); if (value !== this.state.content) { this.setState({ content: value }, function () { var _a; // 发送计算好的数值到上层,isUpdate 是否经过更新 onQuickChange && onQuickChange((_a = {}, _a[name] = value, _a)); }); } }; LionCalcTpl.prototype.render = function () { var _a = this.props, className = _a.className, wrapperComponent = _a.wrapperComponent, inline = _a.inline, cx = _a.classnames, style = _a.style; var Component = wrapperComponent || (inline ? 'span' : 'div'); return (react_1.default.createElement(Component, { className: cx('LionCalcTplField', className), style: style }, this.state.content)); }; LionCalcTpl.defaultProps = { wrapperComponent: '', inline: true, placeholder: '-' }; return LionCalcTpl; }(react_1.default.Component)); exports.LionCalcTpl = LionCalcTpl; var LionCalcTplRenderer = /** @class */ (function (_super) { (0, tslib_1.__extends)(LionCalcTplRenderer, _super); function LionCalcTplRenderer() { return _super !== null && _super.apply(this, arguments) || this; } LionCalcTplRenderer = (0, tslib_1.__decorate)([ (0, factory_1.Renderer)({ test: /(^|\/)(?:lion-calc-tpl|lion-calc-html)$/, name: 'lion-calc-tpl' }) // @ts-ignore 类型没搞定 , Badge_1.withBadge ], LionCalcTplRenderer); return LionCalcTplRenderer; }(LionCalcTpl)); exports.LionCalcTplRenderer = LionCalcTplRenderer; //# sourceMappingURL=./renderers/Lion/components/LionCalcTpl/LionCalcTpl.js.map