123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- "use strict";
- var _a;
- Object.defineProperty(exports, "__esModule", { value: true });
- var verification_1 = require("../type/verification");
- var index_1 = require("../tool/toast/index");
- exports.default = (_a = {},
- _a['empty'] = function (value) {
- if (value === undefined || value === null || value !== value) {
- return false;
- }
- else if (typeof value === 'string') {
- value = this.handle.trim(value);
- return value !== '';
- } else if (value instanceof Array) {
- return value.length > 0;
- }
- else {
- return true;
- }
- },
- _a['mobile'] = function (value) {
- if (!value || typeof value === 'object')
- return false;
- else
- value = String(value);
- return /^1\d{10}$/.test(value);
- },
- _a.verificationItem = function (data, toast) {
- var _a;
- if (data.rules !== undefined) {
- var resultRules = void 0;
- if (typeof data.rules === 'string') {
- resultRules = (_a = {}, _a['empty'] = data.rules, _a);
- }
- else {
- resultRules = data.rules;
- }
- for (var key in resultRules) {
- if (resultRules.hasOwnProperty(key) && this[key] && !this[key](data.value, data)) {
- var value = resultRules[key] || data.placeholder || data.label;
- if (toast) {
- var rulesToast = typeof toast === 'boolean' ? 'info' : toast;
- if (index_1.default[rulesToast]) {
- index_1.default[rulesToast](value);
- }
- }
- return {
- verification: false,
- value: value,
- type: key
- };
- }
- }
- return {
- verification: true,
- value: data.value
- };
- }
- return {
- verification: true,
- value: data.value
- };
- },
- _a.verification = function (data, toast) {
- var resultData;
- if (verification_1.default.isObject(data))
- resultData = [data];
- else
- resultData = data;
- var result = {};
- for (var i = 0, count = resultData.length; i < count; i++) {
- var useResult = this.verificationItem(resultData[i], toast);
- if (!useResult.verification) {
- return useResult;
- }
- else {
- var useKey = resultData[i].exportKey || resultData[i].key;
- if (useKey) {
- result[useKey] = useResult.value;
- }
- }
- }
- return {
- verification: true,
- value: result
- };
- },
- _a.verificationPromise = function (data, toast) {
- var _this = this;
- return new Promise(function (resolve, reject) {
- var result = _this.verification(data, toast);
- return result.verification ? resolve(result.value) : reject(result.value);
- });
- },
- _a.handle = {
- trim: function (value) {
- value = value || '';
- if (typeof value !== 'string')
- value += '';
- return value.replace(/^\s*|\s*$/, '');
- }
- },
- _a);
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxxREFBZ0Q7QUFFaEQsNkNBQTZDO0FBRTdDLG1CQUFlO0lBR1gsUUFBb0IsVUFBUyxLQUFTO1FBRWxDLElBQUksS0FBSyxLQUFLLFNBQVMsSUFBSSxLQUFLLEtBQUcsSUFBSSxJQUFJLEtBQUssS0FBSyxLQUFLLEVBQUM7WUFDdkQsT0FBTyxLQUFLLENBQUM7U0FDaEI7YUFBTSxJQUFJLE9BQU8sS0FBSyxLQUFLLFFBQVEsRUFBRTtZQUVsQyxLQUFLLEdBQUcsSUFBSSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUM7WUFFaEMsT0FBTyxLQUFLLEtBQUssRUFBRSxDQUFDO1NBRXZCO2FBQU07WUFDSCxPQUFPLElBQUksQ0FBQztTQUNmO0lBRUwsQ0FBQztJQUdELFFBQXFCLFVBQVMsS0FBUztRQUNuQyxJQUFJLENBQUMsS0FBSyxJQUFJLE9BQU8sS0FBSyxLQUFLLFFBQVE7WUFBRSxPQUFPLEtBQUssQ0FBQzs7WUFDakQsS0FBSyxHQUFHLE1BQU0sQ0FBQyxLQUFLLENBQUMsQ0FBQztRQUMzQixPQUFPLFdBQVcsQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUM7SUFDbkMsQ0FBQztJQUdELG1CQUFnQixHQUFoQixVQUFpQixJQUFJLEVBQUMsS0FBb0I7O1FBRXRDLElBQUksSUFBSSxDQUFDLEtBQUssS0FBSyxTQUFTLEVBQUU7WUFFMUIsSUFBSSxXQUFXLFNBQWEsQ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M7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGZvciAobGV0IGtleSBpbiByZXN1bHRSdWxlcykge1xuXG5cbiAgICAgICAgICAgICAgICBpZiAocmVzdWx0UnVsZXMuaGFzT3duUHJvcGVydHkoa2V5KSAmJiB0aGlzW2tleV0gJiYgIXRoaXNba2V5XShkYXRhLnZhbHVlLGRhdGEpKSB7XG5cbiAgICAgICAgICAgICAgICAgICAgbGV0IHZhbHVlID0gcmVzdWx0UnVsZXNba2V5XSB8fCBkYXRhLnBsYWNlaG9sZGVyIHx8IGRhdGEubGFiZWw7XG5cbiAgICAgICAgICAgICAgICAgICAgLy8g5aaC5p6c5LiN6YCa6L+HLOaYr+WQpuiHquWKqOaPkOekulxuICAgICAgICAgICAgICAgICAgICBpZiAodG9hc3QpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBydWxlc1RvYXN0ID0gdHlwZW9mIHRvYXN0ID09PSAnYm9vbGVhbicgPyAnaW5mbycgOiB0b2FzdDtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0b2FzdE1vZGFsW3J1bGVzVG9hc3RdKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdG9hc3RNb2RhbFtydWxlc1RvYXN0XSh2YWx1ZSk7XG4gICAgICAgICAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHZlcmlmaWNhdGlvbjogZmFsc2UsXG4gICAgICAgICAgICAgICAgICAgICAgICB2YWx1ZSxcbiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU6IGtleSBhcyB1bmtub3duIGFzIExpYlRlc3RUeXBlXG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHJldHVybiAge1xuICAgICAgICAgICAgICAgIHZlcmlmaWNhdGlvbjp0cnVlLFxuICAgICAgICAgICAgICAgIHZhbHVlOiBkYXRhLnZhbHVlXG4gICAgICAgICAgICB9XG5cblxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuICB7XG4gICAgICAgICAgICB2ZXJpZmljYXRpb246IHRydWUsXG4gICAgICAgICAgICB2YWx1ZTpkYXRhLnZhbHVlXG4gICAgICAgIH1cblxuICAgIH0sXG5cbiAgICAvLyDmoKHpqoxcbiAgICB2ZXJpZmljYXRpb24oZGF0YSx0b2FzdDpib29sZWFufHN0cmluZyk6TGliVGVzdEl0ZW1SZXN1bHR7XG5cbiAgICAgICAgbGV0IHJlc3VsdERhdGE6TGliRGF0YUFycmF5O1xuICAgICAgICBpZiAodmVyaWZpY2F0aW9uLmlzT2JqZWN0KGRhdGEpKSByZXN1bHREYXRhID0gW2RhdGEgYXMgTGliRGF0YV07XG4gICAgICAgIGVsc2UgcmVzdWx0RGF0YSA9IGRhdGEgYXMgTGliRGF0YUFycmF5O1xuXG4gICAgICAgIGxldCByZXN1bHQ6UmVjb3JkPHN0cmluZywgYW55PiA9IHt9O1xuXG4gICAgICAgIGZvciAobGV0IGk9MCxjb3VudD1yZXN1bHREYXRhLmxlbmd0aDtpPGNvdW50O2krKykge1xuXG4gICAgICAgICAgICBsZXQgdXNlUmVzdWx0OkxpYlRlc3RJdGVtUmVzdWx0ID0gdGhpcy52ZXJpZmljYXRpb25JdGVtKHJlc3VsdERhdGFbaV0sdG9hc3QpO1xuXG4gICAgICAgICAgICBpZiAoIXVzZVJlc3VsdC52ZXJpZmljYXRpb24pIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gdXNlUmVzdWx0O1xuICAgICAgICAgICAgfSBlbHNlIHtcblxuICAgICAgICAgICAgICAgIGxldCB1c2VLZXkgPSByZXN1bHREYXRhW2ldLmV4cG9ydEtleSB8fCByZXN1bHREYXRhW2ldLmtleTtcblxuICAgICAgICAgICAgICAgIGlmICh1c2VLZXkpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzdWx0W3VzZUtleV0gPSB1c2VSZXN1bHQudmFsdWU7XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB9XG5cbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICB2ZXJpZmljYXRpb246dHJ1ZSxcbiAgICAgICAgICAgIHZhbHVlOnJlc3VsdFxuICAgICAgICB9XG5cblxuICAgIH0sXG5cbiAgICAvLyDmoKHpqozov5Tlm54gUHJvbWlzZVxuICAgIHZlcmlmaWNhdGlvblByb21pc2UoZGF0YSx0b2FzdDpib29sZWFufHN0cmluZyk6UHJvbWlzZTxSZWNvcmQ8c3RyaW5nLCBhbnk+PntcblxuICAgICAgICByZXR1cm4gIG5ldyBQcm9taXNlPFJlY29yZDxzdHJpbmcsIGFueT4+KCAocmVzb2x2ZSxyZWplY3QpPT57XG4gICAgICAgICAgICBsZXQgcmVzdWx0OkxpYlRlc3RJdGVtUmVzdWx0ID0gdGhpcy52ZXJpZmljYXRpb24oZGF0YSx0b2FzdCk7XG4gICAgICAgICAgICByZXR1cm4gcmVzdWx0LnZlcmlmaWNhdGlvbiA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IHJlamVjdChyZXN1bHQudmFsdWUpO1xuICAgICAgICB9KTtcblxuICAgIH0sXG5cblxuXG4gICAgaGFuZGxlOntcbiAgICAgICAgdHJpbTpmdW5jdGlvbih2YWx1ZTphbnkpe1xuICAgICAgICAgICAgdmFsdWUgPSB2YWx1ZSB8fCAnJztcbiAgICAgICAgICAgIGlmICh0eXBlb2YgdmFsdWUgIT09ICdzdHJpbmcnKSAgdmFsdWUgKz0nJztcbiAgICAgICAgICAgIHJldHVybiB2YWx1ZS5yZXBsYWNlKC9eXFxzKnxcXHMqJC8sJycpO1xuICAgICAgICB9XG4gICAgfVxuXG5cblxufSJdfQ==
|