elmer-ui-core
Version:
web app framework
148 lines (147 loc) • 5.58 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Validated = void 0;
var elmer_validation_1 = require("elmer-validation");
var index_1 = require("../../index");
var Validated = (function (_super) {
__extends(Validated, _super);
function Validated() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.isFirstInit = true;
_this.state = {
errorCode: "",
message: "",
pass: true,
theme: "",
};
return _this;
}
Validated.prototype.$init = function () {
if (!this.isEmpty(this.props.sectionId)) {
delete this.validateParams["sectionId"];
Object.defineProperty(this.validateParams, "sectionId", {
configurable: false,
enumerable: false,
value: this.props.sectionId,
writable: false,
});
}
if (!this.isEmpty(this.props.theme)) {
this.state.theme = this.props.theme;
}
var sender = this;
sender.registe({
dataKey: "props.value",
sectionId: sender.validateParams.sectionId,
tagName: this.props.tagName,
validateId: this.props.validateId,
validateType: this.props.validateType
});
if (!this.isEmpty(this.props.value)) {
sender.validate(this.props.validateId, this.props.value, this.props.options);
}
sender = null;
};
Validated.prototype.$dispose = function () {
var sender = this;
sender.unRegiste(sender.validateParams.sectionId, this.props.validateId);
sender = null;
};
Validated.prototype.$after = function () {
if (this.isFirstInit) {
this.isFirstInit = false;
var sender = this;
sender.validate(this.props.validateId, this.props.value, this.props.options);
sender = null;
}
};
Validated.prototype.$onPropsChanged = function (newProps) {
var sender = this;
if (!this.isEmpty(newProps.theme) && newProps.theme !== this.state.theme) {
this.state.theme = newProps.theme;
}
if (sender.validate(this.props.validateId, newProps.value, newProps.options)) {
this.setState({
errorCode: "",
message: "",
pass: true
});
}
sender = null;
};
Validated.prototype.onValidationError = function (errorCode, message, options) {
var sender = this;
if (options.sectionId === sender.validateParams.sectionId && options.validateId === this.props.validateId) {
this.setState({
errorCode: errorCode,
message: message,
pass: false
});
}
sender = null;
};
Validated.prototype.render = function () {
return require("./views/validated.html");
};
Validated.propTypes = {
options: {
description: "IValidatorOptions, 验证扩展参数",
rule: index_1.propTypes.object
},
sectionId: {
description: "挂载section_Id",
rule: index_1.propTypes.string.isRequired
},
tagName: {
description: "批量验证标识",
rule: index_1.propTypes.string
},
theme: {
description: "自定义样式",
rule: index_1.propTypes.string
},
validateId: {
description: "注册验证Id",
rule: index_1.propTypes.string.isRequired
},
validateType: {
description: "ValidatorNames",
rule: index_1.propTypes.string.isRequired
},
value: {
description: "验证的值",
rule: index_1.propTypes.any.isRequired
}
};
Validated = __decorate([
elmer_validation_1.UseValidation({
sectionId: "AutoValidation"
}),
index_1.declareComponent({
selector: "validated"
})
], Validated);
return Validated;
}(index_1.Component));
exports.Validated = Validated;