@bchr/bchr-front-lib 0.6.5 → 0.6.6

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.
@@ -7,290 +7,61 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _antd = require("antd");
10
- var _excluded = ["ui_render_type", "initValue", "value", "onChange", "maskLength", "placeholder", "maxLength", "allowClear", "disabled", "onKeyDown", "onPaste"];
11
10
  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 _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
12
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
13
11
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
14
12
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
13
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
16
14
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
17
15
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
18
16
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
19
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
20
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
21
- var MASK_LENGTH = 8;
22
- var normalizeValue = function normalizeValue(value) {
23
- if (value === null || value === undefined) {
24
- return "";
25
- }
26
- return String(value);
27
- };
28
- var maskValue = function maskValue(value, maskLength) {
29
- if (value === null || value === undefined || value === "") {
30
- return "";
31
- }
32
- return "*".repeat(maskLength);
33
- };
34
- var limitText = function limitText(text, maxLength) {
35
- if (typeof maxLength === "number" && maxLength > 0 && text.length > maxLength) {
36
- return text.slice(0, maxLength);
37
- }
38
- return text;
39
- };
40
17
  var InputPassword = function InputPassword(props) {
41
18
  var ui_render_type = props.ui_render_type,
42
- initValue = props.initValue,
43
- value = props.value,
44
- onChange = props.onChange,
45
- maskLength = props.maskLength,
46
- placeholder = props.placeholder,
47
- maxLength = props.maxLength,
48
- _props$allowClear = props.allowClear,
49
- allowClear = _props$allowClear === void 0 ? true : _props$allowClear,
50
- _props$disabled = props.disabled,
51
- disabled = _props$disabled === void 0 ? false : _props$disabled,
52
- onKeyDown = props.onKeyDown,
53
- onPaste = props.onPaste,
54
- restInputProps = _objectWithoutProperties(props, _excluded);
55
- var resolvedMaskLength = Number.isInteger(maskLength) && maskLength > 0 ? maskLength : MASK_LENGTH;
56
- var incomingValue = normalizeValue(value !== undefined ? value : initValue);
57
- var _useState = (0, _react.useState)(incomingValue),
19
+ initValue = props.initValue;
20
+ var _useState = (0, _react.useState)(false),
58
21
  _useState2 = _slicedToArray(_useState, 2),
59
- realValue = _useState2[0],
60
- setRealValue = _useState2[1];
61
- var _useState3 = (0, _react.useState)(false),
22
+ toggle = _useState2[0],
23
+ setToggle = _useState2[1];
24
+ var _useState3 = (0, _react.useState)(initValue && initValue.split('').map(function (item) {
25
+ return '*';
26
+ }).join('')),
62
27
  _useState4 = _slicedToArray(_useState3, 2),
63
- toggle = _useState4[0],
64
- setToggle = _useState4[1];
65
- var _useState5 = (0, _react.useState)(maskValue(initValue, resolvedMaskLength)),
66
- _useState6 = _slicedToArray(_useState5, 2),
67
- toggleVal = _useState6[0],
68
- setToggleVal = _useState6[1];
69
- var _useState7 = (0, _react.useState)(-1),
70
- _useState8 = _slicedToArray(_useState7, 2),
71
- revealIndex = _useState8[0],
72
- setRevealIndex = _useState8[1];
73
- var timerRef = (0, _react.useRef)(null);
74
- var revealTimerRef = (0, _react.useRef)(null);
75
- var realValueRef = (0, _react.useRef)(incomingValue);
76
- var originalRef = (0, _react.useRef)(incomingValue);
77
- var emittedRef = (0, _react.useRef)(incomingValue);
78
- var editingRef = (0, _react.useRef)(false);
79
- var maskLengthRef = (0, _react.useRef)(resolvedMaskLength);
80
- realValueRef.current = ui_render_type === "modify" ? realValue : incomingValue;
81
- maskLengthRef.current = resolvedMaskLength;
82
- var clearHideTimer = function clearHideTimer() {
83
- if (timerRef.current) {
84
- clearTimeout(timerRef.current);
85
- timerRef.current = null;
86
- }
87
- };
88
- var clearRevealTimer = function clearRevealTimer() {
89
- if (revealTimerRef.current) {
90
- clearTimeout(revealTimerRef.current);
91
- revealTimerRef.current = null;
92
- }
93
- };
94
- var resetReveal = function resetReveal() {
95
- clearRevealTimer();
96
- setRevealIndex(-1);
97
- };
98
- var flashLastChar = function flashLastChar(val) {
99
- clearRevealTimer();
100
- if (!val) {
101
- setRevealIndex(-1);
102
- return;
103
- }
104
- setRevealIndex(val.length - 1);
105
- revealTimerRef.current = setTimeout(function () {
106
- revealTimerRef.current = null;
107
- setRevealIndex(-1);
108
- }, 500);
109
- };
110
- var hidePlainText = function hidePlainText() {
111
- clearHideTimer();
112
- resetReveal();
113
- setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
114
- setToggle(false);
115
- };
116
- var showPlainText = function showPlainText(plainText) {
117
- clearHideTimer();
118
- resetReveal();
119
- setToggleVal(plainText);
120
- setToggle(true);
121
- timerRef.current = setTimeout(function () {
122
- timerRef.current = null;
123
- setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
124
- setToggle(false);
125
- }, 5000);
126
- };
127
- (0, _react.useEffect)(function () {
128
- return function () {
129
- clearHideTimer();
130
- clearRevealTimer();
131
- };
132
- }, []);
133
- (0, _react.useEffect)(function () {
134
- if (ui_render_type === "modify") {
135
- return undefined;
136
- }
137
- clearHideTimer();
138
- resetReveal();
139
- setToggle(false);
140
- setToggleVal(maskValue(incomingValue, resolvedMaskLength));
141
- return function () {
142
- return clearHideTimer();
143
- };
144
- }, [ui_render_type, incomingValue, resolvedMaskLength]);
145
- (0, _react.useEffect)(function () {
146
- if (ui_render_type !== "modify" || incomingValue === emittedRef.current) {
147
- return undefined;
148
- }
149
- emittedRef.current = incomingValue;
150
- originalRef.current = incomingValue;
151
- editingRef.current = false;
152
- realValueRef.current = incomingValue;
153
- setRealValue(incomingValue);
154
- clearHideTimer();
155
- resetReveal();
156
- setToggle(false);
157
- setToggleVal(maskValue(incomingValue, resolvedMaskLength));
158
- }, [ui_render_type, incomingValue, resolvedMaskLength]);
159
- var commitValue = function commitValue(nextValue, flash) {
160
- var normalized = limitText(normalizeValue(nextValue), maxLength);
161
- emittedRef.current = normalized;
162
- editingRef.current = true;
163
- realValueRef.current = normalized;
164
- setRealValue(normalized);
165
- if (flash) {
166
- flashLastChar(normalized);
167
- } else {
168
- resetReveal();
169
- }
170
- if (onChange) {
171
- onChange({
172
- target: {
173
- value: normalized
174
- }
175
- });
176
- }
177
- };
28
+ toggleVal = _useState4[0],
29
+ setToggleVal = _useState4[1];
178
30
  var onToggleFull = function onToggleFull() {
179
- if (disabled) {
180
- return;
181
- }
182
31
  if (toggle) {
183
- hidePlainText();
184
- return;
185
- }
186
- resetReveal();
187
- var plainText = realValueRef.current;
188
- if (ui_render_type === "modify" && (plainText === "" || editingRef.current || plainText !== originalRef.current)) {
189
- if (plainText) {
190
- showPlainText(plainText);
191
- }
192
- return;
193
- }
194
- if (plainText) {
195
- showPlainText(plainText);
196
- }
197
- };
198
- var onModifyKeyDown = function onModifyKeyDown(event) {
199
- if (onKeyDown) {
200
- onKeyDown(event);
201
- }
202
- if (disabled || toggle || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
203
- return;
204
- }
205
- if (event.key === "Backspace" || event.key === "Delete") {
206
- event.preventDefault();
207
- commitValue(editingRef.current ? realValueRef.current.slice(0, -1) : "", false);
208
- return;
209
- }
210
- if (event.key.length !== 1) {
211
- return;
212
- }
213
- event.preventDefault();
214
- commitValue(editingRef.current ? realValueRef.current + event.key : event.key, true);
215
- };
216
- var onModifyPaste = function onModifyPaste(event) {
217
- if (onPaste) {
218
- onPaste(event);
219
- }
220
- if (disabled || toggle || event.defaultPrevented) {
221
- return;
222
- }
223
- var text = event.clipboardData ? event.clipboardData.getData("text") : "";
224
- event.preventDefault();
225
- if (text) {
226
- commitValue(editingRef.current ? realValueRef.current + text : text, false);
227
- }
228
- };
229
- var onModifyChange = function onModifyChange(event) {
230
- var nextValue = event.target.value;
231
- if (!toggle) {
232
- if (nextValue === "") {
233
- commitValue("", false);
234
- }
235
- return;
236
- }
237
- var normalized = limitText(normalizeValue(nextValue), maxLength);
238
- emittedRef.current = normalized;
239
- editingRef.current = true;
240
- realValueRef.current = normalized;
241
- setRealValue(normalized);
242
- setToggleVal(normalized);
243
- if (onChange) {
244
- onChange({
245
- target: {
246
- value: normalized
247
- }
248
- });
249
- }
250
- };
251
- if (ui_render_type === "modify") {
252
- var modifyDisplay;
253
- if (toggle) {
254
- modifyDisplay = toggleVal;
255
- } else if (editingRef.current && realValue) {
256
- modifyDisplay = realValue.split("").map(function (_char, index) {
257
- return index === revealIndex ? _char : "*";
258
- }).join("");
259
- } else if (realValue) {
260
- modifyDisplay = maskValue(realValue, resolvedMaskLength);
32
+ setToggleVal(initValue && initValue.split('').map(function (item) {
33
+ return '*';
34
+ }).join(''));
35
+ setToggle(false);
261
36
  } else {
262
- modifyDisplay = "";
37
+ setToggleVal(initValue);
38
+ setToggle(true);
39
+ setTimeout(function () {
40
+ setToggleVal(initValue && initValue.split('').map(function (item) {
41
+ return '*';
42
+ }).join(''));
43
+ setToggle(false);
44
+ }, 5000);
263
45
  }
264
- return /*#__PURE__*/_react["default"].createElement(_antd.Input, _extends({}, restInputProps, {
265
- value: modifyDisplay,
266
- placeholder: placeholder,
267
- disabled: disabled,
268
- allowClear: allowClear && !disabled,
269
- maxLength: toggle && typeof maxLength === "number" ? maxLength : undefined,
270
- onChange: onModifyChange,
271
- onKeyDown: onModifyKeyDown,
272
- onPaste: onModifyPaste,
46
+ };
47
+ if (ui_render_type === 'modify') {
48
+ return /*#__PURE__*/_react["default"].createElement(_antd.Input, {
49
+ defaultValue: toggleVal,
273
50
  addonAfter: /*#__PURE__*/_react["default"].createElement("span", {
274
- className: "iconfont ".concat(toggle ? "icon-bchr-show" : "icon-bchr-hide"),
275
- style: {
276
- cursor: disabled ? "not-allowed" : "pointer"
277
- },
278
- onClick: onToggleFull
51
+ className: "iconfont ".concat(toggle ? 'icon-bchr-show' : 'icon-bchr-hide')
279
52
  })
280
- }));
281
- }
282
- if (ui_render_type === "browse") {
53
+ });
54
+ } else if (ui_render_type === 'browse') {
283
55
  return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("span", null, toggleVal, /*#__PURE__*/_react["default"].createElement("span", {
284
- className: "iconfont ".concat(toggle ? "icon-bchr-show" : "icon-bchr-hide"),
56
+ className: "iconfont ".concat(toggle ? 'icon-bchr-show' : 'icon-bchr-hide'),
285
57
  style: {
286
- cursor: disabled ? "not-allowed" : "pointer",
287
- margin: "0 5px",
288
- color: "#337DB7",
289
- fontWeight: "bolder"
58
+ cursor: 'pointer',
59
+ margin: '0 5px',
60
+ color: '#337DB7',
61
+ fontWeight: 'bolder'
290
62
  },
291
63
  onClick: onToggleFull
292
64
  })));
293
65
  }
294
- return null;
295
66
  };
296
67
  var _default = exports["default"] = InputPassword;
@@ -74,16 +74,11 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
74
74
  _useState6 = _slicedToArray(_useState5, 2),
75
75
  toggleVal = _useState6[0],
76
76
  setToggleVal = _useState6[1];
77
- var _useState7 = (0, _react.useState)(-1),
77
+ var _useState7 = (0, _react.useState)(false),
78
78
  _useState8 = _slicedToArray(_useState7, 2),
79
- revealIndex = _useState8[0],
80
- setRevealIndex = _useState8[1];
81
- var _useState9 = (0, _react.useState)(false),
82
- _useState0 = _slicedToArray(_useState9, 2),
83
- loading = _useState0[0],
84
- setLoading = _useState0[1];
79
+ loading = _useState8[0],
80
+ setLoading = _useState8[1];
85
81
  var timerRef = (0, _react.useRef)(null);
86
- var revealTimerRef = (0, _react.useRef)(null);
87
82
  var requestSeqRef = (0, _react.useRef)(0);
88
83
  var realValueRef = (0, _react.useRef)(incomingValue);
89
84
  var originalRef = (0, _react.useRef)(incomingValue);
@@ -98,37 +93,13 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
98
93
  timerRef.current = null;
99
94
  }
100
95
  };
101
- var clearRevealTimer = function clearRevealTimer() {
102
- if (revealTimerRef.current) {
103
- clearTimeout(revealTimerRef.current);
104
- revealTimerRef.current = null;
105
- }
106
- };
107
- var resetReveal = function resetReveal() {
108
- clearRevealTimer();
109
- setRevealIndex(-1);
110
- };
111
- var flashLastChar = function flashLastChar(val) {
112
- clearRevealTimer();
113
- if (!val) {
114
- setRevealIndex(-1);
115
- return;
116
- }
117
- setRevealIndex(val.length - 1);
118
- revealTimerRef.current = setTimeout(function () {
119
- revealTimerRef.current = null;
120
- setRevealIndex(-1);
121
- }, 500);
122
- };
123
96
  var hidePlainText = function hidePlainText() {
124
97
  clearHideTimer();
125
- resetReveal();
126
98
  setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
127
99
  setToggle(false);
128
100
  };
129
101
  var showPlainText = function showPlainText(plainText) {
130
102
  clearHideTimer();
131
- resetReveal();
132
103
  setToggleVal(plainText);
133
104
  setToggle(true);
134
105
  timerRef.current = setTimeout(function () {
@@ -141,7 +112,6 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
141
112
  return function () {
142
113
  requestSeqRef.current += 1;
143
114
  clearHideTimer();
144
- clearRevealTimer();
145
115
  };
146
116
  }, []);
147
117
  (0, _react.useEffect)(function () {
@@ -167,21 +137,18 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
167
137
  setRealValue(incomingValue);
168
138
  requestSeqRef.current += 1;
169
139
  clearHideTimer();
170
- resetReveal();
171
140
  setToggle(false);
172
141
  setToggleVal(maskValue(incomingValue, resolvedMaskLength));
173
142
  setLoading(false);
174
143
  }, [ui_render_type, incomingValue, resolvedMaskLength]);
175
- var commitValue = function commitValue(nextValue, flash) {
144
+ var commitValue = function commitValue(nextValue, reveal) {
176
145
  var normalized = limitText(normalizeValue(nextValue), maxLength);
177
146
  emittedRef.current = normalized;
178
147
  editingRef.current = true;
179
148
  realValueRef.current = normalized;
180
149
  setRealValue(normalized);
181
- if (flash) {
182
- flashLastChar(normalized);
183
- } else {
184
- resetReveal();
150
+ if (reveal) {
151
+ showPlainText(normalized);
185
152
  }
186
153
  if (onChange) {
187
154
  onChange({
@@ -204,7 +171,6 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
204
171
  hidePlainText();
205
172
  return _context.a(2);
206
173
  case 1:
207
- resetReveal();
208
174
  if (!loading) {
209
175
  _context.n = 2;
210
176
  break;
@@ -309,8 +275,7 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
309
275
  }
310
276
  if (event.key === "Backspace" || event.key === "Delete") {
311
277
  event.preventDefault();
312
- var _nextValue = editingRef.current ? realValueRef.current.slice(0, -1) : "";
313
- commitValue(_nextValue, false);
278
+ commitValue("", false);
314
279
  return;
315
280
  }
316
281
  if (event.key.length !== 1) {
@@ -318,7 +283,7 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
318
283
  }
319
284
  event.preventDefault();
320
285
  var nextValue = editingRef.current ? realValueRef.current + event.key : event.key;
321
- commitValue(nextValue, true);
286
+ commitValue(nextValue, false);
322
287
  };
323
288
  var onModifyPaste = function onModifyPaste(event) {
324
289
  if (onPaste) {
@@ -343,33 +308,10 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
343
308
  }
344
309
  return;
345
310
  }
346
- var normalized = limitText(normalizeValue(nextValue), maxLength);
347
- emittedRef.current = normalized;
348
- editingRef.current = true;
349
- realValueRef.current = normalized;
350
- setRealValue(normalized);
351
- setToggleVal(normalized);
352
- if (onChange) {
353
- onChange({
354
- target: {
355
- value: normalized
356
- }
357
- });
358
- }
311
+ commitValue(nextValue, true);
359
312
  };
360
313
  if (ui_render_type === "modify") {
361
- var modifyDisplay;
362
- if (toggle) {
363
- modifyDisplay = toggleVal;
364
- } else if (editingRef.current && realValue) {
365
- modifyDisplay = realValue.split("").map(function (c, i) {
366
- return i === revealIndex ? c : "*";
367
- }).join("");
368
- } else if (realValue) {
369
- modifyDisplay = maskValue(realValue, resolvedMaskLength);
370
- } else {
371
- modifyDisplay = "";
372
- }
314
+ var modifyDisplay = toggle ? toggleVal : maskValue(realValue, resolvedMaskLength);
373
315
  return /*#__PURE__*/_react["default"].createElement(_antd.Input, _extends({}, restInputProps, {
374
316
  value: modifyDisplay,
375
317
  placeholder: placeholder,
@@ -18,16 +18,16 @@ var _BaseAppUtils = require("../../../BaseAppUtils");
18
18
  var _SmartModal = require("../../modal/SmartModal");
19
19
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
20
20
  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); }
21
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
22
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
23
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
24
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
25
21
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
26
22
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
27
23
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
28
24
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
29
25
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
30
26
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
27
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
28
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
29
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
30
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
31
31
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
32
32
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
33
33
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
@@ -297,6 +297,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
297
297
  display_code = display_code || code;
298
298
  var initialValue = data[code];
299
299
  var displayValue = data[display_code];
300
+ var fieldDisabled = b_readonly || b_disabled || _this2.disabledExpression(dataItem, data);
300
301
  var component, valuePropName;
301
302
  if (custom_form_items && custom_form_items[code + "_form_item"] && typeof custom_form_items[code + "_form_item"] === "function") {
302
303
  component = custom_form_items[code + "_form_item"](data);
@@ -571,7 +572,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
571
572
  id: "ant_form_item_".concat(code),
572
573
  key: "col_" + code
573
574
  }, /*#__PURE__*/_react["default"].createElement(_antd.Form.Item, {
574
- className: (b_readonly ? "readonly-form-ant-col " : " ") + " ant-form-item-group-" + _this2.props.label_col,
575
+ className: (b_readonly ? "readonly-form-ant-col " : " ") + " ant-form-item-group-" + _this2.props.label_col + (ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT ? " bchr-input-password-decrypt-form-item" : ""),
575
576
  key: code,
576
577
  label: /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, dataItem.title_of_field_label_prefix && dataItem.title_of_field_label_prefix.trim().length > 0 && dataItem.field_label_prefix && dataItem.field_label_prefix.trim().length > 0 && /*#__PURE__*/_react["default"].createElement(_antd.Tooltip, {
577
578
  title: /*#__PURE__*/_react["default"].createElement("span", {
@@ -610,7 +611,13 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
610
611
  required: false,
611
612
  message: name + "格式不正确",
612
613
  whitespace: true,
613
- validator: _this2.formatValidator.bind(_this2),
614
+ validator: _this2.formatValidator.bind(_this2, {
615
+ ui_render_type: ui_render_type,
616
+ fieldDisabled: fieldDisabled,
617
+ initialValue: initialValue,
618
+ requestUrl: _this2.props.requestUrl || file_service_path,
619
+ serviceConfig: _this2.props.appconfig || _this2.props.appConfig
620
+ }),
614
621
  pattern: regexp_pattern
615
622
  }],
616
623
  hasFeedback: !dataItem.b_readonly && b_required,
@@ -794,6 +801,8 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
794
801
  }
795
802
  });
796
803
  _this2.ref = _this2.props.formref || /*#__PURE__*/_react["default"].createRef();
804
+ _this2.passwordDecryptFormatValidationCache = new Map();
805
+ _this2.passwordDecryptFormatValidationRequests = new Map();
797
806
  _this2.xs = _this2.props.xs || 24;
798
807
  _this2.sm = _this2.props.sm || 24;
799
808
  _this2.md = _this2.props.md || 24;
@@ -885,9 +894,87 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
885
894
  if (!value || value.trim().length === 0) {
886
895
  return Promise.resolve();
887
896
  }
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) {
903
+ return Promise.resolve();
904
+ }
905
+ var normalizedInitialValue = this.normalizePasswordDecryptValidationValue(rule.initialValue);
906
+ if (normalizedValue === normalizedInitialValue) {
907
+ return this.validatePasswordDecryptFormat(normalizedValue, pattern, rule)["catch"](function (error) {
908
+ console.error("password decrypt format validation failed>>>>>>>>", error);
909
+ return Promise.reject("格式校验失败");
910
+ }).then(function (isValid) {
911
+ return isValid ? Promise.resolve() : Promise.reject("格式错误");
912
+ });
913
+ }
914
+ }
888
915
  var regExp = new RegExp(pattern);
889
916
  return regExp.test(value) ? Promise.resolve() : Promise.reject("格式错误");
890
917
  }
918
+ }, {
919
+ key: "normalizePasswordDecryptValidationValue",
920
+ value: function normalizePasswordDecryptValidationValue(value) {
921
+ if (value === null || value === undefined) {
922
+ return "";
923
+ }
924
+ return String(value);
925
+ }
926
+ }, {
927
+ key: "requestPasswordDecryptValue",
928
+ value: function requestPasswordDecryptValue(value, rule) {
929
+ var requestUrl = rule.requestUrl,
930
+ serviceConfig = rule.serviceConfig;
931
+ if (!requestUrl || !serviceConfig) {
932
+ throw new Error("password decrypt request config is blank");
933
+ }
934
+ return new _HttpService["default"](requestUrl, serviceConfig).post("decrypt", {
935
+ data: value
936
+ });
937
+ }
938
+ }, {
939
+ key: "validatePasswordDecryptFormat",
940
+ value: function validatePasswordDecryptFormat(value, pattern, rule) {
941
+ var _this3 = this;
942
+ var cacheKey = JSON.stringify([rule.requestUrl, pattern, value]);
943
+ if (this.passwordDecryptFormatValidationCache.has(cacheKey)) {
944
+ return Promise.resolve(this.passwordDecryptFormatValidationCache.get(cacheKey));
945
+ }
946
+ if (this.passwordDecryptFormatValidationRequests.has(cacheKey)) {
947
+ return this.passwordDecryptFormatValidationRequests.get(cacheKey);
948
+ }
949
+ var validationPromise = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
950
+ var decryptedValue;
951
+ return _regenerator().w(function (_context) {
952
+ while (1) switch (_context.n) {
953
+ case 0:
954
+ _context.n = 1;
955
+ return _this3.requestPasswordDecryptValue(value, rule);
956
+ case 1:
957
+ decryptedValue = _context.v;
958
+ if (!(typeof decryptedValue !== "string")) {
959
+ _context.n = 2;
960
+ break;
961
+ }
962
+ throw new Error("password decrypt validation result is not a string");
963
+ case 2:
964
+ return _context.a(2, new RegExp(pattern).test(decryptedValue));
965
+ }
966
+ }, _callee);
967
+ }))();
968
+ validationPromise.then(function (isValid) {
969
+ _this3.passwordDecryptFormatValidationCache.set(cacheKey, isValid);
970
+ })["catch"](function () {
971
+ return undefined;
972
+ });
973
+ this.passwordDecryptFormatValidationRequests.set(cacheKey, validationPromise);
974
+ return validationPromise["finally"](function () {
975
+ _this3.passwordDecryptFormatValidationRequests["delete"](cacheKey);
976
+ });
977
+ }
891
978
  }, {
892
979
  key: "beforeUpload",
893
980
  value: function beforeUpload(file) {
@@ -1156,7 +1243,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1156
1243
  }, {
1157
1244
  key: "buildTreeNode",
1158
1245
  value: function buildTreeNode(defNodes) {
1159
- var _this3 = this;
1246
+ var _this4 = this;
1160
1247
  if (!defNodes || defNodes.length === 0) {
1161
1248
  return null;
1162
1249
  }
@@ -1173,7 +1260,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1173
1260
  ext_attr_value: ext_attr_value,
1174
1261
  selectable: item.selectable,
1175
1262
  prop: ext_attr_value
1176
- }, _this3.buildTreeNode(item.children));
1263
+ }, _this4.buildTreeNode(item.children));
1177
1264
  });
1178
1265
  }
1179
1266
  }, {
@@ -1317,16 +1404,16 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1317
1404
  }, {
1318
1405
  key: "deleteFile",
1319
1406
  value: function () {
1320
- var _deleteFile = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(dataItem) {
1407
+ var _deleteFile = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(dataItem) {
1321
1408
  var file_pk, _this$props2, file_service_path, appconfig, _this, _t;
1322
- return _regenerator().w(function (_context) {
1323
- while (1) switch (_context.p = _context.n) {
1409
+ return _regenerator().w(function (_context2) {
1410
+ while (1) switch (_context2.p = _context2.n) {
1324
1411
  case 0:
1325
1412
  file_pk = this.props.data[dataItem.code];
1326
1413
  _this$props2 = this.props, file_service_path = _this$props2.file_service_path, appconfig = _this$props2.appconfig;
1327
- _context.p = 1;
1414
+ _context2.p = 1;
1328
1415
  _this = this;
1329
- _context.n = 2;
1416
+ _context2.n = 2;
1330
1417
  return new _HttpService["default"](file_service_path, this.props.appconfig).post("deleteFile", {
1331
1418
  file_pk: file_pk
1332
1419
  });
@@ -1337,17 +1424,17 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1337
1424
  this.setState(function (state) {
1338
1425
  return {};
1339
1426
  });
1340
- _context.n = 4;
1427
+ _context2.n = 4;
1341
1428
  break;
1342
1429
  case 3:
1343
- _context.p = 3;
1344
- _t = _context.v;
1430
+ _context2.p = 3;
1431
+ _t = _context2.v;
1345
1432
  console.log("删除文件失败>>>>>>>>", _t);
1346
1433
  _antd.message.error("删除失败");
1347
1434
  case 4:
1348
- return _context.a(2);
1435
+ return _context2.a(2);
1349
1436
  }
1350
- }, _callee, this, [[1, 3]]);
1437
+ }, _callee2, this, [[1, 3]]);
1351
1438
  }));
1352
1439
  function deleteFile(_x) {
1353
1440
  return _deleteFile.apply(this, arguments);
@@ -242,6 +242,10 @@
242
242
  }
243
243
  }
244
244
 
245
+ .bchr-input-password-decrypt-form-item .ant-form-item-children-icon {
246
+ display: none;
247
+ }
248
+
245
249
  .ant-select-dropdown {
246
250
  width: 100%;
247
251
  min-height: 38px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bchr/bchr-front-lib",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "bchr front lib",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,266 +1,32 @@
1
- import React, {Fragment, useEffect, useRef, useState} from "react";
1
+ import React, {Fragment, useState} from "react"
2
2
  import {Input} from "antd";
3
3
 
4
- const MASK_LENGTH = 8;
5
-
6
- const normalizeValue = (value) => {
7
- if (value === null || value === undefined) {
8
- return "";
9
- }
10
- return String(value);
11
- };
12
-
13
- const maskValue = (value, maskLength) => {
14
- if (value === null || value === undefined || value === "") {
15
- return "";
16
- }
17
- return "*".repeat(maskLength);
18
- };
19
-
20
- const limitText = (text, maxLength) => {
21
- if (typeof maxLength === "number" && maxLength > 0 && text.length > maxLength) {
22
- return text.slice(0, maxLength);
23
- }
24
- return text;
25
- };
26
-
27
4
  const InputPassword = (props) => {
28
- const {
29
- ui_render_type,
30
- initValue,
31
- value,
32
- onChange,
33
- maskLength,
34
- placeholder,
35
- maxLength,
36
- allowClear = true,
37
- disabled = false,
38
- onKeyDown,
39
- onPaste,
40
- ...restInputProps
41
- } = props;
42
- const resolvedMaskLength = Number.isInteger(maskLength) && maskLength > 0 ? maskLength : MASK_LENGTH;
43
- const incomingValue = normalizeValue(value !== undefined ? value : initValue);
44
- const [realValue, setRealValue] = useState(incomingValue);
5
+ let {ui_render_type, initValue} = props;
45
6
  const [toggle, setToggle] = useState(false);
46
- const [toggleVal, setToggleVal] = useState(maskValue(initValue, resolvedMaskLength));
47
- const [revealIndex, setRevealIndex] = useState(-1);
48
- const timerRef = useRef(null);
49
- const revealTimerRef = useRef(null);
50
- const realValueRef = useRef(incomingValue);
51
- const originalRef = useRef(incomingValue);
52
- const emittedRef = useRef(incomingValue);
53
- const editingRef = useRef(false);
54
- const maskLengthRef = useRef(resolvedMaskLength);
55
-
56
- realValueRef.current = ui_render_type === "modify" ? realValue : incomingValue;
57
- maskLengthRef.current = resolvedMaskLength;
58
-
59
- const clearHideTimer = () => {
60
- if (timerRef.current) {
61
- clearTimeout(timerRef.current);
62
- timerRef.current = null;
63
- }
64
- };
65
-
66
- const clearRevealTimer = () => {
67
- if (revealTimerRef.current) {
68
- clearTimeout(revealTimerRef.current);
69
- revealTimerRef.current = null;
70
- }
71
- };
72
-
73
- const resetReveal = () => {
74
- clearRevealTimer();
75
- setRevealIndex(-1);
76
- };
77
-
78
- const flashLastChar = (val) => {
79
- clearRevealTimer();
80
- if (!val) {
81
- setRevealIndex(-1);
82
- return;
83
- }
84
- setRevealIndex(val.length - 1);
85
- revealTimerRef.current = setTimeout(() => {
86
- revealTimerRef.current = null;
87
- setRevealIndex(-1);
88
- }, 500);
89
- };
90
-
91
- const hidePlainText = () => {
92
- clearHideTimer();
93
- resetReveal();
94
- setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
95
- setToggle(false);
96
- };
97
-
98
- const showPlainText = (plainText) => {
99
- clearHideTimer();
100
- resetReveal();
101
- setToggleVal(plainText);
102
- setToggle(true);
103
- timerRef.current = setTimeout(() => {
104
- timerRef.current = null;
105
- setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
106
- setToggle(false);
107
- }, 5000);
108
- };
109
-
110
- useEffect(() => () => {
111
- clearHideTimer();
112
- clearRevealTimer();
113
- }, []);
114
-
115
- useEffect(() => {
116
- if (ui_render_type === "modify") {
117
- return undefined;
118
- }
119
- clearHideTimer();
120
- resetReveal();
121
- setToggle(false);
122
- setToggleVal(maskValue(incomingValue, resolvedMaskLength));
123
- return () => clearHideTimer();
124
- }, [ui_render_type, incomingValue, resolvedMaskLength]);
125
-
126
- useEffect(() => {
127
- if (ui_render_type !== "modify" || incomingValue === emittedRef.current) {
128
- return undefined;
129
- }
130
- emittedRef.current = incomingValue;
131
- originalRef.current = incomingValue;
132
- editingRef.current = false;
133
- realValueRef.current = incomingValue;
134
- setRealValue(incomingValue);
135
- clearHideTimer();
136
- resetReveal();
137
- setToggle(false);
138
- setToggleVal(maskValue(incomingValue, resolvedMaskLength));
139
- }, [ui_render_type, incomingValue, resolvedMaskLength]);
140
-
141
- const commitValue = (nextValue, flash) => {
142
- const normalized = limitText(normalizeValue(nextValue), maxLength);
143
- emittedRef.current = normalized;
144
- editingRef.current = true;
145
- realValueRef.current = normalized;
146
- setRealValue(normalized);
147
- if (flash) {
148
- flashLastChar(normalized);
149
- } else {
150
- resetReveal();
151
- }
152
- if (onChange) {
153
- onChange({target: {value: normalized}});
154
- }
155
- };
7
+ const [toggleVal, setToggleVal] = useState(initValue && initValue.split('').map(item => '*').join(''))
156
8
 
157
9
  const onToggleFull = () => {
158
- if (disabled) {
159
- return;
160
- }
161
10
  if (toggle) {
162
- hidePlainText();
163
- return;
164
- }
165
- resetReveal();
166
- const plainText = realValueRef.current;
167
- if (ui_render_type === "modify" && (plainText === "" || editingRef.current || plainText !== originalRef.current)) {
168
- if (plainText) {
169
- showPlainText(plainText);
170
- }
171
- return;
172
- }
173
- if (plainText) {
174
- showPlainText(plainText);
175
- }
176
- };
177
-
178
- const onModifyKeyDown = (event) => {
179
- if (onKeyDown) {
180
- onKeyDown(event);
181
- }
182
- if (disabled || toggle || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
183
- return;
184
- }
185
- if (event.key === "Backspace" || event.key === "Delete") {
186
- event.preventDefault();
187
- commitValue(editingRef.current ? realValueRef.current.slice(0, -1) : "", false);
188
- return;
189
- }
190
- if (event.key.length !== 1) {
191
- return;
192
- }
193
- event.preventDefault();
194
- commitValue(editingRef.current ? realValueRef.current + event.key : event.key, true);
195
- };
196
-
197
- const onModifyPaste = (event) => {
198
- if (onPaste) {
199
- onPaste(event);
200
- }
201
- if (disabled || toggle || event.defaultPrevented) {
202
- return;
203
- }
204
- const text = event.clipboardData ? event.clipboardData.getData("text") : "";
205
- event.preventDefault();
206
- if (text) {
207
- commitValue(editingRef.current ? realValueRef.current + text : text, false);
208
- }
209
- };
210
-
211
- const onModifyChange = (event) => {
212
- const nextValue = event.target.value;
213
- if (!toggle) {
214
- if (nextValue === "") {
215
- commitValue("", false);
216
- }
217
- return;
218
- }
219
- const normalized = limitText(normalizeValue(nextValue), maxLength);
220
- emittedRef.current = normalized;
221
- editingRef.current = true;
222
- realValueRef.current = normalized;
223
- setRealValue(normalized);
224
- setToggleVal(normalized);
225
- if (onChange) {
226
- onChange({target: {value: normalized}});
227
- }
228
- };
229
-
230
- if (ui_render_type === "modify") {
231
- let modifyDisplay;
232
- if (toggle) {
233
- modifyDisplay = toggleVal;
234
- } else if (editingRef.current && realValue) {
235
- modifyDisplay = realValue.split("").map((char, index) => index === revealIndex ? char : "*").join("");
236
- } else if (realValue) {
237
- modifyDisplay = maskValue(realValue, resolvedMaskLength);
11
+ setToggleVal(initValue && initValue.split('').map(item => '*').join(''))
12
+ setToggle(false);
238
13
  } else {
239
- modifyDisplay = "";
14
+ setToggleVal(initValue)
15
+ setToggle(true);
16
+ setTimeout(() => {
17
+ setToggleVal(initValue && initValue.split('').map(item => '*').join(''))
18
+ setToggle(false);
19
+ }, 5000)
240
20
  }
241
- return <Input
242
- {...restInputProps}
243
- value={modifyDisplay}
244
- placeholder={placeholder}
245
- disabled={disabled}
246
- allowClear={allowClear && !disabled}
247
- maxLength={toggle && typeof maxLength === "number" ? maxLength : undefined}
248
- onChange={onModifyChange}
249
- onKeyDown={onModifyKeyDown}
250
- onPaste={onModifyPaste}
251
- addonAfter={<span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`} style={{cursor: disabled ? "not-allowed" : "pointer"}} onClick={onToggleFull}/>}
252
- />;
253
21
  }
254
22
 
255
- if (ui_render_type === "browse") {
23
+ if (ui_render_type === 'modify') {
24
+ return <Input defaultValue={toggleVal} addonAfter={<span className={`iconfont ${toggle ? 'icon-bchr-show' : 'icon-bchr-hide'}`}/>}/>
25
+ } else if (ui_render_type === 'browse') {
256
26
  return <Fragment>
257
- <span>{toggleVal}<span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`}
258
- style={{cursor: disabled ? "not-allowed" : "pointer", margin: "0 5px", color: "#337DB7", fontWeight: "bolder"}}
259
- onClick={onToggleFull}/></span>
260
- </Fragment>;
27
+ <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>
28
+ </Fragment>
261
29
  }
262
-
263
- return null;
264
- };
30
+ }
265
31
 
266
32
  export default InputPassword;
@@ -48,10 +48,8 @@ const InputPasswordDecrypt = (props) => {
48
48
  const [realValue, setRealValue] = useState(incomingValue);
49
49
  const [toggle, setToggle] = useState(false);
50
50
  const [toggleVal, setToggleVal] = useState(maskValue(initValue, resolvedMaskLength));
51
- const [revealIndex, setRevealIndex] = useState(-1);
52
51
  const [loading, setLoading] = useState(false);
53
52
  const timerRef = useRef(null);
54
- const revealTimerRef = useRef(null);
55
53
  const requestSeqRef = useRef(0);
56
54
  const realValueRef = useRef(incomingValue);
57
55
  const originalRef = useRef(incomingValue);
@@ -69,41 +67,14 @@ const InputPasswordDecrypt = (props) => {
69
67
  }
70
68
  };
71
69
 
72
- const clearRevealTimer = () => {
73
- if (revealTimerRef.current) {
74
- clearTimeout(revealTimerRef.current);
75
- revealTimerRef.current = null;
76
- }
77
- };
78
-
79
- const resetReveal = () => {
80
- clearRevealTimer();
81
- setRevealIndex(-1);
82
- };
83
-
84
- const flashLastChar = (val) => {
85
- clearRevealTimer();
86
- if (!val) {
87
- setRevealIndex(-1);
88
- return;
89
- }
90
- setRevealIndex(val.length - 1);
91
- revealTimerRef.current = setTimeout(() => {
92
- revealTimerRef.current = null;
93
- setRevealIndex(-1);
94
- }, 500);
95
- };
96
-
97
70
  const hidePlainText = () => {
98
71
  clearHideTimer();
99
- resetReveal();
100
72
  setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
101
73
  setToggle(false);
102
74
  };
103
75
 
104
76
  const showPlainText = (plainText) => {
105
77
  clearHideTimer();
106
- resetReveal();
107
78
  setToggleVal(plainText);
108
79
  setToggle(true);
109
80
  timerRef.current = setTimeout(() => {
@@ -117,7 +88,6 @@ const InputPasswordDecrypt = (props) => {
117
88
  return () => {
118
89
  requestSeqRef.current += 1;
119
90
  clearHideTimer();
120
- clearRevealTimer();
121
91
  };
122
92
  }, []);
123
93
 
@@ -145,22 +115,19 @@ const InputPasswordDecrypt = (props) => {
145
115
  setRealValue(incomingValue);
146
116
  requestSeqRef.current += 1;
147
117
  clearHideTimer();
148
- resetReveal();
149
118
  setToggle(false);
150
119
  setToggleVal(maskValue(incomingValue, resolvedMaskLength));
151
120
  setLoading(false);
152
121
  }, [ui_render_type, incomingValue, resolvedMaskLength]);
153
122
 
154
- const commitValue = (nextValue, flash) => {
123
+ const commitValue = (nextValue, reveal) => {
155
124
  const normalized = limitText(normalizeValue(nextValue), maxLength);
156
125
  emittedRef.current = normalized;
157
126
  editingRef.current = true;
158
127
  realValueRef.current = normalized;
159
128
  setRealValue(normalized);
160
- if (flash) {
161
- flashLastChar(normalized);
162
- } else {
163
- resetReveal();
129
+ if (reveal) {
130
+ showPlainText(normalized);
164
131
  }
165
132
  if (onChange) {
166
133
  onChange({target: {value: normalized}});
@@ -172,7 +139,6 @@ const InputPasswordDecrypt = (props) => {
172
139
  hidePlainText();
173
140
  return;
174
141
  }
175
- resetReveal();
176
142
  if (loading) {
177
143
  return;
178
144
  }
@@ -235,8 +201,7 @@ const InputPasswordDecrypt = (props) => {
235
201
  }
236
202
  if (event.key === "Backspace" || event.key === "Delete") {
237
203
  event.preventDefault();
238
- const nextValue = editingRef.current ? realValueRef.current.slice(0, -1) : "";
239
- commitValue(nextValue, false);
204
+ commitValue("", false);
240
205
  return;
241
206
  }
242
207
  if (event.key.length !== 1) {
@@ -244,7 +209,7 @@ const InputPasswordDecrypt = (props) => {
244
209
  }
245
210
  event.preventDefault();
246
211
  const nextValue = editingRef.current ? realValueRef.current + event.key : event.key;
247
- commitValue(nextValue, true);
212
+ commitValue(nextValue, false);
248
213
  };
249
214
 
250
215
  const onModifyPaste = (event) => {
@@ -271,28 +236,11 @@ const InputPasswordDecrypt = (props) => {
271
236
  }
272
237
  return;
273
238
  }
274
- const normalized = limitText(normalizeValue(nextValue), maxLength);
275
- emittedRef.current = normalized;
276
- editingRef.current = true;
277
- realValueRef.current = normalized;
278
- setRealValue(normalized);
279
- setToggleVal(normalized);
280
- if (onChange) {
281
- onChange({target: {value: normalized}});
282
- }
239
+ commitValue(nextValue, true);
283
240
  };
284
241
 
285
242
  if (ui_render_type === "modify") {
286
- let modifyDisplay;
287
- if (toggle) {
288
- modifyDisplay = toggleVal;
289
- } else if (editingRef.current && realValue) {
290
- modifyDisplay = realValue.split("").map((c, i) => i === revealIndex ? c : "*").join("");
291
- } else if (realValue) {
292
- modifyDisplay = maskValue(realValue, resolvedMaskLength);
293
- } else {
294
- modifyDisplay = "";
295
- }
243
+ const modifyDisplay = toggle ? toggleVal : maskValue(realValue, resolvedMaskLength);
296
244
  return <Input
297
245
  {...restInputProps}
298
246
  value={modifyDisplay}
@@ -39,6 +39,8 @@ class FormForModify extends React.Component{
39
39
  super(props);
40
40
 
41
41
  this.ref = this.props.formref || React.createRef();
42
+ this.passwordDecryptFormatValidationCache = new Map();
43
+ this.passwordDecryptFormatValidationRequests = new Map();
42
44
 
43
45
  this.xs = this.props.xs || 24;
44
46
  this.sm = this.props.sm || 24;
@@ -347,6 +349,7 @@ class FormForModify extends React.Component{
347
349
  display_code = display_code || code;
348
350
  let initialValue = data[code];
349
351
  let displayValue = data[display_code];
352
+ let fieldDisabled = b_readonly || b_disabled || this.disabledExpression(dataItem, data);
350
353
 
351
354
  let component, valuePropName;
352
355
  if (custom_form_items && custom_form_items[code + "_form_item"] && typeof custom_form_items[code + "_form_item"] === "function") {
@@ -749,7 +752,7 @@ class FormForModify extends React.Component{
749
752
  return (
750
753
  <Col xs={this.xs} sm={this.sm} md={this.md} lg={this.lg} xl={this.xl} xxl={this.xxl} id={`ant_form_item_${code}`} key={"col_" + code}>
751
754
  <Form.Item
752
- className={(b_readonly ? "readonly-form-ant-col " : " ") + " ant-form-item-group-" + this.props.label_col}
755
+ className={(b_readonly ? "readonly-form-ant-col " : " ") + " ant-form-item-group-" + this.props.label_col + (ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT ? " bchr-input-password-decrypt-form-item" : "")}
753
756
  key={code}
754
757
  label={
755
758
  <Fragment>
@@ -774,7 +777,13 @@ class FormForModify extends React.Component{
774
777
  initialValue={initialValue}
775
778
  rules={[
776
779
  {required: (!dataItem.b_readonly && b_required), message: ("请填写" + name), whitespace: true, validator: this.validator.bind(this, (!dataItem.b_readonly && b_required), ui_render_type)},
777
- {required: false, message: (name + "格式不正确"), whitespace: true, validator: this.formatValidator.bind(this), pattern: regexp_pattern}
780
+ {required: false, message: (name + "格式不正确"), whitespace: true, validator: this.formatValidator.bind(this, {
781
+ ui_render_type,
782
+ fieldDisabled,
783
+ initialValue,
784
+ requestUrl: this.props.requestUrl || file_service_path,
785
+ serviceConfig: this.props.appconfig || this.props.appConfig
786
+ }), pattern: regexp_pattern}
778
787
  ]}
779
788
  hasFeedback={(!dataItem.b_readonly && b_required)}
780
789
  valuePropName={valuePropName ? valuePropName : "value"}
@@ -833,11 +842,80 @@ class FormForModify extends React.Component{
833
842
  return Promise.resolve();
834
843
  }
835
844
 
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) {
852
+ return Promise.resolve();
853
+ }
854
+
855
+ const normalizedInitialValue = this.normalizePasswordDecryptValidationValue(rule.initialValue);
856
+ if (normalizedValue === normalizedInitialValue) {
857
+ return this.validatePasswordDecryptFormat(normalizedValue, pattern, rule)
858
+ .catch((error) => {
859
+ console.error("password decrypt format validation failed>>>>>>>>", error);
860
+ return Promise.reject("格式校验失败");
861
+ })
862
+ .then((isValid) => isValid ? Promise.resolve() : Promise.reject("格式错误"));
863
+ }
864
+ }
865
+
836
866
  let regExp = new RegExp(pattern);
837
867
 
838
868
  return regExp.test(value) ? Promise.resolve() : Promise.reject("格式错误");
839
869
  }
840
870
 
871
+ normalizePasswordDecryptValidationValue(value) {
872
+ if (value === null || value === undefined) {
873
+ return "";
874
+ }
875
+
876
+ return String(value);
877
+ }
878
+
879
+ requestPasswordDecryptValue(value, rule) {
880
+ const {requestUrl, serviceConfig} = rule;
881
+
882
+ if (!requestUrl || !serviceConfig) {
883
+ throw new Error("password decrypt request config is blank");
884
+ }
885
+
886
+ return new HttpService(requestUrl, serviceConfig).post("decrypt", {data: value});
887
+ }
888
+
889
+ validatePasswordDecryptFormat(value, pattern, rule) {
890
+ const cacheKey = JSON.stringify([rule.requestUrl, pattern, value]);
891
+
892
+ if (this.passwordDecryptFormatValidationCache.has(cacheKey)) {
893
+ return Promise.resolve(this.passwordDecryptFormatValidationCache.get(cacheKey));
894
+ }
895
+
896
+ if (this.passwordDecryptFormatValidationRequests.has(cacheKey)) {
897
+ return this.passwordDecryptFormatValidationRequests.get(cacheKey);
898
+ }
899
+
900
+ const validationPromise = (async () => {
901
+ const decryptedValue = await this.requestPasswordDecryptValue(value, rule);
902
+ if (typeof decryptedValue !== "string") {
903
+ throw new Error("password decrypt validation result is not a string");
904
+ }
905
+
906
+ return new RegExp(pattern).test(decryptedValue);
907
+ })();
908
+
909
+ validationPromise.then((isValid) => {
910
+ this.passwordDecryptFormatValidationCache.set(cacheKey, isValid);
911
+ }).catch(() => undefined);
912
+ this.passwordDecryptFormatValidationRequests.set(cacheKey, validationPromise);
913
+
914
+ return validationPromise.finally(() => {
915
+ this.passwordDecryptFormatValidationRequests.delete(cacheKey);
916
+ });
917
+ }
918
+
841
919
  getDictTitle = (ref_pk, value, b_multiple) => {
842
920
  let {def_docs} = this.props;
843
921
  let title = null;
@@ -242,6 +242,10 @@
242
242
  }
243
243
  }
244
244
 
245
+ .bchr-input-password-decrypt-form-item .ant-form-item-children-icon {
246
+ display: none;
247
+ }
248
+
245
249
  .ant-select-dropdown {
246
250
  width: 100%;
247
251
  min-height: 38px;