@bchr/bchr-front-lib 0.6.2 → 0.6.3

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,6 +7,7 @@ exports.UI_RENDER_TYPE = exports.EXPORT_GRID_HEADER_CELL_OPTIONS = exports.EXPOR
7
7
  var UI_RENDER_TYPE = exports.UI_RENDER_TYPE = {
8
8
  INPUT: "input",
9
9
  INPUT_PASSWORD: "inputPassword",
10
+ INPUT_PASSWORD_DECRYPT: "inputPasswordDecrypt",
10
11
  INPUT_NUMBER: "inputNumber",
11
12
  TEXT_AREA: "textArea",
12
13
  DATE: "date",
@@ -10,6 +10,7 @@ var _antd = require("antd");
10
10
  var _icons = require("@ant-design/icons");
11
11
  var _moment = _interopRequireDefault(require("moment"));
12
12
  var _consts = require("../consts");
13
+ var _InputPassword = _interopRequireDefault(require("../InputPassword"));
13
14
  var _InputPasswordDecrypt = _interopRequireDefault(require("../InputPasswordDecrypt"));
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
16
  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); }
@@ -289,6 +290,7 @@ var FormForBrowse = /*#__PURE__*/function (_React$Component) {
289
290
  case _consts.UI_RENDER_TYPE.INPUT:
290
291
  case _consts.UI_RENDER_TYPE.INPUT_NUMBER:
291
292
  case _consts.UI_RENDER_TYPE.INPUT_PASSWORD:
293
+ case _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
292
294
  case _consts.UI_RENDER_TYPE.TEXT_AREA:
293
295
  case _consts.UI_RENDER_TYPE.SELECT:
294
296
  case _consts.UI_RENDER_TYPE.TREE_SELECT:
@@ -320,6 +322,12 @@ var FormForBrowse = /*#__PURE__*/function (_React$Component) {
320
322
  }
321
323
  components = /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("span", null, value));
322
324
  if (ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD) {
325
+ components = /*#__PURE__*/_react["default"].createElement("div", null, initialValues[code] && /*#__PURE__*/_react["default"].createElement(_InputPassword["default"], {
326
+ ui_render_type: 'browse',
327
+ initValue: initialValues[code]
328
+ }));
329
+ }
330
+ if (ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
323
331
  components = /*#__PURE__*/_react["default"].createElement("div", null, initialValues[code] && /*#__PURE__*/_react["default"].createElement(_InputPasswordDecrypt["default"], {
324
332
  ui_render_type: 'browse',
325
333
  initValue: initialValues[code],
@@ -11,6 +11,7 @@ var _moment = _interopRequireDefault(require("moment"));
11
11
  var _consts = require("../consts");
12
12
  var _zh_CN = _interopRequireDefault(require("antd/es/locale/zh_CN"));
13
13
  var _HttpService = _interopRequireDefault(require("../../../../services/HttpService"));
14
+ var _InputPassword = _interopRequireDefault(require("../InputPassword"));
14
15
  var _InputPasswordDecrypt = _interopRequireDefault(require("../InputPasswordDecrypt"));
15
16
  require("../../../AppFormulaFunctions");
16
17
  var _BaseAppUtils = require("../../../BaseAppUtils");
@@ -330,6 +331,18 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
330
331
  }, ext_props));
331
332
  break;
332
333
  case _consts.UI_RENDER_TYPE.INPUT_PASSWORD:
334
+ component = b_readonly || _this2.disabledExpression(dataItem, data) ? /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_InputPassword["default"], {
335
+ ui_render_type: 'browse',
336
+ initValue: displayValue
337
+ })) : /*#__PURE__*/_react["default"].createElement(_antd.Input, _extends({
338
+ key: form_id + "_" + code,
339
+ placeholder: "请填写" + name,
340
+ allowClear: true,
341
+ maxLength: field_length && field_length > 0 ? field_length : null,
342
+ onChange: _this2.inputOnChange.bind(_this2, dataItem, onChange)
343
+ }, ext_props));
344
+ break;
345
+ case _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
333
346
  component = b_readonly || _this2.disabledExpression(dataItem, data) ? /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_InputPasswordDecrypt["default"], {
334
347
  ui_render_type: 'browse',
335
348
  initValue: displayValue,
@@ -848,7 +861,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
848
861
  return Promise.resolve();
849
862
  } else if (ui_render_type === _consts.UI_RENDER_TYPE.INPUT_NUMBER) {
850
863
  return value != null ? Promise.resolve() : Promise.reject("validate fail");
851
- } else if (ui_render_type === _consts.UI_RENDER_TYPE.INPUT || ui_render_type === _consts.UI_RENDER_TYPE.TEXT_AREA || ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD) {
864
+ } else if (ui_render_type === _consts.UI_RENDER_TYPE.INPUT || ui_render_type === _consts.UI_RENDER_TYPE.TEXT_AREA || ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD || ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
852
865
  if (!value) {
853
866
  return Promise.reject("validate fail");
854
867
  } else {
@@ -1222,6 +1235,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1222
1235
  case _consts.UI_RENDER_TYPE.INPUT:
1223
1236
  case _consts.UI_RENDER_TYPE.INPUT_NUMBER:
1224
1237
  case _consts.UI_RENDER_TYPE.INPUT_PASSWORD:
1238
+ case _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
1225
1239
  case _consts.UI_RENDER_TYPE.TEXT_AREA:
1226
1240
  case _consts.UI_RENDER_TYPE.TREE_SELECT:
1227
1241
  value = formItemValue;
@@ -14,6 +14,7 @@ var _consts = require("../consts");
14
14
  var _GridFilterRowIndicator = _interopRequireDefault(require("./GridFilterRowIndicator"));
15
15
  var _zh_CN = _interopRequireDefault(require("antd/es/locale/zh_CN"));
16
16
  var _GridColumnCustomToolBar = _interopRequireDefault(require("./GridColumnCustomToolBar"));
17
+ var _InputPassword = _interopRequireDefault(require("../InputPassword"));
17
18
  var _InputPasswordDecrypt = _interopRequireDefault(require("../InputPasswordDecrypt"));
18
19
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
19
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 _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); }
@@ -202,6 +203,7 @@ var GridForBrowse = /*#__PURE__*/function (_React$Component) {
202
203
  switch (ui_render_type) {
203
204
  case _consts.UI_RENDER_TYPE.INPUT:
204
205
  case _consts.UI_RENDER_TYPE.INPUT_PASSWORD:
206
+ case _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
205
207
  case _consts.UI_RENDER_TYPE.SELECT:
206
208
  case _consts.UI_RENDER_TYPE.TREE_SELECT:
207
209
  case _consts.UI_RENDER_TYPE.UPLOAD:
@@ -527,6 +529,7 @@ var GridForBrowse = /*#__PURE__*/function (_React$Component) {
527
529
  switch (ui_render_type) {
528
530
  case _consts.UI_RENDER_TYPE.INPUT:
529
531
  case _consts.UI_RENDER_TYPE.INPUT_PASSWORD:
532
+ case _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
530
533
  case _consts.UI_RENDER_TYPE.INPUT_NUMBER:
531
534
  case _consts.UI_RENDER_TYPE.SELECT:
532
535
  case _consts.UI_RENDER_TYPE.TREE_SELECT:
@@ -567,7 +570,7 @@ var GridForBrowse = /*#__PURE__*/function (_React$Component) {
567
570
  className: "form-item-control-input-ext-icon",
568
571
  onClick: this.downloadOnClick.bind(this, dataItem[code])
569
572
  }) : null, value);
570
- } else if (ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD) {
573
+ } else if (ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD || ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
571
574
  return /*#__PURE__*/_react["default"].createElement("td", {
572
575
  className: props.className,
573
576
  style: grid_default_locked ? {
@@ -584,7 +587,10 @@ var GridForBrowse = /*#__PURE__*/function (_React$Component) {
584
587
  dangerouslySetInnerHTML: {
585
588
  __html: column_value_prefix
586
589
  }
587
- }), dataItem[code] ? /*#__PURE__*/_react["default"].createElement(_InputPasswordDecrypt["default"], {
590
+ }), dataItem[code] ? ui_render_type === _consts.UI_RENDER_TYPE.INPUT_PASSWORD ? /*#__PURE__*/_react["default"].createElement(_InputPassword["default"], {
591
+ ui_render_type: 'browse',
592
+ initValue: dataItem[code]
593
+ }) : /*#__PURE__*/_react["default"].createElement(_InputPasswordDecrypt["default"], {
588
594
  ui_render_type: 'browse',
589
595
  initValue: dataItem[code],
590
596
  maskLength: this.props.maskLength,
@@ -286,6 +286,15 @@ var GridForModify = /*#__PURE__*/function (_React$Component) {
286
286
  }));
287
287
  break;
288
288
  case _consts.UI_RENDER_TYPE.INPUT_PASSWORD:
289
+ component = /*#__PURE__*/_react["default"].createElement(_antd.Input, {
290
+ title: dataItem[code],
291
+ placeholder: "请填写" + name,
292
+ defaultValue: dataItem[code],
293
+ allowClear: true,
294
+ onChange: this.inputOnChange.bind(this, dataItem, fieldConfig, onChange)
295
+ });
296
+ break;
297
+ case _consts.UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
289
298
  component = /*#__PURE__*/_react["default"].createElement(_InputPasswordDecrypt["default"], {
290
299
  ui_render_type: 'modify',
291
300
  initValue: dataItem[code],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bchr/bchr-front-lib",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "bchr front lib",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,262 +1,262 @@
1
- import React, {Fragment, useEffect, useRef, useState} from "react";
2
- import {Input, message} from "antd";
3
- import HttpService from "../../../services/HttpService";
4
-
5
- const MASK_LENGTH = 8;
6
-
7
- const normalizeValue = (value) => {
8
- if (value === null || value === undefined) {
9
- return "";
10
- }
11
- return String(value);
12
- };
13
-
14
- const maskValue = (value, maskLength) => {
15
- if (value === null || value === undefined || value === "") {
16
- return "";
17
- }
18
- return "*".repeat(maskLength);
19
- };
20
-
21
- const limitText = (text, maxLength) => {
22
- if (typeof maxLength === "number" && maxLength > 0 && text.length > maxLength) {
23
- return text.slice(0, maxLength);
24
- }
25
- return text;
26
- };
27
-
28
- const InputPasswordDecrypt = (props) => {
29
- let {
30
- ui_render_type,
31
- initValue,
32
- value,
33
- onChange,
34
- requestUrl,
35
- appconfig,
36
- appConfig,
37
- maskLength,
38
- placeholder,
39
- maxLength,
40
- allowClear = true,
41
- onKeyDown,
42
- onPaste,
43
- ...restInputProps
44
- } = props;
45
- const resolvedMaskLength = Number.isInteger(maskLength) && maskLength > 0 ? maskLength : MASK_LENGTH;
46
- const serviceConfig = appconfig || appConfig;
47
- const incomingValue = normalizeValue(value !== undefined ? value : initValue);
48
- const [realValue, setRealValue] = useState(incomingValue);
49
- const [toggle, setToggle] = useState(false);
50
- const [toggleVal, setToggleVal] = useState(maskValue(initValue, resolvedMaskLength));
51
- const [loading, setLoading] = useState(false);
52
- const timerRef = useRef(null);
53
- const requestSeqRef = useRef(0);
54
- const realValueRef = useRef(incomingValue);
55
- const originalRef = useRef(incomingValue);
56
- const emittedRef = useRef(incomingValue);
57
- const editingRef = useRef(false);
58
- const maskLengthRef = useRef(resolvedMaskLength);
59
-
60
- realValueRef.current = ui_render_type === "modify" ? realValue : normalizeValue(initValue);
61
- maskLengthRef.current = resolvedMaskLength;
62
-
63
- const clearHideTimer = () => {
64
- if (timerRef.current) {
65
- clearTimeout(timerRef.current);
66
- timerRef.current = null;
67
- }
68
- };
69
-
70
- const hidePlainText = () => {
71
- clearHideTimer();
72
- setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
73
- setToggle(false);
74
- };
75
-
76
- const showPlainText = (plainText) => {
77
- clearHideTimer();
78
- setToggleVal(plainText);
79
- setToggle(true);
80
- timerRef.current = setTimeout(() => {
81
- timerRef.current = null;
82
- setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
83
- setToggle(false);
84
- }, 5000);
85
- };
86
-
87
- useEffect(() => {
88
- return () => {
89
- requestSeqRef.current += 1;
90
- clearHideTimer();
91
- };
92
- }, []);
93
-
94
- useEffect(() => {
95
- if (ui_render_type === "modify") {
96
- return undefined;
97
- }
98
- setToggle(false);
99
- setToggleVal(maskValue(initValue, resolvedMaskLength));
100
- setLoading(false);
101
- return () => {
102
- requestSeqRef.current += 1;
103
- clearHideTimer();
104
- };
105
- }, [ui_render_type, initValue, resolvedMaskLength]);
106
-
107
- useEffect(() => {
108
- if (ui_render_type !== "modify" || incomingValue === emittedRef.current) {
109
- return undefined;
110
- }
111
- emittedRef.current = incomingValue;
112
- originalRef.current = incomingValue;
113
- editingRef.current = false;
114
- realValueRef.current = incomingValue;
115
- setRealValue(incomingValue);
116
- requestSeqRef.current += 1;
117
- clearHideTimer();
118
- setToggle(false);
119
- setToggleVal(maskValue(incomingValue, resolvedMaskLength));
120
- setLoading(false);
121
- }, [ui_render_type, incomingValue, resolvedMaskLength]);
122
-
123
- const commitValue = (nextValue, reveal) => {
124
- const normalized = limitText(normalizeValue(nextValue), maxLength);
125
- emittedRef.current = normalized;
126
- editingRef.current = true;
127
- realValueRef.current = normalized;
128
- setRealValue(normalized);
129
- if (reveal) {
130
- showPlainText(normalized);
131
- }
132
- if (onChange) {
133
- onChange({target: {value: normalized}});
134
- }
135
- };
136
-
137
- const onToggleFull = async () => {
138
- if (toggle) {
139
- hidePlainText();
140
- return;
141
- }
142
- if (loading) {
143
- return;
144
- }
145
-
146
- const secret = realValueRef.current;
147
- if (ui_render_type === "modify" && (secret === "" || editingRef.current || secret !== originalRef.current)) {
148
- if (secret === "") {
149
- return;
150
- }
151
- showPlainText(secret);
152
- return;
153
- }
154
- if (!secret) {
155
- return;
156
- }
157
- if (!requestUrl) {
158
- message.error("请为组件注入属性【requestUrl】");
159
- return;
160
- }
161
- if (!serviceConfig) {
162
- message.error("请为组件注入属性【appconfig】");
163
- return;
164
- }
165
-
166
- const requestSeq = requestSeqRef.current + 1;
167
- requestSeqRef.current = requestSeq;
168
- setLoading(true);
169
- try {
170
- const result = await new HttpService(requestUrl, serviceConfig).post("decrypt", {data: secret});
171
- if (requestSeq !== requestSeqRef.current) {
172
- return;
173
- }
174
- if (typeof result !== "string") {
175
- message.error("解密失败");
176
- return;
177
- }
178
- showPlainText(result);
179
- } catch (error) {
180
- if (requestSeq !== requestSeqRef.current) {
181
- return;
182
- }
183
- if (error && error.responseJSON && error.responseJSON.msg) {
184
- message.error(error.responseJSON.msg);
185
- } else {
186
- message.error("解密失败");
187
- }
188
- } finally {
189
- if (requestSeq === requestSeqRef.current) {
190
- setLoading(false);
191
- }
192
- }
193
- };
194
-
195
- const onModifyKeyDown = (event) => {
196
- if (onKeyDown) {
197
- onKeyDown(event);
198
- }
199
- if (toggle || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
200
- return;
201
- }
202
- if (event.key === "Backspace" || event.key === "Delete") {
203
- event.preventDefault();
204
- commitValue("", false);
205
- return;
206
- }
207
- if (event.key.length !== 1) {
208
- return;
209
- }
210
- event.preventDefault();
211
- const nextValue = editingRef.current ? realValueRef.current + event.key : event.key;
212
- commitValue(nextValue, false);
213
- };
214
-
215
- const onModifyPaste = (event) => {
216
- if (onPaste) {
217
- onPaste(event);
218
- }
219
- if (toggle || event.defaultPrevented) {
220
- return;
221
- }
222
- const text = event.clipboardData ? event.clipboardData.getData("text") : "";
223
- event.preventDefault();
224
- if (!text) {
225
- return;
226
- }
227
- const nextValue = editingRef.current ? realValueRef.current + text : text;
228
- commitValue(nextValue, false);
229
- };
230
-
231
- const onModifyChange = (event) => {
232
- const nextValue = event.target.value;
233
- if (!toggle) {
234
- if (nextValue === "") {
235
- commitValue("", false);
236
- }
237
- return;
238
- }
239
- commitValue(nextValue, true);
240
- };
241
-
242
- if (ui_render_type === "modify") {
243
- const modifyDisplay = toggle ? toggleVal : maskValue(realValue, resolvedMaskLength);
244
- return <Input
245
- {...restInputProps}
246
- value={modifyDisplay}
247
- placeholder={placeholder}
248
- allowClear={allowClear}
249
- maxLength={toggle && typeof maxLength === "number" ? maxLength : undefined}
250
- onChange={onModifyChange}
251
- onKeyDown={onModifyKeyDown}
252
- onPaste={onModifyPaste}
253
- addonAfter={<span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`} style={{cursor: "pointer"}} onClick={onToggleFull}/>}
254
- />;
255
- } else if (ui_render_type === "browse") {
256
- return <Fragment>
257
- <span>{toggleVal}<span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`} style={{cursor: "pointer", margin: "0 5px", color: "#337DB7", fontWeight: "bolder"}} onClick={onToggleFull}/></span>
258
- </Fragment>;
259
- }
260
- };
261
-
262
- export default InputPasswordDecrypt;
1
+ import React, {Fragment, useEffect, useRef, useState} from "react";
2
+ import {Input, message} from "antd";
3
+ import HttpService from "../../../services/HttpService";
4
+
5
+ const MASK_LENGTH = 8;
6
+
7
+ const normalizeValue = (value) => {
8
+ if (value === null || value === undefined) {
9
+ return "";
10
+ }
11
+ return String(value);
12
+ };
13
+
14
+ const maskValue = (value, maskLength) => {
15
+ if (value === null || value === undefined || value === "") {
16
+ return "";
17
+ }
18
+ return "*".repeat(maskLength);
19
+ };
20
+
21
+ const limitText = (text, maxLength) => {
22
+ if (typeof maxLength === "number" && maxLength > 0 && text.length > maxLength) {
23
+ return text.slice(0, maxLength);
24
+ }
25
+ return text;
26
+ };
27
+
28
+ const InputPasswordDecrypt = (props) => {
29
+ let {
30
+ ui_render_type,
31
+ initValue,
32
+ value,
33
+ onChange,
34
+ requestUrl,
35
+ appconfig,
36
+ appConfig,
37
+ maskLength,
38
+ placeholder,
39
+ maxLength,
40
+ allowClear = true,
41
+ onKeyDown,
42
+ onPaste,
43
+ ...restInputProps
44
+ } = props;
45
+ const resolvedMaskLength = Number.isInteger(maskLength) && maskLength > 0 ? maskLength : MASK_LENGTH;
46
+ const serviceConfig = appconfig || appConfig;
47
+ const incomingValue = normalizeValue(value !== undefined ? value : initValue);
48
+ const [realValue, setRealValue] = useState(incomingValue);
49
+ const [toggle, setToggle] = useState(false);
50
+ const [toggleVal, setToggleVal] = useState(maskValue(initValue, resolvedMaskLength));
51
+ const [loading, setLoading] = useState(false);
52
+ const timerRef = useRef(null);
53
+ const requestSeqRef = useRef(0);
54
+ const realValueRef = useRef(incomingValue);
55
+ const originalRef = useRef(incomingValue);
56
+ const emittedRef = useRef(incomingValue);
57
+ const editingRef = useRef(false);
58
+ const maskLengthRef = useRef(resolvedMaskLength);
59
+
60
+ realValueRef.current = ui_render_type === "modify" ? realValue : normalizeValue(initValue);
61
+ maskLengthRef.current = resolvedMaskLength;
62
+
63
+ const clearHideTimer = () => {
64
+ if (timerRef.current) {
65
+ clearTimeout(timerRef.current);
66
+ timerRef.current = null;
67
+ }
68
+ };
69
+
70
+ const hidePlainText = () => {
71
+ clearHideTimer();
72
+ setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
73
+ setToggle(false);
74
+ };
75
+
76
+ const showPlainText = (plainText) => {
77
+ clearHideTimer();
78
+ setToggleVal(plainText);
79
+ setToggle(true);
80
+ timerRef.current = setTimeout(() => {
81
+ timerRef.current = null;
82
+ setToggleVal(maskValue(realValueRef.current, maskLengthRef.current));
83
+ setToggle(false);
84
+ }, 5000);
85
+ };
86
+
87
+ useEffect(() => {
88
+ return () => {
89
+ requestSeqRef.current += 1;
90
+ clearHideTimer();
91
+ };
92
+ }, []);
93
+
94
+ useEffect(() => {
95
+ if (ui_render_type === "modify") {
96
+ return undefined;
97
+ }
98
+ setToggle(false);
99
+ setToggleVal(maskValue(initValue, resolvedMaskLength));
100
+ setLoading(false);
101
+ return () => {
102
+ requestSeqRef.current += 1;
103
+ clearHideTimer();
104
+ };
105
+ }, [ui_render_type, initValue, resolvedMaskLength]);
106
+
107
+ useEffect(() => {
108
+ if (ui_render_type !== "modify" || incomingValue === emittedRef.current) {
109
+ return undefined;
110
+ }
111
+ emittedRef.current = incomingValue;
112
+ originalRef.current = incomingValue;
113
+ editingRef.current = false;
114
+ realValueRef.current = incomingValue;
115
+ setRealValue(incomingValue);
116
+ requestSeqRef.current += 1;
117
+ clearHideTimer();
118
+ setToggle(false);
119
+ setToggleVal(maskValue(incomingValue, resolvedMaskLength));
120
+ setLoading(false);
121
+ }, [ui_render_type, incomingValue, resolvedMaskLength]);
122
+
123
+ const commitValue = (nextValue, reveal) => {
124
+ const normalized = limitText(normalizeValue(nextValue), maxLength);
125
+ emittedRef.current = normalized;
126
+ editingRef.current = true;
127
+ realValueRef.current = normalized;
128
+ setRealValue(normalized);
129
+ if (reveal) {
130
+ showPlainText(normalized);
131
+ }
132
+ if (onChange) {
133
+ onChange({target: {value: normalized}});
134
+ }
135
+ };
136
+
137
+ const onToggleFull = async () => {
138
+ if (toggle) {
139
+ hidePlainText();
140
+ return;
141
+ }
142
+ if (loading) {
143
+ return;
144
+ }
145
+
146
+ const secret = realValueRef.current;
147
+ if (ui_render_type === "modify" && (secret === "" || editingRef.current || secret !== originalRef.current)) {
148
+ if (secret === "") {
149
+ return;
150
+ }
151
+ showPlainText(secret);
152
+ return;
153
+ }
154
+ if (!secret) {
155
+ return;
156
+ }
157
+ if (!requestUrl) {
158
+ message.error("请为组件注入属性【requestUrl】");
159
+ return;
160
+ }
161
+ if (!serviceConfig) {
162
+ message.error("请为组件注入属性【appconfig】");
163
+ return;
164
+ }
165
+
166
+ const requestSeq = requestSeqRef.current + 1;
167
+ requestSeqRef.current = requestSeq;
168
+ setLoading(true);
169
+ try {
170
+ const result = await new HttpService(requestUrl, serviceConfig).post("decrypt", {data: secret});
171
+ if (requestSeq !== requestSeqRef.current) {
172
+ return;
173
+ }
174
+ if (typeof result !== "string") {
175
+ message.error("解密失败");
176
+ return;
177
+ }
178
+ showPlainText(result);
179
+ } catch (error) {
180
+ if (requestSeq !== requestSeqRef.current) {
181
+ return;
182
+ }
183
+ if (error && error.responseJSON && error.responseJSON.msg) {
184
+ message.error(error.responseJSON.msg);
185
+ } else {
186
+ message.error("解密失败");
187
+ }
188
+ } finally {
189
+ if (requestSeq === requestSeqRef.current) {
190
+ setLoading(false);
191
+ }
192
+ }
193
+ };
194
+
195
+ const onModifyKeyDown = (event) => {
196
+ if (onKeyDown) {
197
+ onKeyDown(event);
198
+ }
199
+ if (toggle || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
200
+ return;
201
+ }
202
+ if (event.key === "Backspace" || event.key === "Delete") {
203
+ event.preventDefault();
204
+ commitValue("", false);
205
+ return;
206
+ }
207
+ if (event.key.length !== 1) {
208
+ return;
209
+ }
210
+ event.preventDefault();
211
+ const nextValue = editingRef.current ? realValueRef.current + event.key : event.key;
212
+ commitValue(nextValue, false);
213
+ };
214
+
215
+ const onModifyPaste = (event) => {
216
+ if (onPaste) {
217
+ onPaste(event);
218
+ }
219
+ if (toggle || event.defaultPrevented) {
220
+ return;
221
+ }
222
+ const text = event.clipboardData ? event.clipboardData.getData("text") : "";
223
+ event.preventDefault();
224
+ if (!text) {
225
+ return;
226
+ }
227
+ const nextValue = editingRef.current ? realValueRef.current + text : text;
228
+ commitValue(nextValue, false);
229
+ };
230
+
231
+ const onModifyChange = (event) => {
232
+ const nextValue = event.target.value;
233
+ if (!toggle) {
234
+ if (nextValue === "") {
235
+ commitValue("", false);
236
+ }
237
+ return;
238
+ }
239
+ commitValue(nextValue, true);
240
+ };
241
+
242
+ if (ui_render_type === "modify") {
243
+ const modifyDisplay = toggle ? toggleVal : maskValue(realValue, resolvedMaskLength);
244
+ return <Input
245
+ {...restInputProps}
246
+ value={modifyDisplay}
247
+ placeholder={placeholder}
248
+ allowClear={allowClear}
249
+ maxLength={toggle && typeof maxLength === "number" ? maxLength : undefined}
250
+ onChange={onModifyChange}
251
+ onKeyDown={onModifyKeyDown}
252
+ onPaste={onModifyPaste}
253
+ addonAfter={<span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`} style={{cursor: "pointer"}} onClick={onToggleFull}/>}
254
+ />;
255
+ } else if (ui_render_type === "browse") {
256
+ return <Fragment>
257
+ <span>{toggleVal}<span className={`iconfont ${toggle ? "icon-bchr-show" : "icon-bchr-hide"}`} style={{cursor: "pointer", margin: "0 5px", color: "#337DB7", fontWeight: "bolder"}} onClick={onToggleFull}/></span>
258
+ </Fragment>;
259
+ }
260
+ };
261
+
262
+ export default InputPasswordDecrypt;
@@ -1,6 +1,7 @@
1
1
  const UI_RENDER_TYPE = {
2
2
  INPUT: "input",
3
3
  INPUT_PASSWORD: "inputPassword",
4
+ INPUT_PASSWORD_DECRYPT: "inputPasswordDecrypt",
4
5
  INPUT_NUMBER: "inputNumber",
5
6
  TEXT_AREA: "textArea",
6
7
  DATE: "date",
@@ -4,6 +4,7 @@ import {Badge, Col, ConfigProvider, Form, Row, Tooltip} from "antd";
4
4
  import {DownloadOutlined, QuestionCircleOutlined} from '@ant-design/icons';
5
5
  import moment from "moment";
6
6
  import {UI_RENDER_TYPE} from "../consts";
7
+ import InputPassword from "../InputPassword";
7
8
  import InputPasswordDecrypt from "../InputPasswordDecrypt";
8
9
 
9
10
  class FormForBrowse extends React.Component{
@@ -318,6 +319,7 @@ class FormForBrowse extends React.Component{
318
319
  case UI_RENDER_TYPE.INPUT:
319
320
  case UI_RENDER_TYPE.INPUT_NUMBER:
320
321
  case UI_RENDER_TYPE.INPUT_PASSWORD:
322
+ case UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
321
323
  case UI_RENDER_TYPE.TEXT_AREA:
322
324
  case UI_RENDER_TYPE.SELECT:
323
325
  case UI_RENDER_TYPE.TREE_SELECT:
@@ -355,6 +357,16 @@ class FormForBrowse extends React.Component{
355
357
  );
356
358
 
357
359
  if (ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD) {
360
+ components = (
361
+ <div>
362
+ {
363
+ initialValues[code] && <InputPassword ui_render_type={'browse'} initValue={initialValues[code]}/>
364
+ }
365
+ </div>
366
+ )
367
+ }
368
+
369
+ if (ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
358
370
  components = (
359
371
  <div>
360
372
  {
@@ -21,6 +21,7 @@ import moment from "moment";
21
21
  import {UI_RENDER_TYPE} from "../consts";
22
22
  import zhCN from "antd/es/locale/zh_CN";
23
23
  import HttpService from "../../../../services/HttpService";
24
+ import InputPassword from "../InputPassword";
24
25
  import InputPasswordDecrypt from "../InputPasswordDecrypt";
25
26
  import '../../../AppFormulaFunctions'
26
27
  import {treeDataToListByChildFieldName} from "../../../BaseAppUtils";
@@ -403,6 +404,24 @@ class FormForModify extends React.Component{
403
404
  );
404
405
  break;
405
406
  case UI_RENDER_TYPE.INPUT_PASSWORD:
407
+ component = b_readonly || this.disabledExpression(dataItem, data) ? (
408
+ <div>
409
+ <InputPassword ui_render_type={'browse'} initValue={displayValue}/>
410
+ </div>
411
+ )
412
+ :
413
+ (
414
+ <Input
415
+ key={form_id + "_" + code}
416
+ placeholder={"请填写" + name}
417
+ allowClear
418
+ maxLength={field_length && field_length > 0 ? field_length : null}
419
+ onChange={this.inputOnChange.bind(this, dataItem, onChange)}
420
+ {...ext_props}
421
+ />
422
+ );
423
+ break;
424
+ case UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
406
425
  component = b_readonly || this.disabledExpression(dataItem, data) ? (
407
426
  <div>
408
427
  <InputPasswordDecrypt ui_render_type={'browse'} initValue={displayValue} maskLength={this.props.maskLength} requestUrl={this.props.file_service_path} appconfig={this.props.appconfig || this.props.appConfig}/>
@@ -786,7 +805,8 @@ class FormForModify extends React.Component{
786
805
  }
787
806
  else if (ui_render_type === UI_RENDER_TYPE.INPUT
788
807
  || ui_render_type === UI_RENDER_TYPE.TEXT_AREA
789
- || ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD ) {
808
+ || ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD
809
+ || ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
790
810
 
791
811
  if (!value) {
792
812
  return Promise.reject("validate fail");
@@ -1363,6 +1383,7 @@ class FormForModify extends React.Component{
1363
1383
  case UI_RENDER_TYPE.INPUT:
1364
1384
  case UI_RENDER_TYPE.INPUT_NUMBER:
1365
1385
  case UI_RENDER_TYPE.INPUT_PASSWORD:
1386
+ case UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
1366
1387
  case UI_RENDER_TYPE.TEXT_AREA:
1367
1388
  case UI_RENDER_TYPE.TREE_SELECT:
1368
1389
  value = formItemValue;
@@ -8,6 +8,7 @@ import {EXPORT_GRID_CELL_OPTIONS, EXPORT_GRID_HEADER_CELL_OPTIONS, UI_RENDER_TYP
8
8
  import GridFilterRowIndicator from "./GridFilterRowIndicator";
9
9
  import zhCN from "antd/es/locale/zh_CN";
10
10
  import GridColumnCustomToolBar from "./GridColumnCustomToolBar";
11
+ import InputPassword from "../InputPassword";
11
12
  import InputPasswordDecrypt from "../InputPasswordDecrypt";
12
13
 
13
14
  class GridForBrowse extends React.Component{
@@ -384,6 +385,7 @@ class GridForBrowse extends React.Component{
384
385
  switch (ui_render_type) {
385
386
  case UI_RENDER_TYPE.INPUT:
386
387
  case UI_RENDER_TYPE.INPUT_PASSWORD:
388
+ case UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
387
389
  case UI_RENDER_TYPE.INPUT_NUMBER:
388
390
  case UI_RENDER_TYPE.SELECT:
389
391
  case UI_RENDER_TYPE.TREE_SELECT:
@@ -426,7 +428,8 @@ class GridForBrowse extends React.Component{
426
428
  {value}
427
429
  </td>
428
430
  );
429
- } else if (ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD) {
431
+ } else if (ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD
432
+ || ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT) {
430
433
  return (
431
434
  <td className={props.className}
432
435
  style={grid_default_locked ? {left: column_locked_left + 'px', right: "0px"} : {}}>
@@ -443,7 +446,10 @@ class GridForBrowse extends React.Component{
443
446
  }
444
447
 
445
448
  {
446
- dataItem[code] ? <InputPasswordDecrypt ui_render_type={'browse'} initValue={dataItem[code]} maskLength={this.props.maskLength} requestUrl={this.props.requestUrl} appconfig={this.props.appconfig || this.props.appConfig}/> : null
449
+ dataItem[code] ? (ui_render_type === UI_RENDER_TYPE.INPUT_PASSWORD
450
+ ? <InputPassword ui_render_type={'browse'} initValue={dataItem[code]}/>
451
+ : <InputPasswordDecrypt ui_render_type={'browse'} initValue={dataItem[code]} maskLength={this.props.maskLength} requestUrl={this.props.requestUrl} appconfig={this.props.appconfig || this.props.appConfig}/>)
452
+ : null
447
453
  }
448
454
  </td>
449
455
  );
@@ -507,6 +513,7 @@ class GridForBrowse extends React.Component{
507
513
  switch (ui_render_type) {
508
514
  case UI_RENDER_TYPE.INPUT:
509
515
  case UI_RENDER_TYPE.INPUT_PASSWORD:
516
+ case UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
510
517
  case UI_RENDER_TYPE.SELECT:
511
518
  case UI_RENDER_TYPE.TREE_SELECT:
512
519
  case UI_RENDER_TYPE.UPLOAD:
@@ -261,6 +261,16 @@ class GridForModify extends React.Component{
261
261
  );
262
262
  break;
263
263
  case UI_RENDER_TYPE.INPUT_PASSWORD:
264
+ component = (
265
+ <Input
266
+ title={dataItem[code]}
267
+ placeholder={"请填写" + name}
268
+ defaultValue={dataItem[code]}
269
+ allowClear
270
+ onChange={this.inputOnChange.bind(this, dataItem, fieldConfig, onChange)}/>
271
+ );
272
+ break;
273
+ case UI_RENDER_TYPE.INPUT_PASSWORD_DECRYPT:
264
274
  component = (
265
275
  <InputPasswordDecrypt
266
276
  ui_render_type={'modify'}