Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e02ce7

Browse files
Merge pull request #2042 from iamfaran/fix/scanner
[Fix]: Scanner duplicate code, and open URL on success
2 parents ae4a1a2 + 022cd51 commit 6e02ce7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎client/packages/lowcoder/src/comps/comps/buttonComp/scannerComp.tsx‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import React, {
3030
useState,
3131
useContext,
3232
} from "react";
33-
import { arrayStringExposingStateControl } from "comps/controls/codeStateControl";
33+
import { arrayStringExposingStateControl,stringExposingStateControl } from "comps/controls/codeStateControl";
3434
import { BoolControl } from "comps/controls/boolControl";
3535
import { RefControl } from "comps/controls/refControl";
3636
import { EditorContext } from "comps/editorState";
@@ -120,6 +120,7 @@ const BarcodeScannerComponent = React.lazy(
120120
const ScannerTmpComp = (function () {
121121
const childrenMap = {
122122
data: arrayStringExposingStateControl("data"),
123+
value: stringExposingStateControl("value"),
123124
text: withDefault(StringControl, trans("scanner.text")),
124125
continuous: BoolControl,
125126
uniqueData: withDefault(BoolControl, true),
@@ -150,17 +151,27 @@ const ScannerTmpComp = (function () {
150151
}, [success, showModal]);
151152

152153
const continuousValue = useRef<string[]>([]);
154+
const seenSetRef = useRef<Set<string>>(new Set());
153155

154156
const handleUpdate = (err: any, result: any) => {
155157
if (result) {
156158
if (props.continuous) {
157-
continuousValue.current = [...continuousValue.current, result.text];
159+
const scannedText: string = result.text;
160+
if (props.uniqueData && seenSetRef.current.has(scannedText)) {
161+
return;
162+
}
163+
continuousValue.current = [...continuousValue.current, scannedText];
164+
if (props.uniqueData) {
165+
seenSetRef.current.add(scannedText);
166+
}
158167
const val = props.uniqueData
159168
? [...new Set(continuousValue.current)]
160169
: continuousValue.current;
170+
props.value.onChange(scannedText);
161171
props.data.onChange(val);
162172
props.onEvent("success");
163173
} else {
174+
props.value.onChange(result.text);
164175
props.data.onChange([result.text]);
165176
setShowModal(false);
166177
setSuccess(true);
@@ -205,6 +216,7 @@ const ScannerTmpComp = (function () {
205216
props.onEvent("click");
206217
setShowModal(true);
207218
continuousValue.current = [];
219+
seenSetRef.current = new Set();
208220
}}
209221
>
210222
<span>{props.text}</span>
@@ -317,6 +329,7 @@ const ScannerTmpComp = (function () {
317329

318330
export const ScannerComp = withExposingConfigs(ScannerTmpComp, [
319331
new NameConfig("data", trans("data")),
332+
new NameConfig("value", trans("value")),
320333
new NameConfig("text", trans("button.textDesc")),
321334
...CommonNameConfig,
322335
]);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /