|
@@ -26719,6 +26719,1180 @@ var _default = {
|
|
|
};
|
|
|
exports.default = _default;
|
|
|
|
|
|
+/***/ }),
|
|
|
+/* 362 */,
|
|
|
+/* 363 */,
|
|
|
+/* 364 */,
|
|
|
+/* 365 */,
|
|
|
+/* 366 */,
|
|
|
+/* 367 */,
|
|
|
+/* 368 */,
|
|
|
+/* 369 */,
|
|
|
+/* 370 */,
|
|
|
+/* 371 */,
|
|
|
+/* 372 */,
|
|
|
+/* 373 */,
|
|
|
+/* 374 */,
|
|
|
+/* 375 */,
|
|
|
+/* 376 */,
|
|
|
+/* 377 */,
|
|
|
+/* 378 */,
|
|
|
+/* 379 */,
|
|
|
+/* 380 */,
|
|
|
+/* 381 */,
|
|
|
+/* 382 */,
|
|
|
+/* 383 */,
|
|
|
+/* 384 */,
|
|
|
+/* 385 */,
|
|
|
+/* 386 */,
|
|
|
+/* 387 */,
|
|
|
+/* 388 */,
|
|
|
+/* 389 */,
|
|
|
+/* 390 */,
|
|
|
+/* 391 */,
|
|
|
+/* 392 */,
|
|
|
+/* 393 */,
|
|
|
+/* 394 */,
|
|
|
+/* 395 */,
|
|
|
+/* 396 */,
|
|
|
+/* 397 */,
|
|
|
+/* 398 */,
|
|
|
+/* 399 */,
|
|
|
+/* 400 */,
|
|
|
+/* 401 */,
|
|
|
+/* 402 */,
|
|
|
+/* 403 */,
|
|
|
+/* 404 */,
|
|
|
+/* 405 */,
|
|
|
+/* 406 */,
|
|
|
+/* 407 */,
|
|
|
+/* 408 */,
|
|
|
+/* 409 */,
|
|
|
+/* 410 */,
|
|
|
+/* 411 */,
|
|
|
+/* 412 */,
|
|
|
+/* 413 */,
|
|
|
+/* 414 */,
|
|
|
+/* 415 */,
|
|
|
+/* 416 */,
|
|
|
+/* 417 */,
|
|
|
+/* 418 */,
|
|
|
+/* 419 */,
|
|
|
+/* 420 */,
|
|
|
+/* 421 */,
|
|
|
+/* 422 */,
|
|
|
+/* 423 */,
|
|
|
+/* 424 */,
|
|
|
+/* 425 */,
|
|
|
+/* 426 */,
|
|
|
+/* 427 */,
|
|
|
+/* 428 */,
|
|
|
+/* 429 */,
|
|
|
+/* 430 */,
|
|
|
+/* 431 */
|
|
|
+/*!***********************************************************************************************!*\
|
|
|
+ !*** D:/demo/businessCard/xiaochengxu/uni_modules/uni-forms/components/uni-forms/validate.js ***!
|
|
|
+ \***********************************************************************************************/
|
|
|
+/*! no static exports found */
|
|
|
+/***/ (function(module, exports, __webpack_require__) {
|
|
|
+
|
|
|
+"use strict";
|
|
|
+
|
|
|
+
|
|
|
+var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4);
|
|
|
+Object.defineProperty(exports, "__esModule", {
|
|
|
+ value: true
|
|
|
+});
|
|
|
+exports.default = void 0;
|
|
|
+var _regenerator = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/regenerator */ 75));
|
|
|
+var _inherits2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/inherits */ 432));
|
|
|
+var _possibleConstructorReturn2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ 433));
|
|
|
+var _getPrototypeOf2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ 435));
|
|
|
+var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ 77));
|
|
|
+var _classCallCheck2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ 23));
|
|
|
+var _createClass2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/createClass */ 24));
|
|
|
+var _typeof2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/typeof */ 13));
|
|
|
+function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
|
+function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
|
+var pattern = {
|
|
|
+ email: /^\S+?@\S+?\.\S+?$/,
|
|
|
+ idcard: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
|
|
|
+ url: new RegExp("^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$", 'i')
|
|
|
+};
|
|
|
+var FORMAT_MAPPING = {
|
|
|
+ "int": 'integer',
|
|
|
+ "bool": 'boolean',
|
|
|
+ "double": 'number',
|
|
|
+ "long": 'number',
|
|
|
+ "password": 'string'
|
|
|
+ // "fileurls": 'array'
|
|
|
+};
|
|
|
+
|
|
|
+function formatMessage(args) {
|
|
|
+ var resources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
|
+ var defaultMessage = ['label'];
|
|
|
+ defaultMessage.forEach(function (item) {
|
|
|
+ if (args[item] === undefined) {
|
|
|
+ args[item] = '';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ var str = resources;
|
|
|
+ for (var key in args) {
|
|
|
+ var reg = new RegExp('{' + key + '}');
|
|
|
+ str = str.replace(reg, args[key]);
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+}
|
|
|
+function isEmptyValue(value, type) {
|
|
|
+ if (value === undefined || value === null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (typeof value === 'string' && !value) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (Array.isArray(value) && !value.length) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (type === 'object' && !Object.keys(value).length) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+var types = {
|
|
|
+ integer: function integer(value) {
|
|
|
+ return types.number(value) && parseInt(value, 10) === value;
|
|
|
+ },
|
|
|
+ string: function string(value) {
|
|
|
+ return typeof value === 'string';
|
|
|
+ },
|
|
|
+ number: function number(value) {
|
|
|
+ if (isNaN(value)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return typeof value === 'number';
|
|
|
+ },
|
|
|
+ "boolean": function boolean(value) {
|
|
|
+ return typeof value === 'boolean';
|
|
|
+ },
|
|
|
+ "float": function float(value) {
|
|
|
+ return types.number(value) && !types.integer(value);
|
|
|
+ },
|
|
|
+ array: function array(value) {
|
|
|
+ return Array.isArray(value);
|
|
|
+ },
|
|
|
+ object: function object(value) {
|
|
|
+ return (0, _typeof2.default)(value) === 'object' && !types.array(value);
|
|
|
+ },
|
|
|
+ date: function date(value) {
|
|
|
+ return value instanceof Date;
|
|
|
+ },
|
|
|
+ timestamp: function timestamp(value) {
|
|
|
+ if (!this.integer(value) || Math.abs(value).toString().length > 16) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ file: function file(value) {
|
|
|
+ return typeof value.url === 'string';
|
|
|
+ },
|
|
|
+ email: function email(value) {
|
|
|
+ return typeof value === 'string' && !!value.match(pattern.email) && value.length < 255;
|
|
|
+ },
|
|
|
+ url: function url(value) {
|
|
|
+ return typeof value === 'string' && !!value.match(pattern.url);
|
|
|
+ },
|
|
|
+ pattern: function pattern(reg, value) {
|
|
|
+ try {
|
|
|
+ return new RegExp(reg).test(value);
|
|
|
+ } catch (e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ method: function method(value) {
|
|
|
+ return typeof value === 'function';
|
|
|
+ },
|
|
|
+ idcard: function idcard(value) {
|
|
|
+ return typeof value === 'string' && !!value.match(pattern.idcard);
|
|
|
+ },
|
|
|
+ 'url-https': function urlHttps(value) {
|
|
|
+ return this.url(value) && value.startsWith('https://');
|
|
|
+ },
|
|
|
+ 'url-scheme': function urlScheme(value) {
|
|
|
+ return value.startsWith('://');
|
|
|
+ },
|
|
|
+ 'url-web': function urlWeb(value) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+};
|
|
|
+var RuleValidator = /*#__PURE__*/function () {
|
|
|
+ function RuleValidator(message) {
|
|
|
+ (0, _classCallCheck2.default)(this, RuleValidator);
|
|
|
+ this._message = message;
|
|
|
+ }
|
|
|
+ (0, _createClass2.default)(RuleValidator, [{
|
|
|
+ key: "validateRule",
|
|
|
+ value: function () {
|
|
|
+ var _validateRule = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(fieldKey, fieldValue, value, data, allData) {
|
|
|
+ var result, rules, hasRequired, message, i, rule, vt, now, resultExpr;
|
|
|
+ return _regenerator.default.wrap(function _callee$(_context) {
|
|
|
+ while (1) {
|
|
|
+ switch (_context.prev = _context.next) {
|
|
|
+ case 0:
|
|
|
+ result = null;
|
|
|
+ rules = fieldValue.rules;
|
|
|
+ hasRequired = rules.findIndex(function (item) {
|
|
|
+ return item.required;
|
|
|
+ });
|
|
|
+ if (!(hasRequired < 0)) {
|
|
|
+ _context.next = 8;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (!(value === null || value === undefined)) {
|
|
|
+ _context.next = 6;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return _context.abrupt("return", result);
|
|
|
+ case 6:
|
|
|
+ if (!(typeof value === 'string' && !value.length)) {
|
|
|
+ _context.next = 8;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return _context.abrupt("return", result);
|
|
|
+ case 8:
|
|
|
+ message = this._message;
|
|
|
+ if (!(rules === undefined)) {
|
|
|
+ _context.next = 11;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return _context.abrupt("return", message['default']);
|
|
|
+ case 11:
|
|
|
+ i = 0;
|
|
|
+ case 12:
|
|
|
+ if (!(i < rules.length)) {
|
|
|
+ _context.next = 35;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ rule = rules[i];
|
|
|
+ vt = this._getValidateType(rule);
|
|
|
+ Object.assign(rule, {
|
|
|
+ label: fieldValue.label || "[\"".concat(fieldKey, "\"]")
|
|
|
+ });
|
|
|
+ if (!RuleValidatorHelper[vt]) {
|
|
|
+ _context.next = 20;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ result = RuleValidatorHelper[vt](rule, value, message);
|
|
|
+ if (!(result != null)) {
|
|
|
+ _context.next = 20;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return _context.abrupt("break", 35);
|
|
|
+ case 20:
|
|
|
+ if (!rule.validateExpr) {
|
|
|
+ _context.next = 26;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ now = Date.now();
|
|
|
+ resultExpr = rule.validateExpr(value, allData, now);
|
|
|
+ if (!(resultExpr === false)) {
|
|
|
+ _context.next = 26;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ result = this._getMessage(rule, rule.errorMessage || this._message['default']);
|
|
|
+ return _context.abrupt("break", 35);
|
|
|
+ case 26:
|
|
|
+ if (!rule.validateFunction) {
|
|
|
+ _context.next = 32;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ _context.next = 29;
|
|
|
+ return this.validateFunction(rule, value, data, allData, vt);
|
|
|
+ case 29:
|
|
|
+ result = _context.sent;
|
|
|
+ if (!(result !== null)) {
|
|
|
+ _context.next = 32;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return _context.abrupt("break", 35);
|
|
|
+ case 32:
|
|
|
+ i++;
|
|
|
+ _context.next = 12;
|
|
|
+ break;
|
|
|
+ case 35:
|
|
|
+ if (result !== null) {
|
|
|
+ result = message.TAG + result;
|
|
|
+ }
|
|
|
+ return _context.abrupt("return", result);
|
|
|
+ case 37:
|
|
|
+ case "end":
|
|
|
+ return _context.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, _callee, this);
|
|
|
+ }));
|
|
|
+ function validateRule(_x, _x2, _x3, _x4, _x5) {
|
|
|
+ return _validateRule.apply(this, arguments);
|
|
|
+ }
|
|
|
+ return validateRule;
|
|
|
+ }()
|
|
|
+ }, {
|
|
|
+ key: "validateFunction",
|
|
|
+ value: function () {
|
|
|
+ var _validateFunction = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(rule, value, data, allData, vt) {
|
|
|
+ var result, callbackMessage, res;
|
|
|
+ return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
|
+ while (1) {
|
|
|
+ switch (_context2.prev = _context2.next) {
|
|
|
+ case 0:
|
|
|
+ result = null;
|
|
|
+ _context2.prev = 1;
|
|
|
+ callbackMessage = null;
|
|
|
+ _context2.next = 5;
|
|
|
+ return rule.validateFunction(rule, value, allData || data, function (message) {
|
|
|
+ callbackMessage = message;
|
|
|
+ });
|
|
|
+ case 5:
|
|
|
+ res = _context2.sent;
|
|
|
+ if (callbackMessage || typeof res === 'string' && res || res === false) {
|
|
|
+ result = this._getMessage(rule, callbackMessage || res, vt);
|
|
|
+ }
|
|
|
+ _context2.next = 12;
|
|
|
+ break;
|
|
|
+ case 9:
|
|
|
+ _context2.prev = 9;
|
|
|
+ _context2.t0 = _context2["catch"](1);
|
|
|
+ result = this._getMessage(rule, _context2.t0.message, vt);
|
|
|
+ case 12:
|
|
|
+ return _context2.abrupt("return", result);
|
|
|
+ case 13:
|
|
|
+ case "end":
|
|
|
+ return _context2.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, _callee2, this, [[1, 9]]);
|
|
|
+ }));
|
|
|
+ function validateFunction(_x6, _x7, _x8, _x9, _x10) {
|
|
|
+ return _validateFunction.apply(this, arguments);
|
|
|
+ }
|
|
|
+ return validateFunction;
|
|
|
+ }()
|
|
|
+ }, {
|
|
|
+ key: "_getMessage",
|
|
|
+ value: function _getMessage(rule, message, vt) {
|
|
|
+ return formatMessage(rule, message || rule.errorMessage || this._message[vt] || message['default']);
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: "_getValidateType",
|
|
|
+ value: function _getValidateType(rule) {
|
|
|
+ var result = '';
|
|
|
+ if (rule.required) {
|
|
|
+ result = 'required';
|
|
|
+ } else if (rule.format) {
|
|
|
+ result = 'format';
|
|
|
+ } else if (rule.arrayType) {
|
|
|
+ result = 'arrayTypeFormat';
|
|
|
+ } else if (rule.range) {
|
|
|
+ result = 'range';
|
|
|
+ } else if (rule.maximum !== undefined || rule.minimum !== undefined) {
|
|
|
+ result = 'rangeNumber';
|
|
|
+ } else if (rule.maxLength !== undefined || rule.minLength !== undefined) {
|
|
|
+ result = 'rangeLength';
|
|
|
+ } else if (rule.pattern) {
|
|
|
+ result = 'pattern';
|
|
|
+ } else if (rule.validateFunction) {
|
|
|
+ result = 'validateFunction';
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+ return RuleValidator;
|
|
|
+}();
|
|
|
+var RuleValidatorHelper = {
|
|
|
+ required: function required(rule, value, message) {
|
|
|
+ if (rule.required && isEmptyValue(value, rule.format || (0, _typeof2.default)(value))) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message.required);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+ range: function range(rule, value, message) {
|
|
|
+ var range = rule.range,
|
|
|
+ errorMessage = rule.errorMessage;
|
|
|
+ var list = new Array(range.length);
|
|
|
+ for (var i = 0; i < range.length; i++) {
|
|
|
+ var item = range[i];
|
|
|
+ if (types.object(item) && item.value !== undefined) {
|
|
|
+ list[i] = item.value;
|
|
|
+ } else {
|
|
|
+ list[i] = item;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var result = false;
|
|
|
+ if (Array.isArray(value)) {
|
|
|
+ result = new Set(value.concat(list)).size === list.length;
|
|
|
+ } else {
|
|
|
+ if (list.indexOf(value) > -1) {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!result) {
|
|
|
+ return formatMessage(rule, errorMessage || message['enum']);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+ rangeNumber: function rangeNumber(rule, value, message) {
|
|
|
+ if (!types.number(value)) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message.pattern.mismatch);
|
|
|
+ }
|
|
|
+ var minimum = rule.minimum,
|
|
|
+ maximum = rule.maximum,
|
|
|
+ exclusiveMinimum = rule.exclusiveMinimum,
|
|
|
+ exclusiveMaximum = rule.exclusiveMaximum;
|
|
|
+ var min = exclusiveMinimum ? value <= minimum : value < minimum;
|
|
|
+ var max = exclusiveMaximum ? value >= maximum : value > maximum;
|
|
|
+ if (minimum !== undefined && min) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message['number'][exclusiveMinimum ? 'exclusiveMinimum' : 'minimum']);
|
|
|
+ } else if (maximum !== undefined && max) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message['number'][exclusiveMaximum ? 'exclusiveMaximum' : 'maximum']);
|
|
|
+ } else if (minimum !== undefined && maximum !== undefined && (min || max)) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message['number'].range);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+ rangeLength: function rangeLength(rule, value, message) {
|
|
|
+ if (!types.string(value) && !types.array(value)) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message.pattern.mismatch);
|
|
|
+ }
|
|
|
+ var min = rule.minLength;
|
|
|
+ var max = rule.maxLength;
|
|
|
+ var val = value.length;
|
|
|
+ if (min !== undefined && val < min) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message['length'].minLength);
|
|
|
+ } else if (max !== undefined && val > max) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message['length'].maxLength);
|
|
|
+ } else if (min !== undefined && max !== undefined && (val < min || val > max)) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message['length'].range);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+ pattern: function pattern(rule, value, message) {
|
|
|
+ if (!types['pattern'](rule.pattern, value)) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message.pattern.mismatch);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+ format: function format(rule, value, message) {
|
|
|
+ var customTypes = Object.keys(types);
|
|
|
+ var format = FORMAT_MAPPING[rule.format] ? FORMAT_MAPPING[rule.format] : rule.format || rule.arrayType;
|
|
|
+ if (customTypes.indexOf(format) > -1) {
|
|
|
+ if (!types[format](value)) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message.typeError);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+ arrayTypeFormat: function arrayTypeFormat(rule, value, message) {
|
|
|
+ if (!Array.isArray(value)) {
|
|
|
+ return formatMessage(rule, rule.errorMessage || message.typeError);
|
|
|
+ }
|
|
|
+ for (var i = 0; i < value.length; i++) {
|
|
|
+ var element = value[i];
|
|
|
+ var formatResult = this.format(rule, element, message);
|
|
|
+ if (formatResult !== null) {
|
|
|
+ return formatResult;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+};
|
|
|
+var SchemaValidator = /*#__PURE__*/function (_RuleValidator) {
|
|
|
+ (0, _inherits2.default)(SchemaValidator, _RuleValidator);
|
|
|
+ var _super = _createSuper(SchemaValidator);
|
|
|
+ function SchemaValidator(schema, options) {
|
|
|
+ var _this;
|
|
|
+ (0, _classCallCheck2.default)(this, SchemaValidator);
|
|
|
+ _this = _super.call(this, SchemaValidator.message);
|
|
|
+ _this._schema = schema;
|
|
|
+ _this._options = options || null;
|
|
|
+ return _this;
|
|
|
+ }
|
|
|
+ (0, _createClass2.default)(SchemaValidator, [{
|
|
|
+ key: "updateSchema",
|
|
|
+ value: function updateSchema(schema) {
|
|
|
+ this._schema = schema;
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: "validate",
|
|
|
+ value: function () {
|
|
|
+ var _validate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(data, allData) {
|
|
|
+ var result;
|
|
|
+ return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
|
+ while (1) {
|
|
|
+ switch (_context3.prev = _context3.next) {
|
|
|
+ case 0:
|
|
|
+ result = this._checkFieldInSchema(data);
|
|
|
+ if (result) {
|
|
|
+ _context3.next = 5;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ _context3.next = 4;
|
|
|
+ return this.invokeValidate(data, false, allData);
|
|
|
+ case 4:
|
|
|
+ result = _context3.sent;
|
|
|
+ case 5:
|
|
|
+ return _context3.abrupt("return", result.length ? result[0] : null);
|
|
|
+ case 6:
|
|
|
+ case "end":
|
|
|
+ return _context3.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, _callee3, this);
|
|
|
+ }));
|
|
|
+ function validate(_x11, _x12) {
|
|
|
+ return _validate.apply(this, arguments);
|
|
|
+ }
|
|
|
+ return validate;
|
|
|
+ }()
|
|
|
+ }, {
|
|
|
+ key: "validateAll",
|
|
|
+ value: function () {
|
|
|
+ var _validateAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(data, allData) {
|
|
|
+ var result;
|
|
|
+ return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
|
+ while (1) {
|
|
|
+ switch (_context4.prev = _context4.next) {
|
|
|
+ case 0:
|
|
|
+ result = this._checkFieldInSchema(data);
|
|
|
+ if (result) {
|
|
|
+ _context4.next = 5;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ _context4.next = 4;
|
|
|
+ return this.invokeValidate(data, true, allData);
|
|
|
+ case 4:
|
|
|
+ result = _context4.sent;
|
|
|
+ case 5:
|
|
|
+ return _context4.abrupt("return", result);
|
|
|
+ case 6:
|
|
|
+ case "end":
|
|
|
+ return _context4.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, _callee4, this);
|
|
|
+ }));
|
|
|
+ function validateAll(_x13, _x14) {
|
|
|
+ return _validateAll.apply(this, arguments);
|
|
|
+ }
|
|
|
+ return validateAll;
|
|
|
+ }()
|
|
|
+ }, {
|
|
|
+ key: "validateUpdate",
|
|
|
+ value: function () {
|
|
|
+ var _validateUpdate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(data, allData) {
|
|
|
+ var result;
|
|
|
+ return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
|
+ while (1) {
|
|
|
+ switch (_context5.prev = _context5.next) {
|
|
|
+ case 0:
|
|
|
+ result = this._checkFieldInSchema(data);
|
|
|
+ if (result) {
|
|
|
+ _context5.next = 5;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ _context5.next = 4;
|
|
|
+ return this.invokeValidateUpdate(data, false, allData);
|
|
|
+ case 4:
|
|
|
+ result = _context5.sent;
|
|
|
+ case 5:
|
|
|
+ return _context5.abrupt("return", result.length ? result[0] : null);
|
|
|
+ case 6:
|
|
|
+ case "end":
|
|
|
+ return _context5.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, _callee5, this);
|
|
|
+ }));
|
|
|
+ function validateUpdate(_x15, _x16) {
|
|
|
+ return _validateUpdate.apply(this, arguments);
|
|
|
+ }
|
|
|
+ return validateUpdate;
|
|
|
+ }()
|
|
|
+ }, {
|
|
|
+ key: "invokeValidate",
|
|
|
+ value: function () {
|
|
|
+ var _invokeValidate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(data, all, allData) {
|
|
|
+ var result, schema, key, value, errorMessage;
|
|
|
+ return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
|
+ while (1) {
|
|
|
+ switch (_context6.prev = _context6.next) {
|
|
|
+ case 0:
|
|
|
+ result = [];
|
|
|
+ schema = this._schema;
|
|
|
+ _context6.t0 = _regenerator.default.keys(schema);
|
|
|
+ case 3:
|
|
|
+ if ((_context6.t1 = _context6.t0()).done) {
|
|
|
+ _context6.next = 15;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ key = _context6.t1.value;
|
|
|
+ value = schema[key];
|
|
|
+ _context6.next = 8;
|
|
|
+ return this.validateRule(key, value, data[key], data, allData);
|
|
|
+ case 8:
|
|
|
+ errorMessage = _context6.sent;
|
|
|
+ if (!(errorMessage != null)) {
|
|
|
+ _context6.next = 13;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ result.push({
|
|
|
+ key: key,
|
|
|
+ errorMessage: errorMessage
|
|
|
+ });
|
|
|
+ if (all) {
|
|
|
+ _context6.next = 13;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return _context6.abrupt("break", 15);
|
|
|
+ case 13:
|
|
|
+ _context6.next = 3;
|
|
|
+ break;
|
|
|
+ case 15:
|
|
|
+ return _context6.abrupt("return", result);
|
|
|
+ case 16:
|
|
|
+ case "end":
|
|
|
+ return _context6.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, _callee6, this);
|
|
|
+ }));
|
|
|
+ function invokeValidate(_x17, _x18, _x19) {
|
|
|
+ return _invokeValidate.apply(this, arguments);
|
|
|
+ }
|
|
|
+ return invokeValidate;
|
|
|
+ }()
|
|
|
+ }, {
|
|
|
+ key: "invokeValidateUpdate",
|
|
|
+ value: function () {
|
|
|
+ var _invokeValidateUpdate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(data, all, allData) {
|
|
|
+ var result, key, errorMessage;
|
|
|
+ return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
|
+ while (1) {
|
|
|
+ switch (_context7.prev = _context7.next) {
|
|
|
+ case 0:
|
|
|
+ result = [];
|
|
|
+ _context7.t0 = _regenerator.default.keys(data);
|
|
|
+ case 2:
|
|
|
+ if ((_context7.t1 = _context7.t0()).done) {
|
|
|
+ _context7.next = 13;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ key = _context7.t1.value;
|
|
|
+ _context7.next = 6;
|
|
|
+ return this.validateRule(key, this._schema[key], data[key], data, allData);
|
|
|
+ case 6:
|
|
|
+ errorMessage = _context7.sent;
|
|
|
+ if (!(errorMessage != null)) {
|
|
|
+ _context7.next = 11;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ result.push({
|
|
|
+ key: key,
|
|
|
+ errorMessage: errorMessage
|
|
|
+ });
|
|
|
+ if (all) {
|
|
|
+ _context7.next = 11;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return _context7.abrupt("break", 13);
|
|
|
+ case 11:
|
|
|
+ _context7.next = 2;
|
|
|
+ break;
|
|
|
+ case 13:
|
|
|
+ return _context7.abrupt("return", result);
|
|
|
+ case 14:
|
|
|
+ case "end":
|
|
|
+ return _context7.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, _callee7, this);
|
|
|
+ }));
|
|
|
+ function invokeValidateUpdate(_x20, _x21, _x22) {
|
|
|
+ return _invokeValidateUpdate.apply(this, arguments);
|
|
|
+ }
|
|
|
+ return invokeValidateUpdate;
|
|
|
+ }()
|
|
|
+ }, {
|
|
|
+ key: "_checkFieldInSchema",
|
|
|
+ value: function _checkFieldInSchema(data) {
|
|
|
+ var keys = Object.keys(data);
|
|
|
+ var keys2 = Object.keys(this._schema);
|
|
|
+ if (new Set(keys.concat(keys2)).size === keys2.length) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ var noExistFields = keys.filter(function (key) {
|
|
|
+ return keys2.indexOf(key) < 0;
|
|
|
+ });
|
|
|
+ var errorMessage = formatMessage({
|
|
|
+ field: JSON.stringify(noExistFields)
|
|
|
+ }, SchemaValidator.message.TAG + SchemaValidator.message['defaultInvalid']);
|
|
|
+ return [{
|
|
|
+ key: 'invalid',
|
|
|
+ errorMessage: errorMessage
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+ return SchemaValidator;
|
|
|
+}(RuleValidator);
|
|
|
+function Message() {
|
|
|
+ return {
|
|
|
+ TAG: "",
|
|
|
+ default: '验证错误',
|
|
|
+ defaultInvalid: '提交的字段{field}在数据库中并不存在',
|
|
|
+ validateFunction: '验证无效',
|
|
|
+ required: '{label}必填',
|
|
|
+ 'enum': '{label}超出范围',
|
|
|
+ timestamp: '{label}格式无效',
|
|
|
+ whitespace: '{label}不能为空',
|
|
|
+ typeError: '{label}类型无效',
|
|
|
+ date: {
|
|
|
+ format: '{label}日期{value}格式无效',
|
|
|
+ parse: '{label}日期无法解析,{value}无效',
|
|
|
+ invalid: '{label}日期{value}无效'
|
|
|
+ },
|
|
|
+ length: {
|
|
|
+ minLength: '{label}长度不能少于{minLength}',
|
|
|
+ maxLength: '{label}长度不能超过{maxLength}',
|
|
|
+ range: '{label}必须介于{minLength}和{maxLength}之间'
|
|
|
+ },
|
|
|
+ number: {
|
|
|
+ minimum: '{label}不能小于{minimum}',
|
|
|
+ maximum: '{label}不能大于{maximum}',
|
|
|
+ exclusiveMinimum: '{label}不能小于等于{minimum}',
|
|
|
+ exclusiveMaximum: '{label}不能大于等于{maximum}',
|
|
|
+ range: '{label}必须介于{minimum}and{maximum}之间'
|
|
|
+ },
|
|
|
+ pattern: {
|
|
|
+ mismatch: '{label}格式不匹配'
|
|
|
+ }
|
|
|
+ };
|
|
|
+}
|
|
|
+SchemaValidator.message = new Message();
|
|
|
+var _default = SchemaValidator;
|
|
|
+exports.default = _default;
|
|
|
+
|
|
|
+/***/ }),
|
|
|
+/* 432 */
|
|
|
+/*!*********************************************************!*\
|
|
|
+ !*** ./node_modules/@babel/runtime/helpers/inherits.js ***!
|
|
|
+ \*********************************************************/
|
|
|
+/*! no static exports found */
|
|
|
+/***/ (function(module, exports, __webpack_require__) {
|
|
|
+
|
|
|
+var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf.js */ 16);
|
|
|
+function _inherits(subClass, superClass) {
|
|
|
+ if (typeof superClass !== "function" && superClass !== null) {
|
|
|
+ throw new TypeError("Super expression must either be null or a function");
|
|
|
+ }
|
|
|
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
|
+ constructor: {
|
|
|
+ value: subClass,
|
|
|
+ writable: true,
|
|
|
+ configurable: true
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Object.defineProperty(subClass, "prototype", {
|
|
|
+ writable: false
|
|
|
+ });
|
|
|
+ if (superClass) setPrototypeOf(subClass, superClass);
|
|
|
+}
|
|
|
+module.exports = _inherits, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
|
+
|
|
|
+/***/ }),
|
|
|
+/* 433 */
|
|
|
+/*!**************************************************************************!*\
|
|
|
+ !*** ./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js ***!
|
|
|
+ \**************************************************************************/
|
|
|
+/*! no static exports found */
|
|
|
+/***/ (function(module, exports, __webpack_require__) {
|
|
|
+
|
|
|
+var _typeof = __webpack_require__(/*! ./typeof.js */ 13)["default"];
|
|
|
+var assertThisInitialized = __webpack_require__(/*! ./assertThisInitialized.js */ 434);
|
|
|
+function _possibleConstructorReturn(self, call) {
|
|
|
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
|
+ return call;
|
|
|
+ } else if (call !== void 0) {
|
|
|
+ throw new TypeError("Derived constructors may only return object or undefined");
|
|
|
+ }
|
|
|
+ return assertThisInitialized(self);
|
|
|
+}
|
|
|
+module.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
|
+
|
|
|
+/***/ }),
|
|
|
+/* 434 */
|
|
|
+/*!**********************************************************************!*\
|
|
|
+ !*** ./node_modules/@babel/runtime/helpers/assertThisInitialized.js ***!
|
|
|
+ \**********************************************************************/
|
|
|
+/*! no static exports found */
|
|
|
+/***/ (function(module, exports) {
|
|
|
+
|
|
|
+function _assertThisInitialized(self) {
|
|
|
+ if (self === void 0) {
|
|
|
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+module.exports = _assertThisInitialized, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
|
+
|
|
|
+/***/ }),
|
|
|
+/* 435 */
|
|
|
+/*!***************************************************************!*\
|
|
|
+ !*** ./node_modules/@babel/runtime/helpers/getPrototypeOf.js ***!
|
|
|
+ \***************************************************************/
|
|
|
+/*! no static exports found */
|
|
|
+/***/ (function(module, exports) {
|
|
|
+
|
|
|
+function _getPrototypeOf(o) {
|
|
|
+ module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
|
+ return o.__proto__ || Object.getPrototypeOf(o);
|
|
|
+ }, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
|
+ return _getPrototypeOf(o);
|
|
|
+}
|
|
|
+module.exports = _getPrototypeOf, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
|
+
|
|
|
+/***/ }),
|
|
|
+/* 436 */
|
|
|
+/*!********************************************************************************************!*\
|
|
|
+ !*** D:/demo/businessCard/xiaochengxu/uni_modules/uni-forms/components/uni-forms/utils.js ***!
|
|
|
+ \********************************************************************************************/
|
|
|
+/*! no static exports found */
|
|
|
+/***/ (function(module, exports, __webpack_require__) {
|
|
|
+
|
|
|
+"use strict";
|
|
|
+
|
|
|
+
|
|
|
+var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4);
|
|
|
+Object.defineProperty(exports, "__esModule", {
|
|
|
+ value: true
|
|
|
+});
|
|
|
+exports.typeFilter = exports.type = exports.setDataValue = exports.realName = exports.rawData = exports.objSet = exports.objGet = exports.name2arr = exports.isRequiredField = exports.isRealName = exports.isNumber = exports.isEqual = exports.isBoolean = exports.getValue = exports.getDataValueType = exports.getDataValue = exports.deepCopy = void 0;
|
|
|
+var _typeof2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/typeof */ 13));
|
|
|
+/**
|
|
|
+ * 简单处理对象拷贝
|
|
|
+ * @param {Obejct} 被拷贝对象
|
|
|
+ * @@return {Object} 拷贝对象
|
|
|
+ */
|
|
|
+var deepCopy = function deepCopy(val) {
|
|
|
+ return JSON.parse(JSON.stringify(val));
|
|
|
+};
|
|
|
+/**
|
|
|
+ * 过滤数字类型
|
|
|
+ * @param {String} format 数字类型
|
|
|
+ * @@return {Boolean} 返回是否为数字类型
|
|
|
+ */
|
|
|
+exports.deepCopy = deepCopy;
|
|
|
+var typeFilter = function typeFilter(format) {
|
|
|
+ return format === 'int' || format === 'double' || format === 'number' || format === 'timestamp';
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 把 value 转换成指定的类型,用于处理初始值,原因是初始值需要入库不能为 undefined
|
|
|
+ * @param {String} key 字段名
|
|
|
+ * @param {any} value 字段值
|
|
|
+ * @param {Object} rules 表单校验规则
|
|
|
+ */
|
|
|
+exports.typeFilter = typeFilter;
|
|
|
+var getValue = function getValue(key, value, rules) {
|
|
|
+ var isRuleNumType = rules.find(function (val) {
|
|
|
+ return val.format && typeFilter(val.format);
|
|
|
+ });
|
|
|
+ var isRuleBoolType = rules.find(function (val) {
|
|
|
+ return val.format && val.format === 'boolean' || val.format === 'bool';
|
|
|
+ });
|
|
|
+ // 输入类型为 number
|
|
|
+ if (!!isRuleNumType) {
|
|
|
+ if (!value && value !== 0) {
|
|
|
+ value = null;
|
|
|
+ } else {
|
|
|
+ value = isNumber(Number(value)) ? Number(value) : value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 输入类型为 boolean
|
|
|
+ if (!!isRuleBoolType) {
|
|
|
+ value = isBoolean(value) ? value : false;
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取表单数据
|
|
|
+ * @param {String|Array} name 真实名称,需要使用 realName 获取
|
|
|
+ * @param {Object} data 原始数据
|
|
|
+ * @param {any} value 需要设置的值
|
|
|
+ */
|
|
|
+exports.getValue = getValue;
|
|
|
+var setDataValue = function setDataValue(field, formdata, value) {
|
|
|
+ formdata[field] = value;
|
|
|
+ return value || '';
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取表单数据
|
|
|
+ * @param {String|Array} field 真实名称,需要使用 realName 获取
|
|
|
+ * @param {Object} data 原始数据
|
|
|
+ */
|
|
|
+exports.setDataValue = setDataValue;
|
|
|
+var getDataValue = function getDataValue(field, data) {
|
|
|
+ return objGet(data, field);
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取表单类型
|
|
|
+ * @param {String|Array} field 真实名称,需要使用 realName 获取
|
|
|
+ */
|
|
|
+exports.getDataValue = getDataValue;
|
|
|
+var getDataValueType = function getDataValueType(field, data) {
|
|
|
+ var value = getDataValue(field, data);
|
|
|
+ return {
|
|
|
+ type: type(value),
|
|
|
+ value: value
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取表单可用的真实name
|
|
|
+ * @param {String|Array} name 表单name
|
|
|
+ * @@return {String} 表单可用的真实name
|
|
|
+ */
|
|
|
+exports.getDataValueType = getDataValueType;
|
|
|
+var realName = function realName(name) {
|
|
|
+ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
|
+ var base_name = _basePath(name);
|
|
|
+ if ((0, _typeof2.default)(base_name) === 'object' && Array.isArray(base_name) && base_name.length > 1) {
|
|
|
+ var realname = base_name.reduce(function (a, b) {
|
|
|
+ return a += "#".concat(b);
|
|
|
+ }, '_formdata_');
|
|
|
+ return realname;
|
|
|
+ }
|
|
|
+ return base_name[0] || name;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 判断是否表单可用的真实name
|
|
|
+ * @param {String|Array} name 表单name
|
|
|
+ * @@return {String} 表单可用的真实name
|
|
|
+ */
|
|
|
+exports.realName = realName;
|
|
|
+var isRealName = function isRealName(name) {
|
|
|
+ var reg = /^_formdata_#*/;
|
|
|
+ return reg.test(name);
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取表单数据的原始格式
|
|
|
+ * @@return {Object|Array} object 需要解析的数据
|
|
|
+ */
|
|
|
+exports.isRealName = isRealName;
|
|
|
+var rawData = function rawData() {
|
|
|
+ var object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
|
+ var name = arguments.length > 1 ? arguments[1] : undefined;
|
|
|
+ var newData = JSON.parse(JSON.stringify(object));
|
|
|
+ var formData = {};
|
|
|
+ for (var i in newData) {
|
|
|
+ var path = name2arr(i);
|
|
|
+ objSet(formData, path, newData[i]);
|
|
|
+ }
|
|
|
+ return formData;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 真实name还原为 array
|
|
|
+ * @param {*} name
|
|
|
+ */
|
|
|
+exports.rawData = rawData;
|
|
|
+var name2arr = function name2arr(name) {
|
|
|
+ var field = name.replace('_formdata_#', '');
|
|
|
+ field = field.split('#').map(function (v) {
|
|
|
+ return isNumber(v) ? Number(v) : v;
|
|
|
+ });
|
|
|
+ return field;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 对象中设置值
|
|
|
+ * @param {Object|Array} object 源数据
|
|
|
+ * @param {String| Array} path 'a.b.c' 或 ['a',0,'b','c']
|
|
|
+ * @param {String} value 需要设置的值
|
|
|
+ */
|
|
|
+exports.name2arr = name2arr;
|
|
|
+var objSet = function objSet(object, path, value) {
|
|
|
+ if ((0, _typeof2.default)(object) !== 'object') return object;
|
|
|
+ _basePath(path).reduce(function (o, k, i, _) {
|
|
|
+ if (i === _.length - 1) {
|
|
|
+ // 若遍历结束直接赋值
|
|
|
+ o[k] = value;
|
|
|
+ return null;
|
|
|
+ } else if (k in o) {
|
|
|
+ // 若存在对应路径,则返回找到的对象,进行下一次遍历
|
|
|
+ return o[k];
|
|
|
+ } else {
|
|
|
+ // 若不存在对应路径,则创建对应对象,若下一路径是数字,新对象赋值为空数组,否则赋值为空对象
|
|
|
+ o[k] = /^[0-9]{1,}$/.test(_[i + 1]) ? [] : {};
|
|
|
+ return o[k];
|
|
|
+ }
|
|
|
+ }, object);
|
|
|
+ // 返回object
|
|
|
+ return object;
|
|
|
+};
|
|
|
+
|
|
|
+// 处理 path, path有三种形式:'a[0].b.c'、'a.0.b.c' 和 ['a','0','b','c'],需要统一处理成数组,便于后续使用
|
|
|
+exports.objSet = objSet;
|
|
|
+function _basePath(path) {
|
|
|
+ // 若是数组,则直接返回
|
|
|
+ if (Array.isArray(path)) return path;
|
|
|
+ // 若有 '[',']',则替换成将 '[' 替换成 '.',去掉 ']'
|
|
|
+ return path.replace(/\[/g, '.').replace(/\]/g, '').split('.');
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 从对象中获取值
|
|
|
+ * @param {Object|Array} object 源数据
|
|
|
+ * @param {String| Array} path 'a.b.c' 或 ['a',0,'b','c']
|
|
|
+ * @param {String} defaultVal 如果无法从调用链中获取值的默认值
|
|
|
+ */
|
|
|
+var objGet = function objGet(object, path) {
|
|
|
+ var defaultVal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'undefined';
|
|
|
+ // 先将path处理成统一格式
|
|
|
+ var newPath = _basePath(path);
|
|
|
+ // 递归处理,返回最后结果
|
|
|
+ var val = newPath.reduce(function (o, k) {
|
|
|
+ return (o || {})[k];
|
|
|
+ }, object);
|
|
|
+ return !val || val !== undefined ? val : defaultVal;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 是否为 number 类型
|
|
|
+ * @param {any} num 需要判断的值
|
|
|
+ * @return {Boolean} 是否为 number
|
|
|
+ */
|
|
|
+exports.objGet = objGet;
|
|
|
+var isNumber = function isNumber(num) {
|
|
|
+ return !isNaN(Number(num));
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 是否为 boolean 类型
|
|
|
+ * @param {any} bool 需要判断的值
|
|
|
+ * @return {Boolean} 是否为 boolean
|
|
|
+ */
|
|
|
+exports.isNumber = isNumber;
|
|
|
+var isBoolean = function isBoolean(bool) {
|
|
|
+ return typeof bool === 'boolean';
|
|
|
+};
|
|
|
+/**
|
|
|
+ * 是否有必填字段
|
|
|
+ * @param {Object} rules 规则
|
|
|
+ * @return {Boolean} 是否有必填字段
|
|
|
+ */
|
|
|
+exports.isBoolean = isBoolean;
|
|
|
+var isRequiredField = function isRequiredField(rules) {
|
|
|
+ var isNoField = false;
|
|
|
+ for (var i = 0; i < rules.length; i++) {
|
|
|
+ var ruleData = rules[i];
|
|
|
+ if (ruleData.required) {
|
|
|
+ isNoField = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return isNoField;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取数据类型
|
|
|
+ * @param {Any} obj 需要获取数据类型的值
|
|
|
+ */
|
|
|
+exports.isRequiredField = isRequiredField;
|
|
|
+var type = function type(obj) {
|
|
|
+ var class2type = {};
|
|
|
+
|
|
|
+ // 生成class2type映射
|
|
|
+ "Boolean Number String Function Array Date RegExp Object Error".split(" ").map(function (item, index) {
|
|
|
+ class2type["[object " + item + "]"] = item.toLowerCase();
|
|
|
+ });
|
|
|
+ if (obj == null) {
|
|
|
+ return obj + "";
|
|
|
+ }
|
|
|
+ return (0, _typeof2.default)(obj) === "object" || typeof obj === "function" ? class2type[Object.prototype.toString.call(obj)] || "object" : (0, _typeof2.default)(obj);
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 判断两个值是否相等
|
|
|
+ * @param {any} a 值
|
|
|
+ * @param {any} b 值
|
|
|
+ * @return {Boolean} 是否相等
|
|
|
+ */
|
|
|
+exports.type = type;
|
|
|
+var isEqual = function isEqual(a, b) {
|
|
|
+ //如果a和b本来就全等
|
|
|
+ if (a === b) {
|
|
|
+ //判断是否为0和-0
|
|
|
+ return a !== 0 || 1 / a === 1 / b;
|
|
|
+ }
|
|
|
+ //判断是否为null和undefined
|
|
|
+ if (a == null || b == null) {
|
|
|
+ return a === b;
|
|
|
+ }
|
|
|
+ //接下来判断a和b的数据类型
|
|
|
+ var classNameA = toString.call(a),
|
|
|
+ classNameB = toString.call(b);
|
|
|
+ //如果数据类型不相等,则返回false
|
|
|
+ if (classNameA !== classNameB) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //如果数据类型相等,再根据不同数据类型分别判断
|
|
|
+ switch (classNameA) {
|
|
|
+ case '[object RegExp]':
|
|
|
+ case '[object String]':
|
|
|
+ //进行字符串转换比较
|
|
|
+ return '' + a === '' + b;
|
|
|
+ case '[object Number]':
|
|
|
+ //进行数字转换比较,判断是否为NaN
|
|
|
+ if (+a !== +a) {
|
|
|
+ return +b !== +b;
|
|
|
+ }
|
|
|
+ //判断是否为0或-0
|
|
|
+ return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
|
|
+ case '[object Date]':
|
|
|
+ case '[object Boolean]':
|
|
|
+ return +a === +b;
|
|
|
+ }
|
|
|
+ //如果是对象类型
|
|
|
+ if (classNameA == '[object Object]') {
|
|
|
+ //获取a和b的属性长度
|
|
|
+ var propsA = Object.getOwnPropertyNames(a),
|
|
|
+ propsB = Object.getOwnPropertyNames(b);
|
|
|
+ if (propsA.length != propsB.length) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (var i = 0; i < propsA.length; i++) {
|
|
|
+ var propName = propsA[i];
|
|
|
+ //如果对应属性对应值不相等,则返回false
|
|
|
+ if (a[propName] !== b[propName]) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ //如果是数组类型
|
|
|
+ if (classNameA == '[object Array]') {
|
|
|
+ if (a.toString() == b.toString()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+};
|
|
|
+exports.isEqual = isEqual;
|
|
|
+
|
|
|
/***/ })
|
|
|
]]);
|
|
|
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/vendor.js.map
|