UNPKG

maycur-business

Version:

maycur business react components of web

133 lines (104 loc) 3.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _lodash = _interopRequireDefault(require("lodash")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function commonComparator(sourceList, fieldValue, isPositive) { var _fieldValue; if (_lodash["default"].isObject(fieldValue)) { _fieldValue = fieldValue.code; } else { _fieldValue = fieldValue; } var bool = _lodash["default"].indexOf(sourceList, _fieldValue) !== -1; return isPositive ? bool : !bool; } /** * 部门选择控件里面返回的fieldValue的数据结构如下,并且唯一标识是code * [{code}] */ function departmentComparator(sourceList, fieldValue, isPositive) { return _lodash["default"].every(Array.isArray(fieldValue) ? fieldValue : [fieldValue], function (item) { var bool = _lodash["default"].intersection(_lodash["default"].split(sourceList, ','), _lodash["default"].split(item.heirCode, '.')).length > 0; return isPositive ? bool : !bool; }); } /** * 人员选择控件里面返回的fieldValue的数据结构如下,并且唯一标识是userCode * [{userCode}] */ function staffComparator(sourceList, fieldValue, isPositive) { return _lodash["default"].every(Array.isArray(fieldValue) ? fieldValue : [fieldValue], function (item) { var bool = _lodash["default"].indexOf(sourceList, item && item.userCode) !== -1; return isPositive ? bool : !bool; }); } /** * 数据互联返回的fieldValue数据结构如下,唯一标识为id * {value: [{id}]} */ function assositionComparator(sourceList, fieldValue, isPositive) { if (_lodash["default"].isEmpty(fieldValue && fieldValue.value)) { return false; } else { return _lodash["default"].every(fieldValue && fieldValue.value, function (item) { var bool = _lodash["default"].indexOf(sourceList, item && item.id) !== -1; return isPositive ? bool : !bool; }); } } /** * 表单控件里面返回的fieldValue的数据结构如下 * {details: [{level}]} */ function validateComparator(sourceList, fieldValue, isPositive) { return _lodash["default"].every(fieldValue && fieldValue.details, function (item) { //return item.level === sourceList[0]; var bool = item.level === sourceList[0]; return isPositive ? bool : !bool; }); } function comparaRules(condition, data, isPositive) { var field = condition.field, identifier = condition.identifier; var fieldValue = data[identifier]; var sourceList = _lodash["default"].split(condition.valueCodes, ','); //当值为空的时候,属于条件返回false,不属于返回true if (_lodash["default"].isEmpty(fieldValue)) { return !isPositive; } var result; switch (field) { case 'WEB_CHECK_COVER_DEPARTMENT_CODE': result = departmentComparator(sourceList, fieldValue, isPositive); break; case 'WEB_CHECK_COVER_USER_CODE': result = staffComparator(sourceList, fieldValue, isPositive); break; case 'WEB_CHECK_STAFF_CODE': result = staffComparator(sourceList, fieldValue, isPositive); break; case 'WEB_CHECK_DATA_ASSOCIATION': result = assositionComparator(sourceList, fieldValue, isPositive); break; case 'WEB_CHECK_FORM_VALIDATION': result = validateComparator(sourceList, fieldValue, isPositive); break; default: result = commonComparator(sourceList, fieldValue, isPositive); break; } return result; } /** * * @param {*} condition 条件 * @param {*} data 表单数据对象 * @param {*} isPositive 是否包含 */ function IN(condition, data, isPositive) { return comparaRules(condition, data, isPositive); } var _default = IN; exports["default"] = _default;