fastlion-amis
Version:
一种MIS页面生成工具
75 lines (74 loc) • 4.36 kB
JavaScript
/**
* @file Button
* @author fex
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Button = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var TooltipWrapper_1 = (0, tslib_1.__importDefault)(require("./TooltipWrapper"));
var helper_1 = require("../utils/helper");
var theme_1 = require("../theme");
var icons_1 = require("./icons");
var Button = /** @class */ (function (_super) {
(0, tslib_1.__extends)(Button, _super);
function Button() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.lastSubmitTime = 0; // 最后一次提交的时间
return _this;
}
Button.prototype.renderButton = function () {
var _a, _b;
var _this = this;
var _c = this.props, level = _c.level, size = _c.size, disabled = _c.disabled, className = _c.className, Comp = _c.componentClass, cx = _c.classnames, children = _c.children, disabledTip = _c.disabledTip, block = _c.block, type = _c.type, active = _c.active, iconOnly = _c.iconOnly, href = _c.href, loading = _c.loading, loadingClassName = _c.loadingClassName, overrideClassName = _c.overrideClassName, butColor = _c.butColor, refDom = _c.refDom, title = _c.title, rest = (0, tslib_1.__rest)(_c, ["level", "size", "disabled", "className", "componentClass", "classnames", "children", "disabledTip", "block", "type", "active", "iconOnly", "href", "loading", "loadingClassName", "overrideClassName", "butColor", "refDom", "title"]);
if (href) {
Comp = 'a';
}
else if (loading) {
Comp = 'div';
}
return (react_1.default.createElement(Comp, (0, tslib_1.__assign)({ type: Comp === 'input' || Comp === 'button' ? type : undefined }, (0, helper_1.pickEventsProps)(rest), { onClick: function (e) {
var _a;
var currentTime = Date.now();
// 判断是否超过了设定的延迟时间
if (currentTime - _this.lastSubmitTime >= 500) {
rest.onClick && disabled ? function () { } : (_a = rest.onClick) === null || _a === void 0 ? void 0 : _a.call(rest, e);
_this.lastSubmitTime = currentTime;
}
}, title: title ? title : '', href: href, className: cx(overrideClassName
? ''
: (_a = {
'Button': true
},
_a["Button--" + level] = level,
_a["Button--" + size] = size,
_a["Button--block"] = block,
_a["Button--iconOnly"] = iconOnly,
_a['is-disabled'] = disabled,
_a['is-active'] = active,
_a['in-state'] = butColor,
_a), className), disabled: disabled, ref: refDom }),
loading && !disabled ? (react_1.default.createElement("span", { className: cx(overrideClassName
? ''
: (_b = {}, _b["Button--loading Button--loading--" + level] = level, _b), loadingClassName) },
react_1.default.createElement(icons_1.Icon, { icon: "loading-outline", className: "icon" }))) : null,
children));
};
Button.prototype.render = function () {
var _a = this.props, tooltip = _a.tooltip, tooltipPlacement = _a.tooltipPlacement, tooltipContainer = _a.tooltipContainer, tooltipTrigger = _a.tooltipTrigger, tooltipRootClose = _a.tooltipRootClose, disabled = _a.disabled, disabledTip = _a.disabledTip, cx = _a.classnames;
return (react_1.default.createElement(TooltipWrapper_1.default, { placement: tooltipPlacement, tooltip: disabled ? disabledTip : tooltip, container: tooltipContainer, trigger: tooltipTrigger, rootClose: tooltipRootClose }, this.renderButton()));
};
Button.defaultProps = {
componentClass: 'button',
level: 'default',
type: 'button',
tooltipPlacement: 'top',
tooltipTrigger: ['hover', 'focus'],
tooltipRootClose: false
};
return Button;
}(react_1.default.Component));
exports.Button = Button;
exports.default = (0, theme_1.themeable)(Button);
//# sourceMappingURL=./components/Button.js.map
;