@bchr/bchr-front-lib 0.6.7 → 0.6.8

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.
@@ -8,6 +8,7 @@ exports["default"] = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _antd = require("antd");
10
10
  var _HttpService = _interopRequireDefault(require("../../../services/HttpService"));
11
+ var _utils = require("../../utils");
11
12
  var _excluded = ["ui_render_type", "initValue", "value", "onChange", "requestUrl", "appconfig", "appConfig", "maskLength", "placeholder", "maxLength", "allowClear", "onKeyDown", "onPaste"];
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
13
14
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
@@ -329,7 +330,7 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
329
330
  })
330
331
  }));
331
332
  } else if (ui_render_type === "browse") {
332
- return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("span", null, toggleVal, /*#__PURE__*/_react["default"].createElement("span", {
333
+ return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("span", null, toggleVal, _utils.Values.isNotBlankString(incomingValue) && /*#__PURE__*/_react["default"].createElement("span", {
333
334
  className: "iconfont ".concat(toggle ? "icon-bchr-show" : "icon-bchr-hide"),
334
335
  style: {
335
336
  cursor: "pointer",
@@ -886,60 +886,43 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
886
886
  }
887
887
  }, {
888
888
  key: "formatValidator",
889
- value: function formatValidator(validationContext, rule, value) {
889
+ value: function formatValidator(rule, value) {
890
890
  var pattern = rule.pattern;
891
- var formatErrorMessage = rule.message || "格式不正确";
892
- if (this.isBlankFormatValidationPattern(pattern)) {
891
+ if (!pattern || pattern.trim().length === 0) {
893
892
  return Promise.resolve();
894
893
  }
895
- var normalizedValue = this.normalizeFormatValidationValue(value);
896
- if (normalizedValue.trim().length === 0) {
894
+ if (!value || value.trim().length === 0) {
897
895
  return Promise.resolve();
898
896
  }
899
- if ((validationContext === null || validationContext === void 0 ? void 0 : validationContext.ui_render_type) === _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
900
- if (validationContext.fieldDisabled) {
897
+ var normalizedValue = this.normalizePasswordDecryptValidationValue(value);
898
+ if (normalizedValue.length === 0) {
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) {
901
903
  return Promise.resolve();
902
904
  }
903
- var normalizedInitialValue = this.normalizeFormatValidationValue(validationContext.initialValue);
905
+ var normalizedInitialValue = this.normalizePasswordDecryptValidationValue(rule.initialValue);
904
906
  if (normalizedValue === normalizedInitialValue) {
905
- return this.validatePasswordDecryptFormat(normalizedValue, pattern, validationContext)["catch"](function (error) {
907
+ return this.validatePasswordDecryptFormat(normalizedValue, pattern, rule)["catch"](function (error) {
906
908
  console.error("password decrypt format validation failed>>>>>>>>", error);
907
- return Promise.reject(formatErrorMessage);
909
+ return Promise.reject("格式校验失败");
908
910
  }).then(function (isValid) {
909
- return isValid ? Promise.resolve() : Promise.reject(formatErrorMessage);
911
+ return isValid ? Promise.resolve() : Promise.reject("格式错误");
910
912
  });
911
913
  }
912
914
  }
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);
915
+ var regExp = new RegExp(pattern);
916
+ return regExp.test(value) ? Promise.resolve() : Promise.reject("格式错误");
921
917
  }
922
918
  }, {
923
- key: "normalizeFormatValidationValue",
924
- value: function normalizeFormatValidationValue(value) {
919
+ key: "normalizePasswordDecryptValidationValue",
920
+ value: function normalizePasswordDecryptValidationValue(value) {
925
921
  if (value === null || value === undefined) {
926
922
  return "";
927
923
  }
928
924
  return String(value);
929
925
  }
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
- }
943
926
  }, {
944
927
  key: "requestPasswordDecryptValue",
945
928
  value: function requestPasswordDecryptValue(value, rule) {
@@ -978,7 +961,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
978
961
  }
979
962
  throw new Error("password decrypt validation result is not a string");
980
963
  case 2:
981
- return _context.a(2, _this3.createValidationRegExp(pattern).test(decryptedValue));
964
+ return _context.a(2, new RegExp(pattern).test(decryptedValue));
982
965
  }
983
966
  }, _callee);
984
967
  }))();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bchr/bchr-front-lib",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "description": "bchr front lib",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,6 +1,7 @@
1
1
  import React, {Fragment, useEffect, useRef, useState} from "react";
2
2
  import {Input, message} from "antd";
3
3
  import HttpService from "../../../services/HttpService";
4
+ import {Values} from "../../utils";
4
5
 
5
6
  const MASK_LENGTH = 8;
6
7
 
@@ -254,7 +255,12 @@ const InputPasswordDecrypt = (props) => {
254
255
  />;
255
256
  } else if (ui_render_type === "browse") {
256
257
  return <Fragment>
257
- <span>{toggleVal}<span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`} style={{cursor: "pointer", margin: "0 5px", color: "#337DB7", fontWeight: "bolder"}} onClick={onToggleFull}/></span>
258
+ <span>
259
+ {toggleVal}
260
+ {Values.isNotBlankString(incomingValue) && (
261
+ <span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`} style={{cursor: "pointer", margin: "0 5px", color: "#337DB7", fontWeight: "bolder"}} onClick={onToggleFull}/>
262
+ )}
263
+ </span>
258
264
  </Fragment>;
259
265
  }
260
266
  };
@@ -831,47 +831,44 @@ class FormForModify extends React.Component{
831
831
  }
832
832
  }
833
833
 
834
- formatValidator(validationContext, rule, value) {
834
+ formatValidator(rule, value) {
835
835
  let {pattern} = rule;
836
- const formatErrorMessage = rule.message || "格式不正确";
837
836
 
838
- if (this.isBlankFormatValidationPattern(pattern)) {
837
+ if (!pattern || pattern.trim().length === 0) {
839
838
  return Promise.resolve();
840
839
  }
841
840
 
842
- const normalizedValue = this.normalizeFormatValidationValue(value);
843
- if (normalizedValue.trim().length === 0) {
841
+ if (!value || value.trim().length === 0) {
844
842
  return Promise.resolve();
845
843
  }
846
844
 
847
- if (validationContext?.ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
848
- if (validationContext.fieldDisabled) {
845
+ const normalizedValue = this.normalizePasswordDecryptValidationValue(value);
846
+ if (normalizedValue.length === 0) {
847
+ return Promise.resolve();
848
+ }
849
+
850
+ if (rule?.ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
851
+ if (rule.fieldDisabled) {
849
852
  return Promise.resolve();
850
853
  }
851
854
 
852
- const normalizedInitialValue = this.normalizeFormatValidationValue(validationContext.initialValue);
855
+ const normalizedInitialValue = this.normalizePasswordDecryptValidationValue(rule.initialValue);
853
856
  if (normalizedValue === normalizedInitialValue) {
854
- return this.validatePasswordDecryptFormat(normalizedValue, pattern, validationContext)
857
+ return this.validatePasswordDecryptFormat(normalizedValue, pattern, rule)
855
858
  .catch((error) => {
856
859
  console.error("password decrypt format validation failed>>>>>>>>", error);
857
- return Promise.reject(formatErrorMessage);
860
+ return Promise.reject("格式校验失败");
858
861
  })
859
- .then((isValid) => isValid ? Promise.resolve() : Promise.reject(formatErrorMessage));
862
+ .then((isValid) => isValid ? Promise.resolve() : Promise.reject("格式错误"));
860
863
  }
861
864
  }
862
865
 
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
- }
866
+ let regExp = new RegExp(pattern);
870
867
 
871
- return regExp.test(normalizedValue) ? Promise.resolve() : Promise.reject(formatErrorMessage);
868
+ return regExp.test(value) ? Promise.resolve() : Promise.reject("格式错误");
872
869
  }
873
870
 
874
- normalizeFormatValidationValue(value) {
871
+ normalizePasswordDecryptValidationValue(value) {
875
872
  if (value === null || value === undefined) {
876
873
  return "";
877
874
  }
@@ -879,20 +876,6 @@ class FormForModify extends React.Component{
879
876
  return String(value);
880
877
  }
881
878
 
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
-
896
879
  requestPasswordDecryptValue(value, rule) {
897
880
  const {requestUrl, serviceConfig} = rule;
898
881
 
@@ -920,7 +903,7 @@ class FormForModify extends React.Component{
920
903
  throw new Error("password decrypt validation result is not a string");
921
904
  }
922
905
 
923
- return this.createValidationRegExp(pattern).test(decryptedValue);
906
+ return new RegExp(pattern).test(decryptedValue);
924
907
  })();
925
908
 
926
909
  validationPromise.then((isValid) => {