@bchr/bchr-front-lib 0.6.9 → 0.6.10

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,12 +7,18 @@ 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 _icons = require("@ant-design/icons");
10
11
  var _HttpService = _interopRequireDefault(require("../../../services/HttpService"));
11
12
  var _utils = require("../../utils");
12
- var _excluded = ["ui_render_type", "initValue", "value", "onChange", "requestUrl", "appconfig", "appConfig", "maskLength", "placeholder", "maxLength", "allowClear", "onKeyDown", "onPaste"];
13
+ var _excluded = ["ui_render_type", "initValue", "value", "onChange", "requestUrl", "appconfig", "appConfig", "maskLength", "placeholder", "maxLength", "onChangeValueType", "allowClear", "disabled", "className", "style", "onKeyDown", "onPaste"];
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
15
  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); }
15
16
  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); }
17
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
21
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
22
  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 }; })(); }
17
23
  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); }
18
24
  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); }
@@ -25,7 +31,13 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
25
31
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
26
32
  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; }
27
33
  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; }
28
- var MASK_LENGTH = 8;
34
+ var DEFAULT_MASK_LENGTH = 8;
35
+ var DEFAULT_VISIBLE_DURATION = 5000;
36
+ var PASSWORD_ICON_STYLE = {
37
+ cursor: "pointer",
38
+ color: "#337DB7",
39
+ fontWeight: "bolder"
40
+ };
29
41
  var normalizeValue = function normalizeValue(value) {
30
42
  if (value === null || value === undefined) {
31
43
  return "";
@@ -44,24 +56,33 @@ var limitText = function limitText(text, maxLength) {
44
56
  }
45
57
  return text;
46
58
  };
59
+ var getErrorMessage = function getErrorMessage(error) {
60
+ return error && error.responseJSON && error.responseJSON.msg || error && error.message || "解密失败";
61
+ };
47
62
  var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
48
63
  var ui_render_type = props.ui_render_type,
49
64
  initValue = props.initValue,
50
65
  value = props.value,
51
66
  onChange = props.onChange,
52
67
  requestUrl = props.requestUrl,
53
- appconfig = props.appconfig,
54
- appConfig = props.appConfig,
68
+ serviceAppconfig = props.appconfig,
69
+ serviceAppConfig = props.appConfig,
55
70
  maskLength = props.maskLength,
56
71
  placeholder = props.placeholder,
57
72
  maxLength = props.maxLength,
73
+ _props$onChangeValueT = props.onChangeValueType,
74
+ onChangeValueType = _props$onChangeValueT === void 0 ? "event" : _props$onChangeValueT,
58
75
  _props$allowClear = props.allowClear,
59
76
  allowClear = _props$allowClear === void 0 ? true : _props$allowClear,
77
+ disabled = props.disabled,
78
+ className = props.className,
79
+ style = props.style,
60
80
  onKeyDown = props.onKeyDown,
61
81
  onPaste = props.onPaste,
62
82
  restInputProps = _objectWithoutProperties(props, _excluded);
63
- var resolvedMaskLength = Number.isInteger(maskLength) && maskLength > 0 ? maskLength : MASK_LENGTH;
64
- var serviceConfig = appconfig || appConfig;
83
+ var resolvedMaskLength = _utils.Values.isInteger(maskLength) && maskLength > 0 ? maskLength : DEFAULT_MASK_LENGTH;
84
+ var serviceConfig = serviceAppconfig || serviceAppConfig;
85
+ var requestContextPath = _utils.Values.isNotBlankString(requestUrl) ? requestUrl : _utils.Values.isNotBlankString(serviceConfig) ? serviceConfig : serviceConfig && (serviceConfig.requestContextPath || serviceConfig.requestUrl) || "";
65
86
  var incomingValue = normalizeValue(value !== undefined ? value : initValue);
66
87
  var _useState = (0, _react.useState)(incomingValue),
67
88
  _useState2 = _slicedToArray(_useState, 2),
@@ -71,93 +92,140 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
71
92
  _useState4 = _slicedToArray(_useState3, 2),
72
93
  toggle = _useState4[0],
73
94
  setToggle = _useState4[1];
74
- var _useState5 = (0, _react.useState)(maskValue(initValue, resolvedMaskLength)),
95
+ var _useState5 = (0, _react.useState)(maskValue(incomingValue, resolvedMaskLength)),
75
96
  _useState6 = _slicedToArray(_useState5, 2),
76
97
  toggleVal = _useState6[0],
77
98
  setToggleVal = _useState6[1];
78
- var _useState7 = (0, _react.useState)(false),
99
+ var _useState7 = (0, _react.useState)(-1),
79
100
  _useState8 = _slicedToArray(_useState7, 2),
80
- loading = _useState8[0],
81
- setLoading = _useState8[1];
82
- var timerRef = (0, _react.useRef)(null);
101
+ revealIndex = _useState8[0],
102
+ setRevealIndex = _useState8[1];
103
+ var _useState9 = (0, _react.useState)(null),
104
+ _useState0 = _slicedToArray(_useState9, 2),
105
+ compositionDisplay = _useState0[0],
106
+ setCompositionDisplay = _useState0[1];
107
+ var _useState1 = (0, _react.useState)(false),
108
+ _useState10 = _slicedToArray(_useState1, 2),
109
+ loading = _useState10[0],
110
+ setLoading = _useState10[1];
111
+ var hideTimerRef = (0, _react.useRef)(null);
112
+ var revealTimerRef = (0, _react.useRef)(null);
83
113
  var requestSeqRef = (0, _react.useRef)(0);
84
114
  var realValueRef = (0, _react.useRef)(incomingValue);
85
- var originalRef = (0, _react.useRef)(incomingValue);
86
115
  var emittedRef = (0, _react.useRef)(incomingValue);
87
116
  var editingRef = (0, _react.useRef)(false);
88
117
  var maskLengthRef = (0, _react.useRef)(resolvedMaskLength);
89
- realValueRef.current = ui_render_type === "modify" ? realValue : normalizeValue(initValue);
118
+ var composingRef = (0, _react.useRef)(false);
119
+ var composeBaseDisplayRef = (0, _react.useRef)("");
120
+ var inputRef = (0, _react.useRef)(null);
121
+ realValueRef.current = ui_render_type === "modify" ? realValue : incomingValue;
90
122
  maskLengthRef.current = resolvedMaskLength;
91
- var clearHideTimer = function clearHideTimer() {
92
- if (timerRef.current) {
93
- clearTimeout(timerRef.current);
94
- timerRef.current = null;
123
+ var clearHideTimer = (0, _react.useCallback)(function () {
124
+ if (hideTimerRef.current) {
125
+ clearTimeout(hideTimerRef.current);
126
+ hideTimerRef.current = null;
127
+ }
128
+ }, []);
129
+ var clearRevealTimer = (0, _react.useCallback)(function () {
130
+ if (revealTimerRef.current) {
131
+ clearTimeout(revealTimerRef.current);
132
+ revealTimerRef.current = null;
95
133
  }
134
+ }, []);
135
+ var resetReveal = (0, _react.useCallback)(function () {
136
+ clearRevealTimer();
137
+ setRevealIndex(-1);
138
+ }, [clearRevealTimer]);
139
+ var flashLastChar = function flashLastChar(nextValue) {
140
+ clearRevealTimer();
141
+ if (!nextValue) {
142
+ setRevealIndex(-1);
143
+ return;
144
+ }
145
+ setRevealIndex(nextValue.length - 1);
146
+ revealTimerRef.current = setTimeout(function () {
147
+ revealTimerRef.current = null;
148
+ setRevealIndex(-1);
149
+ }, 500);
96
150
  };
97
151
  var hidePlainText = function hidePlainText() {
98
152
  clearHideTimer();
153
+ resetReveal();
99
154
  setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
100
155
  setToggle(false);
101
156
  };
102
157
  var showPlainText = function showPlainText(plainText) {
158
+ var autoHide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
103
159
  clearHideTimer();
160
+ resetReveal();
104
161
  setToggleVal(plainText);
105
162
  setToggle(true);
106
- timerRef.current = setTimeout(function () {
107
- timerRef.current = null;
108
- setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
109
- setToggle(false);
110
- }, 5000);
163
+ if (autoHide) {
164
+ hideTimerRef.current = setTimeout(function () {
165
+ hideTimerRef.current = null;
166
+ setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
167
+ setToggle(false);
168
+ }, DEFAULT_VISIBLE_DURATION);
169
+ }
111
170
  };
112
171
  (0, _react.useEffect)(function () {
113
172
  return function () {
114
173
  requestSeqRef.current += 1;
115
174
  clearHideTimer();
175
+ clearRevealTimer();
116
176
  };
117
- }, []);
177
+ }, [clearHideTimer, clearRevealTimer]);
118
178
  (0, _react.useEffect)(function () {
119
179
  if (ui_render_type === "modify") {
120
180
  return undefined;
121
181
  }
182
+ requestSeqRef.current += 1;
183
+ clearHideTimer();
184
+ resetReveal();
185
+ setCompositionDisplay(null);
122
186
  setToggle(false);
123
- setToggleVal(maskValue(initValue, resolvedMaskLength));
187
+ setToggleVal(maskValue(incomingValue, resolvedMaskLength));
124
188
  setLoading(false);
125
- return function () {
126
- requestSeqRef.current += 1;
127
- clearHideTimer();
128
- };
129
- }, [ui_render_type, initValue, resolvedMaskLength]);
189
+ return clearHideTimer;
190
+ }, [clearHideTimer, resetReveal, ui_render_type, incomingValue, resolvedMaskLength]);
130
191
  (0, _react.useEffect)(function () {
131
192
  if (ui_render_type !== "modify" || incomingValue === emittedRef.current) {
132
193
  return undefined;
133
194
  }
134
195
  emittedRef.current = incomingValue;
135
- originalRef.current = incomingValue;
136
196
  editingRef.current = false;
137
197
  realValueRef.current = incomingValue;
138
198
  setRealValue(incomingValue);
139
199
  requestSeqRef.current += 1;
140
200
  clearHideTimer();
201
+ resetReveal();
141
202
  setToggle(false);
142
203
  setToggleVal(maskValue(incomingValue, resolvedMaskLength));
143
204
  setLoading(false);
144
- }, [ui_render_type, incomingValue, resolvedMaskLength]);
145
- var commitValue = function commitValue(nextValue, reveal) {
205
+ return undefined;
206
+ }, [clearHideTimer, resetReveal, ui_render_type, incomingValue, resolvedMaskLength]);
207
+ var emitChange = function emitChange(nextValue) {
208
+ if (onChange) {
209
+ onChange(onChangeValueType === "value" ? nextValue : {
210
+ target: {
211
+ value: nextValue
212
+ }
213
+ });
214
+ }
215
+ };
216
+ var commitValue = function commitValue(nextValue, flash) {
146
217
  var normalized = limitText(normalizeValue(nextValue), maxLength);
147
218
  emittedRef.current = normalized;
148
219
  editingRef.current = true;
149
220
  realValueRef.current = normalized;
221
+ setCompositionDisplay(null);
150
222
  setRealValue(normalized);
151
- if (reveal) {
152
- showPlainText(normalized);
153
- }
154
- if (onChange) {
155
- onChange({
156
- target: {
157
- value: normalized
158
- }
159
- });
223
+ if (flash) {
224
+ flashLastChar(normalized);
225
+ } else {
226
+ resetReveal();
160
227
  }
228
+ emitChange(normalized);
161
229
  };
162
230
  var onToggleFull = /*#__PURE__*/function () {
163
231
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
@@ -165,30 +233,39 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
165
233
  return _regenerator().w(function (_context) {
166
234
  while (1) switch (_context.p = _context.n) {
167
235
  case 0:
168
- if (!toggle) {
236
+ if (!loading) {
169
237
  _context.n = 1;
170
238
  break;
171
239
  }
172
- hidePlainText();
173
240
  return _context.a(2);
174
241
  case 1:
175
- if (!loading) {
242
+ if (!toggle) {
176
243
  _context.n = 2;
177
244
  break;
178
245
  }
246
+ hidePlainText();
179
247
  return _context.a(2);
180
248
  case 2:
249
+ resetReveal();
181
250
  secret = realValueRef.current;
182
- if (!(ui_render_type === "modify" && (secret === "" || editingRef.current || secret !== originalRef.current))) {
251
+ if (!(ui_render_type === "modify")) {
183
252
  _context.n = 4;
184
253
  break;
185
254
  }
186
- if (!(secret === "")) {
255
+ if (secret) {
187
256
  _context.n = 3;
188
257
  break;
189
258
  }
259
+ commitValue("", false);
260
+ if (inputRef.current && inputRef.current.focus) {
261
+ inputRef.current.focus();
262
+ }
190
263
  return _context.a(2);
191
264
  case 3:
265
+ if (!editingRef.current) {
266
+ _context.n = 4;
267
+ break;
268
+ }
192
269
  showPlainText(secret);
193
270
  return _context.a(2);
194
271
  case 4:
@@ -198,7 +275,7 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
198
275
  }
199
276
  return _context.a(2);
200
277
  case 5:
201
- if (requestUrl) {
278
+ if (requestContextPath) {
202
279
  _context.n = 6;
203
280
  break;
204
281
  }
@@ -217,7 +294,7 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
217
294
  setLoading(true);
218
295
  _context.p = 8;
219
296
  _context.n = 9;
220
- return new _HttpService["default"](requestUrl, serviceConfig).post("decrypt", {
297
+ return new _HttpService["default"](requestContextPath, serviceConfig).post("decrypt", {
221
298
  data: secret
222
299
  });
223
300
  case 9:
@@ -247,11 +324,10 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
247
324
  }
248
325
  return _context.a(2);
249
326
  case 13:
250
- if (_t && _t.responseJSON && _t.responseJSON.msg) {
251
- _antd.message.error(_t.responseJSON.msg);
252
- } else {
253
- _antd.message.error("解密失败");
254
- }
327
+ resetReveal();
328
+ setToggle(false);
329
+ setToggleVal(maskValue(secret, resolvedMaskLength));
330
+ _antd.message.error(getErrorMessage(_t));
255
331
  case 14:
256
332
  _context.p = 14;
257
333
  if (requestSeq === requestSeqRef.current) {
@@ -271,26 +347,25 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
271
347
  if (onKeyDown) {
272
348
  onKeyDown(event);
273
349
  }
274
- if (toggle || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
350
+ if (disabled || toggle || composingRef.current || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
275
351
  return;
276
352
  }
277
353
  if (event.key === "Backspace" || event.key === "Delete") {
278
354
  event.preventDefault();
279
- commitValue("", false);
355
+ commitValue(editingRef.current ? realValueRef.current.slice(0, -1) : "", false);
280
356
  return;
281
357
  }
282
358
  if (event.key.length !== 1) {
283
359
  return;
284
360
  }
285
361
  event.preventDefault();
286
- var nextValue = editingRef.current ? realValueRef.current + event.key : event.key;
287
- commitValue(nextValue, false);
362
+ commitValue(editingRef.current ? realValueRef.current + event.key : event.key, true);
288
363
  };
289
364
  var onModifyPaste = function onModifyPaste(event) {
290
365
  if (onPaste) {
291
366
  onPaste(event);
292
367
  }
293
- if (toggle || event.defaultPrevented) {
368
+ if (disabled || toggle || composingRef.current || event.defaultPrevented) {
294
369
  return;
295
370
  }
296
371
  var text = event.clipboardData ? event.clipboardData.getData("text") : "";
@@ -298,48 +373,98 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
298
373
  if (!text) {
299
374
  return;
300
375
  }
301
- var nextValue = editingRef.current ? realValueRef.current + text : text;
302
- commitValue(nextValue, false);
376
+ commitValue(editingRef.current ? realValueRef.current + text : text, false);
303
377
  };
304
- var onModifyChange = function onModifyChange(event) {
305
- var nextValue = event.target.value;
306
- if (!toggle) {
307
- if (nextValue === "") {
308
- commitValue("", false);
309
- }
378
+ var onCompositionStart = function onCompositionStart(event) {
379
+ clearRevealTimer();
380
+ var compositionDisplayValue = event && event.target ? event.target.value : typeof event === "string" ? event : "";
381
+ composingRef.current = true;
382
+ composeBaseDisplayRef.current = compositionDisplayValue;
383
+ setCompositionDisplay(compositionDisplayValue);
384
+ };
385
+ var onCompositionEnd = function onCompositionEnd(event) {
386
+ if (!composingRef.current) {
387
+ return;
388
+ }
389
+ composingRef.current = false;
390
+ if (disabled || toggle) {
391
+ return;
392
+ }
393
+ var domValue = event && event.target ? event.target.value : typeof event === "string" ? event : "";
394
+ var baseValue = composeBaseDisplayRef.current;
395
+ var composedText = baseValue && domValue.startsWith(baseValue) ? domValue.slice(baseValue.length) : domValue.replace(/^\*+/, "");
396
+ if (!composedText) {
397
+ setCompositionDisplay(null);
310
398
  return;
311
399
  }
312
- commitValue(nextValue, true);
400
+ commitValue(editingRef.current ? realValueRef.current + composedText : composedText, true);
401
+ };
402
+ var onModifyChange = function onModifyChange(valueOrEvent) {
403
+ var nextValue = valueOrEvent && valueOrEvent.target ? valueOrEvent.target.value : valueOrEvent;
404
+ if (composingRef.current && !toggle) {
405
+ setCompositionDisplay(nextValue);
406
+ return;
407
+ }
408
+ if (disabled || !toggle && nextValue !== "") {
409
+ return;
410
+ }
411
+ commitValue(nextValue, false);
412
+ };
413
+ var onToggleClick = function onToggleClick() {
414
+ Promise.resolve(onToggleFull())["catch"](function (error) {
415
+ _antd.message.error(getErrorMessage(error));
416
+ });
417
+ };
418
+ var renderToggleIcon = function renderToggleIcon() {
419
+ var extraStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
420
+ if (loading) {
421
+ return /*#__PURE__*/_react["default"].createElement(_icons.LoadingOutlined, {
422
+ spin: true,
423
+ style: {
424
+ color: PASSWORD_ICON_STYLE.color
425
+ }
426
+ });
427
+ }
428
+ return /*#__PURE__*/_react["default"].createElement("span", {
429
+ className: "iconfont ".concat(toggle ? "icon-bchr-show" : "icon-bchr-hide"),
430
+ style: _objectSpread(_objectSpread({}, PASSWORD_ICON_STYLE), extraStyle),
431
+ onClick: onToggleClick
432
+ });
313
433
  };
314
434
  if (ui_render_type === "modify") {
315
- var modifyDisplay = toggle ? toggleVal : maskValue(realValue, resolvedMaskLength);
435
+ var modifyDisplay;
436
+ if (compositionDisplay !== null) {
437
+ modifyDisplay = compositionDisplay;
438
+ } else if (toggle) {
439
+ modifyDisplay = editingRef.current ? realValue : toggleVal;
440
+ } else if (editingRef.current && realValue) {
441
+ var fullMask = "*".repeat(resolvedMaskLength);
442
+ modifyDisplay = revealIndex >= 0 ? fullMask.slice(0, -1) + realValue.charAt(realValue.length - 1) : fullMask;
443
+ } else {
444
+ modifyDisplay = maskValue(realValue, resolvedMaskLength);
445
+ }
316
446
  return /*#__PURE__*/_react["default"].createElement(_antd.Input, _extends({}, restInputProps, {
447
+ ref: inputRef,
448
+ className: className,
449
+ style: style,
317
450
  value: modifyDisplay,
318
451
  placeholder: placeholder,
452
+ disabled: disabled,
319
453
  allowClear: allowClear,
320
454
  maxLength: toggle && typeof maxLength === "number" ? maxLength : undefined,
321
455
  onChange: onModifyChange,
322
456
  onKeyDown: onModifyKeyDown,
323
457
  onPaste: onModifyPaste,
324
- addonAfter: /*#__PURE__*/_react["default"].createElement("span", {
325
- className: "iconfont ".concat(toggle ? "icon-bchr-show" : "icon-bchr-hide"),
326
- style: {
327
- cursor: "pointer"
328
- },
329
- onClick: onToggleFull
330
- })
458
+ onCompositionStart: onCompositionStart,
459
+ onCompositionEnd: onCompositionEnd,
460
+ suffix: renderToggleIcon()
331
461
  }));
332
- } else if (ui_render_type === "browse") {
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", {
334
- className: "iconfont ".concat(toggle ? "icon-bchr-show" : "icon-bchr-hide"),
335
- style: {
336
- cursor: "pointer",
337
- margin: "0 5px",
338
- color: "#337DB7",
339
- fontWeight: "bolder"
340
- },
341
- onClick: onToggleFull
342
- })));
343
462
  }
463
+ return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
464
+ className: className,
465
+ style: style
466
+ }, toggleVal, _utils.Values.isNotBlankString(incomingValue) && renderToggleIcon({
467
+ margin: "0 5px"
468
+ })));
344
469
  };
345
470
  var _default = exports["default"] = InputPasswordDecrypt;
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+ var ExcelJS = _interopRequireWildcard(require("exceljs"));
7
8
  var _fileSaver = require("file-saver");
8
9
  var _Values = _interopRequireDefault(require("./Values"));
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
+ 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); }
10
12
  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); }
11
13
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
12
14
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -18,11 +20,6 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
18
20
  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; }
19
21
  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; } }
20
22
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
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 _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); }
24
- 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); }
25
- 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); }); }; }
26
23
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
27
24
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
28
25
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -161,70 +158,50 @@ var ExcelKits = {
161
158
  this.exportTableData2ExcelFile(exportGridColumns, exportGridData, fileName);
162
159
  },
163
160
  exportTableData2ExcelFile: function exportTableData2ExcelFile() {
164
- var _arguments = arguments,
165
- _this2 = this;
166
- return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
167
- var _excelModule$default;
168
- var columns, data, fileName, excelModule, ExcelJS, workbook, worksheet, exportGridColumnsData, totalColumnHeaderRowCount, columnHeaderData, rowHeaderArray, columnHeaderMergeCellArray, exportGridData, headerRows, bodyRows;
169
- return _regenerator().w(function (_context) {
170
- while (1) switch (_context.n) {
171
- case 0:
172
- columns = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : [];
173
- data = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : [];
174
- fileName = _arguments.length > 2 ? _arguments[2] : undefined;
175
- if (_Values["default"].isBlankString(fileName)) {
176
- fileName = "".concat(t('ui.export.excel.file'), "-") + new Date().getTime();
177
- }
178
- _context.n = 1;
179
- return Promise.resolve().then(function () {
180
- return _interopRequireWildcard(require("exceljs/dist/exceljs.bare.min.js"));
181
- });
182
- case 1:
183
- excelModule = _context.v;
184
- ExcelJS = (_excelModule$default = excelModule["default"]) !== null && _excelModule$default !== void 0 ? _excelModule$default : excelModule;
185
- workbook = new ExcelJS.Workbook();
186
- worksheet = workbook.addWorksheet('sheet');
187
- exportGridColumnsData = _this2.gatherExcelColumnHeaderStructureInfo(_this2.extractColumns(columns));
188
- totalColumnHeaderRowCount = exportGridColumnsData.totalColumnHeaderRowCount;
189
- columnHeaderData = exportGridColumnsData.columnHeaderData;
190
- rowHeaderArray = exportGridColumnsData.rowHeaderArray;
191
- columnHeaderMergeCellArray = exportGridColumnsData.columnHeaderMergeCellArray;
192
- exportGridData = data;
193
- worksheet.columns = columnHeaderData;
194
- worksheet.spliceRows(1, 1);
195
- worksheet.insertRows(1, rowHeaderArray);
196
- exportGridData.forEach(function (gridItem) {
197
- worksheet.addRow(gridItem);
198
- });
199
- columnHeaderMergeCellArray.forEach(function (mergeCells) {
200
- worksheet.mergeCells(mergeCells);
201
- });
161
+ var columns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
162
+ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
163
+ var fileName = arguments.length > 2 ? arguments[2] : undefined;
164
+ if (_Values["default"].isBlankString(fileName)) {
165
+ fileName = "".concat(t('ui.export.excel.file'), "-") + new Date().getTime();
166
+ }
167
+ var workbook = new ExcelJS.Workbook();
168
+ var worksheet = workbook.addWorksheet('sheet');
169
+ var exportGridColumnsData = this.gatherExcelColumnHeaderStructureInfo(this.extractColumns(columns));
170
+ var totalColumnHeaderRowCount = exportGridColumnsData.totalColumnHeaderRowCount;
171
+ var columnHeaderData = exportGridColumnsData.columnHeaderData;
172
+ var rowHeaderArray = exportGridColumnsData.rowHeaderArray;
173
+ var columnHeaderMergeCellArray = exportGridColumnsData.columnHeaderMergeCellArray;
174
+ var exportGridData = data;
175
+ worksheet.columns = columnHeaderData;
176
+ worksheet.spliceRows(1, 1);
177
+ worksheet.insertRows(1, rowHeaderArray);
178
+ exportGridData.forEach(function (gridItem) {
179
+ worksheet.addRow(gridItem);
180
+ });
181
+ columnHeaderMergeCellArray.forEach(function (mergeCells) {
182
+ worksheet.mergeCells(mergeCells);
183
+ });
202
184
 
203
- // 设置表头样式
204
- headerRows = worksheet.getRows(1, totalColumnHeaderRowCount);
205
- headerRows.forEach(function (row, rowIndex) {
206
- row.eachCell(function (cell, cellIndex) {
207
- cell.style = excelHeaderRowStyle;
208
- });
209
- });
185
+ // 设置表头样式
186
+ var headerRows = worksheet.getRows(1, totalColumnHeaderRowCount);
187
+ headerRows.forEach(function (row, rowIndex) {
188
+ row.eachCell(function (cell, cellIndex) {
189
+ cell.style = excelHeaderRowStyle;
190
+ });
191
+ });
210
192
 
211
- // 设置表体样式
212
- bodyRows = worksheet.getRows(totalColumnHeaderRowCount + 1, totalColumnHeaderRowCount + exportGridData.length + 5);
213
- bodyRows.forEach(function (row) {
214
- row.eachCell(function (cell, cellIndex) {
215
- cell.style = excelBodyRowStyle;
216
- });
217
- });
218
- workbook.xlsx.writeBuffer().then(function (buffer) {
219
- (0, _fileSaver.saveAs)(new Blob([buffer], {
220
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
221
- }), fileName + ".xlsx");
222
- });
223
- case 2:
224
- return _context.a(2);
225
- }
226
- }, _callee);
227
- }))();
193
+ // 设置表体样式
194
+ var bodyRows = worksheet.getRows(totalColumnHeaderRowCount + 1, totalColumnHeaderRowCount + exportGridData.length + 5);
195
+ bodyRows.forEach(function (row) {
196
+ row.eachCell(function (cell, cellIndex) {
197
+ cell.style = excelBodyRowStyle;
198
+ });
199
+ });
200
+ workbook.xlsx.writeBuffer().then(function (buffer) {
201
+ (0, _fileSaver.saveAs)(new Blob([buffer], {
202
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
203
+ }), fileName + ".xlsx");
204
+ });
228
205
  },
229
206
  extractColumns: function extractColumns(children, level) {
230
207
  var _this = this;
@@ -251,7 +228,7 @@ var ExcelKits = {
251
228
  * @returns {{totalColumnCount: {int}, totalColumnHeaderRowCount: {int}, columnHeaderArray: [] }}
252
229
  */
253
230
  gatherExcelColumnHeaderStructureInfo: function gatherExcelColumnHeaderStructureInfo(gridColumns) {
254
- var _this3 = this;
231
+ var _this2 = this;
255
232
  var _this$getTotalColumnC = this.getTotalColumnCountAndTotalColumnHeaderRowCount(gridColumns, 0, 1),
256
233
  _this$getTotalColumnC2 = _slicedToArray(_this$getTotalColumnC, 2),
257
234
  totalColumnCount = _this$getTotalColumnC2[0],
@@ -289,7 +266,7 @@ var ExcelKits = {
289
266
  var columnIndex = 0;
290
267
  var _addColumns = function addColumns(columns, result) {
291
268
  columns.forEach(function (column) {
292
- var exporterColumn = _this3.$normalizedExportColumn(column);
269
+ var exporterColumn = _this2.$normalizedExportColumn(column);
293
270
  result.push(exporterColumn);
294
271
  if (column.children && column.children.length > 1) {
295
272
  var children = exporterColumn.columns = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bchr/bchr-front-lib",
3
- "version": "0.6.9",
3
+ "version": "0.6.10",
4
4
  "description": "bchr front lib",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,9 +1,16 @@
1
- import React, {Fragment, useEffect, useRef, useState} from "react";
1
+ import React, {Fragment, useCallback, useEffect, useRef, useState} from "react";
2
2
  import {Input, message} from "antd";
3
+ import {LoadingOutlined} from "@ant-design/icons";
3
4
  import HttpService from "../../../services/HttpService";
4
5
  import {Values} from "../../utils";
5
6
 
6
- const MASK_LENGTH = 8;
7
+ const DEFAULT_MASK_LENGTH = 8;
8
+ const DEFAULT_VISIBLE_DURATION = 5000;
9
+ const PASSWORD_ICON_STYLE = {
10
+ cursor: "pointer",
11
+ color: "#337DB7",
12
+ fontWeight: "bolder"
13
+ };
7
14
 
8
15
  const normalizeValue = (value) => {
9
16
  if (value === null || value === undefined) {
@@ -26,136 +33,198 @@ const limitText = (text, maxLength) => {
26
33
  return text;
27
34
  };
28
35
 
36
+ const getErrorMessage = (error) => {
37
+ return (error && error.responseJSON && error.responseJSON.msg) || (error && error.message) || "解密失败";
38
+ };
39
+
29
40
  const InputPasswordDecrypt = (props) => {
30
- let {
41
+ const {
31
42
  ui_render_type,
32
43
  initValue,
33
44
  value,
34
45
  onChange,
35
46
  requestUrl,
36
- appconfig,
37
- appConfig,
47
+ appconfig: serviceAppconfig,
48
+ appConfig: serviceAppConfig,
38
49
  maskLength,
39
50
  placeholder,
40
51
  maxLength,
52
+ onChangeValueType = "event",
41
53
  allowClear = true,
54
+ disabled,
55
+ className,
56
+ style,
42
57
  onKeyDown,
43
58
  onPaste,
44
59
  ...restInputProps
45
60
  } = props;
46
- const resolvedMaskLength = Number.isInteger(maskLength) && maskLength > 0 ? maskLength : MASK_LENGTH;
47
- const serviceConfig = appconfig || appConfig;
61
+ const resolvedMaskLength = Values.isInteger(maskLength) && maskLength > 0 ? maskLength : DEFAULT_MASK_LENGTH;
62
+ const serviceConfig = serviceAppconfig || serviceAppConfig;
63
+ const requestContextPath = Values.isNotBlankString(requestUrl)
64
+ ? requestUrl
65
+ : (Values.isNotBlankString(serviceConfig)
66
+ ? serviceConfig
67
+ : (serviceConfig && (serviceConfig.requestContextPath || serviceConfig.requestUrl)) || "");
48
68
  const incomingValue = normalizeValue(value !== undefined ? value : initValue);
49
69
  const [realValue, setRealValue] = useState(incomingValue);
50
70
  const [toggle, setToggle] = useState(false);
51
- const [toggleVal, setToggleVal] = useState(maskValue(initValue, resolvedMaskLength));
71
+ const [toggleVal, setToggleVal] = useState(maskValue(incomingValue, resolvedMaskLength));
72
+ const [revealIndex, setRevealIndex] = useState(-1);
73
+ const [compositionDisplay, setCompositionDisplay] = useState(null);
52
74
  const [loading, setLoading] = useState(false);
53
- const timerRef = useRef(null);
75
+ const hideTimerRef = useRef(null);
76
+ const revealTimerRef = useRef(null);
54
77
  const requestSeqRef = useRef(0);
55
78
  const realValueRef = useRef(incomingValue);
56
- const originalRef = useRef(incomingValue);
57
79
  const emittedRef = useRef(incomingValue);
58
80
  const editingRef = useRef(false);
59
81
  const maskLengthRef = useRef(resolvedMaskLength);
82
+ const composingRef = useRef(false);
83
+ const composeBaseDisplayRef = useRef("");
84
+ const inputRef = useRef(null);
60
85
 
61
- realValueRef.current = ui_render_type === "modify" ? realValue : normalizeValue(initValue);
86
+ realValueRef.current = ui_render_type === "modify" ? realValue : incomingValue;
62
87
  maskLengthRef.current = resolvedMaskLength;
63
88
 
64
- const clearHideTimer = () => {
65
- if (timerRef.current) {
66
- clearTimeout(timerRef.current);
67
- timerRef.current = null;
89
+ const clearHideTimer = useCallback(() => {
90
+ if (hideTimerRef.current) {
91
+ clearTimeout(hideTimerRef.current);
92
+ hideTimerRef.current = null;
93
+ }
94
+ }, []);
95
+
96
+ const clearRevealTimer = useCallback(() => {
97
+ if (revealTimerRef.current) {
98
+ clearTimeout(revealTimerRef.current);
99
+ revealTimerRef.current = null;
100
+ }
101
+ }, []);
102
+
103
+ const resetReveal = useCallback(() => {
104
+ clearRevealTimer();
105
+ setRevealIndex(-1);
106
+ }, [clearRevealTimer]);
107
+
108
+ const flashLastChar = (nextValue) => {
109
+ clearRevealTimer();
110
+ if (!nextValue) {
111
+ setRevealIndex(-1);
112
+ return;
68
113
  }
114
+ setRevealIndex(nextValue.length - 1);
115
+ revealTimerRef.current = setTimeout(() => {
116
+ revealTimerRef.current = null;
117
+ setRevealIndex(-1);
118
+ }, 500);
69
119
  };
70
120
 
71
121
  const hidePlainText = () => {
72
122
  clearHideTimer();
123
+ resetReveal();
73
124
  setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
74
125
  setToggle(false);
75
126
  };
76
127
 
77
- const showPlainText = (plainText) => {
128
+ const showPlainText = (plainText, autoHide = true) => {
78
129
  clearHideTimer();
130
+ resetReveal();
79
131
  setToggleVal(plainText);
80
132
  setToggle(true);
81
- timerRef.current = setTimeout(() => {
82
- timerRef.current = null;
83
- setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
84
- setToggle(false);
85
- }, 5000);
133
+ if (autoHide) {
134
+ hideTimerRef.current = setTimeout(() => {
135
+ hideTimerRef.current = null;
136
+ setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
137
+ setToggle(false);
138
+ }, DEFAULT_VISIBLE_DURATION);
139
+ }
86
140
  };
87
141
 
88
- useEffect(() => {
89
- return () => {
90
- requestSeqRef.current += 1;
91
- clearHideTimer();
92
- };
93
- }, []);
142
+ useEffect(() => () => {
143
+ requestSeqRef.current += 1;
144
+ clearHideTimer();
145
+ clearRevealTimer();
146
+ }, [clearHideTimer, clearRevealTimer]);
94
147
 
95
148
  useEffect(() => {
96
149
  if (ui_render_type === "modify") {
97
150
  return undefined;
98
151
  }
152
+ requestSeqRef.current += 1;
153
+ clearHideTimer();
154
+ resetReveal();
155
+ setCompositionDisplay(null);
99
156
  setToggle(false);
100
- setToggleVal(maskValue(initValue, resolvedMaskLength));
157
+ setToggleVal(maskValue(incomingValue, resolvedMaskLength));
101
158
  setLoading(false);
102
- return () => {
103
- requestSeqRef.current += 1;
104
- clearHideTimer();
105
- };
106
- }, [ui_render_type, initValue, resolvedMaskLength]);
159
+ return clearHideTimer;
160
+ }, [clearHideTimer, resetReveal, ui_render_type, incomingValue, resolvedMaskLength]);
107
161
 
108
162
  useEffect(() => {
109
163
  if (ui_render_type !== "modify" || incomingValue === emittedRef.current) {
110
164
  return undefined;
111
165
  }
112
166
  emittedRef.current = incomingValue;
113
- originalRef.current = incomingValue;
114
167
  editingRef.current = false;
115
168
  realValueRef.current = incomingValue;
116
169
  setRealValue(incomingValue);
117
170
  requestSeqRef.current += 1;
118
171
  clearHideTimer();
172
+ resetReveal();
119
173
  setToggle(false);
120
174
  setToggleVal(maskValue(incomingValue, resolvedMaskLength));
121
175
  setLoading(false);
122
- }, [ui_render_type, incomingValue, resolvedMaskLength]);
176
+ return undefined;
177
+ }, [clearHideTimer, resetReveal, ui_render_type, incomingValue, resolvedMaskLength]);
123
178
 
124
- const commitValue = (nextValue, reveal) => {
179
+ const emitChange = (nextValue) => {
180
+ if (onChange) {
181
+ onChange(onChangeValueType === "value" ? nextValue : {target: {value: nextValue}});
182
+ }
183
+ };
184
+
185
+ const commitValue = (nextValue, flash) => {
125
186
  const normalized = limitText(normalizeValue(nextValue), maxLength);
126
187
  emittedRef.current = normalized;
127
188
  editingRef.current = true;
128
189
  realValueRef.current = normalized;
190
+ setCompositionDisplay(null);
129
191
  setRealValue(normalized);
130
- if (reveal) {
131
- showPlainText(normalized);
132
- }
133
- if (onChange) {
134
- onChange({target: {value: normalized}});
192
+ if (flash) {
193
+ flashLastChar(normalized);
194
+ } else {
195
+ resetReveal();
135
196
  }
197
+ emitChange(normalized);
136
198
  };
137
199
 
138
200
  const onToggleFull = async () => {
139
- if (toggle) {
140
- hidePlainText();
141
- return;
142
- }
143
201
  if (loading) {
144
202
  return;
145
203
  }
146
204
 
205
+ if (toggle) {
206
+ hidePlainText();
207
+ return;
208
+ }
209
+ resetReveal();
147
210
  const secret = realValueRef.current;
148
- if (ui_render_type === "modify" && (secret === "" || editingRef.current || secret !== originalRef.current)) {
149
- if (secret === "") {
211
+ if (ui_render_type === "modify") {
212
+ if (!secret) {
213
+ commitValue("", false);
214
+ if (inputRef.current && inputRef.current.focus) {
215
+ inputRef.current.focus();
216
+ }
217
+ return;
218
+ }
219
+ if (editingRef.current) {
220
+ showPlainText(secret);
150
221
  return;
151
222
  }
152
- showPlainText(secret);
153
- return;
154
223
  }
155
224
  if (!secret) {
156
225
  return;
157
226
  }
158
- if (!requestUrl) {
227
+ if (!requestContextPath) {
159
228
  message.error("请为组件注入属性【requestUrl】");
160
229
  return;
161
230
  }
@@ -168,7 +237,7 @@ const InputPasswordDecrypt = (props) => {
168
237
  requestSeqRef.current = requestSeq;
169
238
  setLoading(true);
170
239
  try {
171
- const result = await new HttpService(requestUrl, serviceConfig).post("decrypt", {data: secret});
240
+ const result = await new HttpService(requestContextPath, serviceConfig).post("decrypt", {data: secret});
172
241
  if (requestSeq !== requestSeqRef.current) {
173
242
  return;
174
243
  }
@@ -181,11 +250,10 @@ const InputPasswordDecrypt = (props) => {
181
250
  if (requestSeq !== requestSeqRef.current) {
182
251
  return;
183
252
  }
184
- if (error && error.responseJSON && error.responseJSON.msg) {
185
- message.error(error.responseJSON.msg);
186
- } else {
187
- message.error("解密失败");
188
- }
253
+ resetReveal();
254
+ setToggle(false);
255
+ setToggleVal(maskValue(secret, resolvedMaskLength));
256
+ message.error(getErrorMessage(error));
189
257
  } finally {
190
258
  if (requestSeq === requestSeqRef.current) {
191
259
  setLoading(false);
@@ -197,27 +265,26 @@ const InputPasswordDecrypt = (props) => {
197
265
  if (onKeyDown) {
198
266
  onKeyDown(event);
199
267
  }
200
- if (toggle || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
268
+ if (disabled || toggle || composingRef.current || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
201
269
  return;
202
270
  }
203
271
  if (event.key === "Backspace" || event.key === "Delete") {
204
272
  event.preventDefault();
205
- commitValue("", false);
273
+ commitValue(editingRef.current ? realValueRef.current.slice(0, -1) : "", false);
206
274
  return;
207
275
  }
208
276
  if (event.key.length !== 1) {
209
277
  return;
210
278
  }
211
279
  event.preventDefault();
212
- const nextValue = editingRef.current ? realValueRef.current + event.key : event.key;
213
- commitValue(nextValue, false);
280
+ commitValue(editingRef.current ? realValueRef.current + event.key : event.key, true);
214
281
  };
215
282
 
216
283
  const onModifyPaste = (event) => {
217
284
  if (onPaste) {
218
285
  onPaste(event);
219
286
  }
220
- if (toggle || event.defaultPrevented) {
287
+ if (disabled || toggle || composingRef.current || event.defaultPrevented) {
221
288
  return;
222
289
  }
223
290
  const text = event.clipboardData ? event.clipboardData.getData("text") : "";
@@ -225,44 +292,110 @@ const InputPasswordDecrypt = (props) => {
225
292
  if (!text) {
226
293
  return;
227
294
  }
228
- const nextValue = editingRef.current ? realValueRef.current + text : text;
229
- commitValue(nextValue, false);
295
+ commitValue(editingRef.current ? realValueRef.current + text : text, false);
230
296
  };
231
297
 
232
- const onModifyChange = (event) => {
233
- const nextValue = event.target.value;
234
- if (!toggle) {
235
- if (nextValue === "") {
236
- commitValue("", false);
237
- }
298
+ const onCompositionStart = (event) => {
299
+ clearRevealTimer();
300
+ const compositionDisplayValue = event && event.target ? event.target.value : (typeof event === "string" ? event : "");
301
+ composingRef.current = true;
302
+ composeBaseDisplayRef.current = compositionDisplayValue;
303
+ setCompositionDisplay(compositionDisplayValue);
304
+ };
305
+
306
+ const onCompositionEnd = (event) => {
307
+ if (!composingRef.current) {
238
308
  return;
239
309
  }
240
- commitValue(nextValue, true);
310
+ composingRef.current = false;
311
+ if (disabled || toggle) {
312
+ return;
313
+ }
314
+ const domValue = event && event.target ? event.target.value : (typeof event === "string" ? event : "");
315
+ const baseValue = composeBaseDisplayRef.current;
316
+ const composedText = baseValue && domValue.startsWith(baseValue)
317
+ ? domValue.slice(baseValue.length)
318
+ : domValue.replace(/^\*+/, "");
319
+ if (!composedText) {
320
+ setCompositionDisplay(null);
321
+ return;
322
+ }
323
+ commitValue(editingRef.current ? realValueRef.current + composedText : composedText, true);
324
+ };
325
+
326
+ const onModifyChange = (valueOrEvent) => {
327
+ const nextValue = valueOrEvent && valueOrEvent.target ? valueOrEvent.target.value : valueOrEvent;
328
+ if (composingRef.current && !toggle) {
329
+ setCompositionDisplay(nextValue);
330
+ return;
331
+ }
332
+ if (disabled || (!toggle && nextValue !== "")) {
333
+ return;
334
+ }
335
+ commitValue(nextValue, false);
336
+ };
337
+
338
+ const onToggleClick = () => {
339
+ Promise.resolve(onToggleFull()).catch((error) => {
340
+ message.error(getErrorMessage(error));
341
+ });
342
+ };
343
+
344
+ const renderToggleIcon = (extraStyle = {}) => {
345
+ if (loading) {
346
+ return <LoadingOutlined spin style={{color: PASSWORD_ICON_STYLE.color}}/>;
347
+ }
348
+ return (
349
+ <span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`}
350
+ style={{...PASSWORD_ICON_STYLE, ...extraStyle}}
351
+ onClick={onToggleClick}/>
352
+ );
241
353
  };
242
354
 
243
355
  if (ui_render_type === "modify") {
244
- const modifyDisplay = toggle ? toggleVal : maskValue(realValue, resolvedMaskLength);
245
- return <Input
246
- {...restInputProps}
247
- value={modifyDisplay}
248
- placeholder={placeholder}
249
- allowClear={allowClear}
250
- maxLength={toggle && typeof maxLength === "number" ? maxLength : undefined}
251
- onChange={onModifyChange}
252
- onKeyDown={onModifyKeyDown}
253
- onPaste={onModifyPaste}
254
- addonAfter={<span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`} style={{cursor: "pointer"}} onClick={onToggleFull}/>}
255
- />;
256
- } else if (ui_render_type === "browse") {
257
- return <Fragment>
258
- <span>
356
+ let modifyDisplay;
357
+ if (compositionDisplay !== null) {
358
+ modifyDisplay = compositionDisplay;
359
+ } else if (toggle) {
360
+ modifyDisplay = editingRef.current ? realValue : toggleVal;
361
+ } else if (editingRef.current && realValue) {
362
+ const fullMask = "*".repeat(resolvedMaskLength);
363
+ modifyDisplay = revealIndex >= 0
364
+ ? fullMask.slice(0, -1) + realValue.charAt(realValue.length - 1)
365
+ : fullMask;
366
+ } else {
367
+ modifyDisplay = maskValue(realValue, resolvedMaskLength);
368
+ }
369
+
370
+ return (
371
+ <Input
372
+ {...restInputProps}
373
+ ref={inputRef}
374
+ className={className}
375
+ style={style}
376
+ value={modifyDisplay}
377
+ placeholder={placeholder}
378
+ disabled={disabled}
379
+ allowClear={allowClear}
380
+ maxLength={toggle && typeof maxLength === "number" ? maxLength : undefined}
381
+ onChange={onModifyChange}
382
+ onKeyDown={onModifyKeyDown}
383
+ onPaste={onModifyPaste}
384
+ onCompositionStart={onCompositionStart}
385
+ onCompositionEnd={onCompositionEnd}
386
+ suffix={renderToggleIcon()}
387
+ />
388
+ );
389
+ }
390
+
391
+ return (
392
+ <Fragment>
393
+ <span className={className} style={style}>
259
394
  {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
- )}
395
+ {Values.isNotBlankString(incomingValue) && renderToggleIcon({margin: "0 5px"})}
263
396
  </span>
264
- </Fragment>;
265
- }
397
+ </Fragment>
398
+ );
266
399
  };
267
400
 
268
401
  export default InputPasswordDecrypt;
@@ -1,3 +1,4 @@
1
+ import * as ExcelJS from "exceljs";
1
2
  import {saveAs} from "file-saver";
2
3
  import Values from "./Values";
3
4
 
@@ -109,14 +110,12 @@ const ExcelKits = {
109
110
  this.exportTableData2ExcelFile(exportGridColumns, exportGridData, fileName);
110
111
  },
111
112
 
112
- async exportTableData2ExcelFile(columns = [], data = [], fileName) {
113
+ exportTableData2ExcelFile(columns = [], data = [], fileName) {
113
114
 
114
115
  if (Values.isBlankString(fileName)) {
115
116
  fileName = `${t('ui.export.excel.file')}-` + new Date().getTime();
116
117
  }
117
118
 
118
- const excelModule = await import("exceljs/dist/exceljs.bare.min.js");
119
- const ExcelJS = excelModule.default ?? excelModule;
120
119
  const workbook = new ExcelJS.Workbook();
121
120
  const worksheet = workbook.addWorksheet('sheet');
122
121