@bchr/bchr-front-lib 0.6.6 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -886,43 +886,60 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
|
|
|
886
886
|
}
|
|
887
887
|
}, {
|
|
888
888
|
key: "formatValidator",
|
|
889
|
-
value: function formatValidator(rule, value) {
|
|
889
|
+
value: function formatValidator(validationContext, rule, value) {
|
|
890
890
|
var pattern = rule.pattern;
|
|
891
|
-
|
|
891
|
+
var formatErrorMessage = rule.message || "格式不正确";
|
|
892
|
+
if (this.isBlankFormatValidationPattern(pattern)) {
|
|
892
893
|
return Promise.resolve();
|
|
893
894
|
}
|
|
894
|
-
|
|
895
|
+
var normalizedValue = this.normalizeFormatValidationValue(value);
|
|
896
|
+
if (normalizedValue.trim().length === 0) {
|
|
895
897
|
return Promise.resolve();
|
|
896
898
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
return Promise.resolve();
|
|
900
|
-
}
|
|
901
|
-
if ((rule === null || rule === void 0 ? void 0 : rule.ui_render_type) === _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
|
|
902
|
-
if (rule.fieldDisabled) {
|
|
899
|
+
if ((validationContext === null || validationContext === void 0 ? void 0 : validationContext.ui_render_type) === _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
|
|
900
|
+
if (validationContext.fieldDisabled) {
|
|
903
901
|
return Promise.resolve();
|
|
904
902
|
}
|
|
905
|
-
var normalizedInitialValue = this.
|
|
903
|
+
var normalizedInitialValue = this.normalizeFormatValidationValue(validationContext.initialValue);
|
|
906
904
|
if (normalizedValue === normalizedInitialValue) {
|
|
907
|
-
return this.validatePasswordDecryptFormat(normalizedValue, pattern,
|
|
905
|
+
return this.validatePasswordDecryptFormat(normalizedValue, pattern, validationContext)["catch"](function (error) {
|
|
908
906
|
console.error("password decrypt format validation failed>>>>>>>>", error);
|
|
909
|
-
return Promise.reject(
|
|
907
|
+
return Promise.reject(formatErrorMessage);
|
|
910
908
|
}).then(function (isValid) {
|
|
911
|
-
return isValid ? Promise.resolve() : Promise.reject(
|
|
909
|
+
return isValid ? Promise.resolve() : Promise.reject(formatErrorMessage);
|
|
912
910
|
});
|
|
913
911
|
}
|
|
914
912
|
}
|
|
915
|
-
var regExp
|
|
916
|
-
|
|
913
|
+
var regExp;
|
|
914
|
+
try {
|
|
915
|
+
regExp = this.createValidationRegExp(pattern);
|
|
916
|
+
} catch (error) {
|
|
917
|
+
console.error("form item format pattern is invalid>>>>>>>>", error);
|
|
918
|
+
return Promise.reject(formatErrorMessage);
|
|
919
|
+
}
|
|
920
|
+
return regExp.test(normalizedValue) ? Promise.resolve() : Promise.reject(formatErrorMessage);
|
|
917
921
|
}
|
|
918
922
|
}, {
|
|
919
|
-
key: "
|
|
920
|
-
value: function
|
|
923
|
+
key: "normalizeFormatValidationValue",
|
|
924
|
+
value: function normalizeFormatValidationValue(value) {
|
|
921
925
|
if (value === null || value === undefined) {
|
|
922
926
|
return "";
|
|
923
927
|
}
|
|
924
928
|
return String(value);
|
|
925
929
|
}
|
|
930
|
+
}, {
|
|
931
|
+
key: "isBlankFormatValidationPattern",
|
|
932
|
+
value: function isBlankFormatValidationPattern(pattern) {
|
|
933
|
+
if (pattern instanceof RegExp) {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
return typeof pattern !== "string" || pattern.trim().length === 0;
|
|
937
|
+
}
|
|
938
|
+
}, {
|
|
939
|
+
key: "createValidationRegExp",
|
|
940
|
+
value: function createValidationRegExp(pattern) {
|
|
941
|
+
return pattern instanceof RegExp ? new RegExp(pattern.source, pattern.flags) : new RegExp(pattern);
|
|
942
|
+
}
|
|
926
943
|
}, {
|
|
927
944
|
key: "requestPasswordDecryptValue",
|
|
928
945
|
value: function requestPasswordDecryptValue(value, rule) {
|
|
@@ -961,7 +978,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
|
|
|
961
978
|
}
|
|
962
979
|
throw new Error("password decrypt validation result is not a string");
|
|
963
980
|
case 2:
|
|
964
|
-
return _context.a(2,
|
|
981
|
+
return _context.a(2, _this3.createValidationRegExp(pattern).test(decryptedValue));
|
|
965
982
|
}
|
|
966
983
|
}, _callee);
|
|
967
984
|
}))();
|
package/package.json
CHANGED
|
@@ -831,44 +831,47 @@ class FormForModify extends React.Component{
|
|
|
831
831
|
}
|
|
832
832
|
}
|
|
833
833
|
|
|
834
|
-
formatValidator(rule, value) {
|
|
834
|
+
formatValidator(validationContext, rule, value) {
|
|
835
835
|
let {pattern} = rule;
|
|
836
|
+
const formatErrorMessage = rule.message || "格式不正确";
|
|
836
837
|
|
|
837
|
-
if (
|
|
838
|
+
if (this.isBlankFormatValidationPattern(pattern)) {
|
|
838
839
|
return Promise.resolve();
|
|
839
840
|
}
|
|
840
841
|
|
|
841
|
-
|
|
842
|
+
const normalizedValue = this.normalizeFormatValidationValue(value);
|
|
843
|
+
if (normalizedValue.trim().length === 0) {
|
|
842
844
|
return Promise.resolve();
|
|
843
845
|
}
|
|
844
846
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
return Promise.resolve();
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
if (rule?.ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
|
|
851
|
-
if (rule.fieldDisabled) {
|
|
847
|
+
if (validationContext?.ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
|
|
848
|
+
if (validationContext.fieldDisabled) {
|
|
852
849
|
return Promise.resolve();
|
|
853
850
|
}
|
|
854
851
|
|
|
855
|
-
const normalizedInitialValue = this.
|
|
852
|
+
const normalizedInitialValue = this.normalizeFormatValidationValue(validationContext.initialValue);
|
|
856
853
|
if (normalizedValue === normalizedInitialValue) {
|
|
857
|
-
return this.validatePasswordDecryptFormat(normalizedValue, pattern,
|
|
854
|
+
return this.validatePasswordDecryptFormat(normalizedValue, pattern, validationContext)
|
|
858
855
|
.catch((error) => {
|
|
859
856
|
console.error("password decrypt format validation failed>>>>>>>>", error);
|
|
860
|
-
return Promise.reject(
|
|
857
|
+
return Promise.reject(formatErrorMessage);
|
|
861
858
|
})
|
|
862
|
-
.then((isValid) => isValid ? Promise.resolve() : Promise.reject(
|
|
859
|
+
.then((isValid) => isValid ? Promise.resolve() : Promise.reject(formatErrorMessage));
|
|
863
860
|
}
|
|
864
861
|
}
|
|
865
862
|
|
|
866
|
-
let regExp
|
|
863
|
+
let regExp;
|
|
864
|
+
try {
|
|
865
|
+
regExp = this.createValidationRegExp(pattern);
|
|
866
|
+
} catch (error) {
|
|
867
|
+
console.error("form item format pattern is invalid>>>>>>>>", error);
|
|
868
|
+
return Promise.reject(formatErrorMessage);
|
|
869
|
+
}
|
|
867
870
|
|
|
868
|
-
return regExp.test(
|
|
871
|
+
return regExp.test(normalizedValue) ? Promise.resolve() : Promise.reject(formatErrorMessage);
|
|
869
872
|
}
|
|
870
873
|
|
|
871
|
-
|
|
874
|
+
normalizeFormatValidationValue(value) {
|
|
872
875
|
if (value === null || value === undefined) {
|
|
873
876
|
return "";
|
|
874
877
|
}
|
|
@@ -876,6 +879,20 @@ class FormForModify extends React.Component{
|
|
|
876
879
|
return String(value);
|
|
877
880
|
}
|
|
878
881
|
|
|
882
|
+
isBlankFormatValidationPattern(pattern) {
|
|
883
|
+
if (pattern instanceof RegExp) {
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
return typeof pattern !== "string" || pattern.trim().length === 0;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
createValidationRegExp(pattern) {
|
|
891
|
+
return pattern instanceof RegExp
|
|
892
|
+
? new RegExp(pattern.source, pattern.flags)
|
|
893
|
+
: new RegExp(pattern);
|
|
894
|
+
}
|
|
895
|
+
|
|
879
896
|
requestPasswordDecryptValue(value, rule) {
|
|
880
897
|
const {requestUrl, serviceConfig} = rule;
|
|
881
898
|
|
|
@@ -903,7 +920,7 @@ class FormForModify extends React.Component{
|
|
|
903
920
|
throw new Error("password decrypt validation result is not a string");
|
|
904
921
|
}
|
|
905
922
|
|
|
906
|
-
return
|
|
923
|
+
return this.createValidationRegExp(pattern).test(decryptedValue);
|
|
907
924
|
})();
|
|
908
925
|
|
|
909
926
|
validationPromise.then((isValid) => {
|